# PixAnvil Spring System demo

Er, JavaScript or WebGL doesn't seem to be running, so basically all you're going to see is the bare code...

 var car={ nwheel:4, // number of wheels naxle:2, // number of axles wheelradius:0.3, // radius of wheels wheel:[], // wheel objects axle:[], // axle objects }; for (var wi=0;wi0.02) lib.dt=0.02; if (SPS.particles.length==0) return; // not initialized yet // Initialize all particles: if (!SPS_is_setup) { for (var i = 0; i < SPS.particles.length; i++) { var p=SPS.particles[i]; p.i=i; // Link over to vector names: p.P=p.position; p.V=p.direction; // Mass is constant p.mass=1.0; // Are we a wheel center? if (i0.01) downForce=0.0; // off ground // FIXME: sliding friction? var sideForce=friction*downForce; var Flen=wheelF.length(); if (Flen>sideForce) { wheelF.te(sideForce/Flen); w.mesh.color=new BABYLON.Color3(1,0,0); } trace("Wheel "+wi+": F "+p.F+" N, wheel "+wheelF); // Show forces on wheels lib.tempVector(p.P,p.P.p(p.F.t(0.01))); lib.tempVector(p.P,p.P.p(wheelF.t(0.01))); // Add wheel force to spring system p.F.pe(wheelF); } // Apply forces on each particle for (var i = 0; i < SPS.particles.length; i++) { var p=SPS.particles[i]; // Compute acceleration from force var A=p.F.t(1.0/p.mass).pe(new vec3(0,0,-9.8)); // Verlet integration // (Need 2nd order for stability) var old_P=p.P.clone(); p.P.pe(p.V.te(lib.dt). pe(A.t(lib.dt*lib.dt))); // Recompute effective velocity p.V=p.P.m(old_P).te(1.0/lib.dt); //if (i%10==0) { // trace("Particle "+i+": F="+p.F); //} if (p.P.z<0) { p.P.z=0.0; p.V.z=Math.abs(p.V.z); // p.V.te(0.0); // complete friction losses } } last_dt=lib.dt; var export_start=performance.now(); trace(" Neighbors (ms): "+(export_start-neighbor_start)); // Export particles to screen: SPS.animate(); var end=performance.now(); trace(" Export (ms): "+(end-export_start)); // User Interface (UI) code: