hw7 parts
by yi hom
HTML
<div id="info">hw7 parts<br/>Basics</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js">
</script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var camera, scene, renderer, geometry, material, mesh, controls;
var pos, vel;
var clock = new THREE.Clock();
var puck;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 500;
scene.add(camera);
geometry = new THREE.BoxGeometry(220, 30, 10);
material = new THREE.MeshBasicMaterial({
transparent: true,
color: 0xff2387,
opacity: 0.4
});
mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 15, 105);
scene.add(mesh);
mesh2 = mesh.clone();
mesh2.position.set(0, 15, -105);
scene.add(mesh2);
mesh3 = mesh.clone();
mesh3.rotation.y = Math.PI / 2;
mesh3.position.set(105, 15, 0);
scene.add(mesh3);
mesh4 = mesh.clone();
mesh4.rotation.y = Math.PI / 2;
mesh4.position.set(-105, 15, 0);
scene.add(mesh4);
var Puck = function() {
this.pos = new THREE.Vector3();
this.vel = new THREE.Vector3();
this.mesh = new THREE.Mesh(new THREE.CylinderGeometry(5, 5, 2, 20),
new THREE.MeshBasicMaterial());
};
Puck.prototype.update = function(dt){
this.pos.add(this.vel.clone().multiplyScalar(dt));
this.mesh.position.copy(this.pos);
};
Puck.prototype.collision = function () {
if (this.pos.x > 100) {
this.pos.x = 100;
this.vel.set(-this.vel.x, 0, this.vel.z);
} else if (this.pos.x < -100) {
this.pos.x = -100;
this.vel.set(-this.vel.x, 0, this.vel.z);
}
if (this.pos.z > 100) {
this.pos.z = 100;
this.vel.set(this.vel.x, 0, -this.vel.z);
} else if (this.pos.z < -100) {
this.pos.z = -100;
this.vel.set(this.vel.x, 0, -this.vel.z);
}
}
puck = new Puck();
puck.pos = new THREE.Vector3(0, 1, 0);
puck.vel = new THREE.Vector3(50, 0, 70);
scene.add(puck.mesh);
var...