contact problem
by jmchen
HTML
<div id="info">Contact Problem</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
// Contact:
// assumption: ball is initially on plane
// ball appearance: specular sufficient?!
// Mac to open Javascript console: opt + command + I
//
// not yet
// finite border: out of bound to remove contact force
// (use basis to compute local coordinates)
// rolling rotation texture
// accelerameter
// hole in the center: cutout texture, detection
// ball flying out of edge
// mixed collision & contact problem ("drop & stay")
// new rolling (pachigo like) game
//
var camera, scene, renderer, light, controls;
var ball, plane;
var clock = new THREE.Clock();
var mouse = new THREE.Vector2();
var gravity = new THREE.Vector3(0, -20, 0);
// class defintions here
var Ball = function () {
// properties
this.pos = new THREE.Vector3(0, 0, 0);
this.vel = new THREE.Vector3();
this.force = new THREE.Vector3();
this.mesh = new THREE.Mesh(new THREE.SphereGeometry(10, 12, 12), new THREE.MeshPhongMaterial({
color: 0xff1234,
specular: 0x444444,
shininess: 80
}));
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(500, 20, 500), new THREE.MeshLambertMaterial({
transparent: true,
opacity: 0.5
}));
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());
return...