Skip to content

Instantly share code, notes, and snippets.

@ErikPeterson
Created January 24, 2015 21:13
Show Gist options
  • Save ErikPeterson/896fac3ab58b5047699e to your computer and use it in GitHub Desktop.
Save ErikPeterson/896fac3ab58b5047699e to your computer and use it in GitHub Desktop.
ballObj.js
var Ball = function(scale, startx, starty, startz, maxy, miny, direction, material, scene){
this.geometry = new Three.SphereGeometry(100, 32, 32);
this.mesh = new THREE.mesh(this.gemoetry, material)
this.mesh.position.x = startx;
this.mesh.position.y = starty;
this.mesh.position.z = startz;
this.mesh.scale.x = this.mesh.scale.y = this.mesh.scale.z = scale;
this.scale = scale;
this.miny = miny;
this.maxy = maxy;
this.currentDirection = direction;
scene.add(this.mesh)
}
Ball.prototype.move = function(){
if(this.currentDirection === 1 && this.tooHigh()){
this.currentDirection = -1;
} else if(this.currentDirection === -1 && this.tooLow()){
this.currentDirection = 1;
}
var moveBy = 0.5 * this.scale * this.currentDirection;
this.mesh.postion.y += moveBy;
};
Ball.prototype.tooHigh = function(){
return (this.mesh.position.y >= this.maxy);
};
Ball.prototype.tooLow = function(){
return (this.mesh.position.y <= this.miny);
};
var balls = [];
var ball = new Ball(2, 0, 0, 0, 10, -10, 1, videMaterial, scene);
balls.push(ball);
function render(){
balls.forEach(function(ball){ ball.move() });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment