rotating ground
HTML
<div id="info">Drop!</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="http://threejs.org/examples/js/controls/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, light, controls;
var ball, plane;
var clock = new THREE.Clock();
// class defintion here
var Ball = function () {
// properties
this.pos = new THREE.Vector3(0, 100, 0);
this.vel = new THREE.Vector3();
this.force = new THREE.Vector3(0, -50, 0);
this.mesh = new THREE.Mesh(new THREE.SphereGeometry(5, 12, 12), new THREE.MeshBasicMaterial());
scene.add(this.mesh);
// methods
this.update = function (dt) {
this.vel.add(this.force.clone().multiplyScalar(dt));
this.pos.add(this.vel.clone().multiplyScalar(dt));
this.mesh.position.copy(this.pos);
}
}
var Plane = function () {
// properties
this.pos = new THREE.Vector3(0, 10, 0); // object frame
this.normal = new THREE.Vector3(0, 1, 0); // object frame
this.mesh = new THREE.Mesh(new THREE.BoxGeometry(200, 20, 200), new THREE.MeshLambertMaterial());
scene.add(this.mesh);
// methods
this.isPointOut = function (point) {
// considering plane transformation
var posW = this.pos.clone(); // in world frame
var normalW = this.normal.clone();
posW.applyMatrix4(this.mesh.matrixWorld);
var tt = new THREE.Matrix4();
normalW.applyMatrix4(tt.getInverse(this.mesh.matrixWorld).transpose());
var tmp = new THREE.Vector3();
tmp.subVectors(point, posW);
if (tmp.dot(normalW) > 0) return true;
else return false;
}
};
init();
animate();
function ProjVonU(v, u) {
var uhat = u.clone().normalize();
return uhat.multiplyScalar(uhat.dot(v));
}
function CollisionResponse(ball, plane) {
// considering plane transformation
var posW = plane.pos.clone(); // plane in world frame
var normalW = plane.normal.clone();
posW.applyMatrix4(plane.mesh.matrixWorld);
var tt = new THREE.Matrix4();
normalW.applyMatrix4(tt.getInverse(plane.mesh.matrixWorld).transpose());
// position...