/** * Find minimum depth and set mtd appropriately. mtd is the minimum translational * distance, the vector along which we must move the box to resolve the collision. */ //TBD: this is only for right triangle surfaces - make generic public void SetMTD( double depthX, double depthY, double depthN, Vector surfNormal ) { double absX = Math.Abs( depthX ); double absY = Math.Abs( depthY ); double absN = Math.Abs( depthN ); if ( absX < absY && absX < absN ) mtd.Set( depthX, 0 ); else if ( absY < absX && absY < absN ) mtd.Set( 0, depthY ); else if ( absN < absX && absN < absY ) mtd = surfNormal.MultNew( depthN ); }
// TBD: too much passing around of the Physics object. Probably better if // it was static. there is no way to individually set the kfr and friction of the // surfaces since they are calculated here from properties of the Physics // object. Also, review for too much object creation public virtual Vector ResolveCollision( Vector normal, Engine engine) { // get the velocity Vector vel = curr.MinusNew( prev ); double sDotV = normal.Dot( vel ); // compute momentum of particle perpendicular to normal Vector velProjection = vel.MinusNew( normal.MultNew( sDotV ) ); Vector perpMomentum = velProjection.MultNew( engine.CoeffFric ); // compute momentum of particle in direction of normal Vector normMomentum = normal.MultNew( sDotV * engine.CoeffRest ); Vector totalMomentum = normMomentum.PlusNew( perpMomentum ); // set new velocity w/ total momentum Vector newVel = vel.MinusNew( totalMomentum ); // project out of collision curr.Plus( mtd ); // apply new velocity prev = curr.MinusNew( newVel ); return newVel; }