Angular Velocity Matrix demo
Er, JavaScript doesn't seem to be running, so basically all you're going to see is the bare code...
// Make a bunch of spheres var g=new THREE.SphereGeometry(1, 3, 3); var m=new THREE.MeshLambertMaterial( {color: 0xffffff}) sim.nspheres=5; sim.spheres=[]; for (var i=0;i
/** Matrix preliminaries **/ // Assign this column of the matrix from this vector. THREE.Matrix4.prototype.setCol=function(col,v) { this.elements[col*4+0]=v.x; this.elements[col*4+1]=v.y; this.elements[col*4+2]=v.z; } // Extract this column of the matrix, and return it. THREE.Matrix4.prototype.getCol=function(col) { return new vec3(this.elements[col*4+0], this.elements[col*4+1], this.elements[col*4+2]); } // Normalize the vec3 making up this column. THREE.Matrix4.prototype.normCol=function(col) { var v=this.getCol(col); v.normalize(); this.setCol(col,v); } // Normalize the XYZ axes, so they have unit length. THREE.Matrix4.prototype.normalize=function() { this.normCol(0); this.normCol(1); this.normCol(2); } // Do time integration: add v*dt to each element. THREE.Matrix4.prototype.integrate=function(v,dt) { var te=this.elements; var ve=v.elements; // loop ends early, so we don't mess up W. for (var i=0;i<15;i++) te[i]+=ve[i]*dt; }; // User Interface and camera control var rot=new vec3(); // user-applied torques // X control via J and L if (lib.key['j']) rot.pe(new vec3(-1,0,0)); if (lib.key['l']) rot.pe(new vec3(+1,0,0)); // Y control via I and K if (lib.key['i']) rot.pe(new vec3(0,+1,0)); if (lib.key['k']) rot.pe(new vec3(0,-1,0)); // Z control via U and M if (lib.key['u']) rot.pe(new vec3(0,0,+1)); if (lib.key['m']) rot.pe(new vec3(0,0,-1)); // Per-object rotation physics for (var i=0;i
0.0) { // we hit the boundary s.P.pe(N.t(-d)); // move inside var dV=s.V.dot(N); if (dV>0.0) { // flip velocity s.V.pe(N.t(-2.0*dV )); } s.V.te(0.6); // bounce friction (inelastic) } } // Linear bounce physics for (var i=0;i
// Camera control could go here.