PixAnvil/Three.js demo
JavaScript doesn't seem to be running, so nothing below is going to work.
Setup
Animate
Save
// Make a bunch of spheres var g=new THREE.SphereGeometry(0.5, 8, 6); var m=new THREE.MeshLambertMaterial( {color: 0xffffff}) sim.nspheres=50; sim.spheres=[]; for (var i=0;i
/** s: sphere object, with s.P position and s.V velocity. N: surface normal, facing out of region. P: point on surface of boundary region. */ function boundaryBounce(s,N,P) { N.normalize(); var rP=s.P.clone().subSelf(P); // sphere position, relative to boundary var d=rP.dot(N); if (d>0.0) { // we hit the boundary s.P.addSelf(N.clone().multiplyScalar(-d)); // move inside var dV=s.V.dot(N); if (dV>0.0) { // flip velocity s.V.addSelf(N.clone().multiplyScalar(-2.0*dV )); } s.V.multiplyScalar(0.6); // bounce friction (inelastic) if (dV>0.3) { // CLANG! the camera camera.position.addSelf(N.clone().multiplyScalar(-dV*0.0005)); } } } var dt=0.1*lib.dt; // 10% of realtime. camera.position.set(0,-10,1.7); // default: assume no "clang!". for (var i=0;i
To save, copy into a
plain text
editor like Notepad.
/* Content here coming soon! */ For now, just copy out your Setup and Animate code.