public override Vector ResolveCollision( Vector normal, Engine engine ) { Vector velocity = base.ResolveCollision(normal, engine); Resolve(normal); lastNormal = normal; return velocity; }
public RigidComposite( Engine engine, params Particle[] particles ) { this.particles = particles; foreach ( Particle particle in particles ) { engine.Add( particle ); } for ( int index = 0; index < particles.Length; index += 2 ) { int index1 = ( index + 1 < particles.Length ) ? index + 1 : 0; int index2 = ( index1 + 1 < particles.Length ) ? index1 + 1 : 0; AngularConstraint constraint = new AngularConstraint( particles[ index ], particles[ index1 ], particles[ index2 ] ); engine.Add( constraint ); } }
public override void Verlet( Engine engine ) { rp.Verlet( engine ); base.Verlet( engine ); }
public void ResolveRectangleCollision( RectangleParticle p, Engine engine ) { if ( IsRectangleColliding( p ) ) { OnContact(); p.OnContact(); p.ResolveCollision( collNormal, engine ); } }
public virtual void ResolveRectangleCollision( RectangleParticle p, Engine engine, ref CollisionState state ) { }
public virtual void Verlet( Engine engine ) { temp.X = curr.X; temp.Y = curr.Y; curr.X += engine.CoeffDamp * ( curr.X - prev.X ) + engine.Gravity.X; curr.Y += engine.CoeffDamp * ( curr.Y - prev.Y ) + engine.Gravity.Y; prev.X = temp.X; prev.Y = temp.Y; }
public virtual void ResolveCircleCollision( CircleParticle p, Engine engine, ref CollisionState state ) { }
public override void ResolveRectangleCollision( RectangleParticle p, Engine engine, ref CollisionState state ) { throw new Exception( "The method or operation is not implemented." ); }
public virtual void CheckCollision( ISurface surface, Engine engine ) { }
public virtual void CheckCollision( IParticle particle, Engine engine, ref CollisionState state ) { }
public override void CheckCollision( IParticle particle, Engine engine, ref CollisionState state ) { //particle.ResolveRectangleCollision( this, engine ); }
public override void CheckCollision( ISurface surface, Engine engine ) { surface.ResolveRectangleCollision( this, engine ); }
public override void CheckCollision( IParticle particle, Engine engine, ref CollisionState state ) { // HACK: here i need not to collide wheels with body particles if (this is Wheel && !(particle is Wheel)) return; if (particle is Wheel && !(this is Wheel)) return; particle.ResolveCircleCollision(this, engine, ref state); }
// TBD: provide a way to get the worldspace position of the rimparticle // either here, or in the wheel class, so it can be used to move other // primitives / constraints public void Verlet( Engine engine ) { //clamp torques to valid range speed = Math.Max( -maxTorque, Math.Min( maxTorque, speed + vs ) ); //apply torque //this is the tangent vector at the rim particle double dx = -curr.Y; double dy = curr.X; //normalize so we can scale by the rotational speed double len = Math.Sqrt( dx * dx + dy * dy ); dx /= len; dy /= len; curr.X += speed * dx; curr.Y += speed * dy; double ox = prev.X; double oy = prev.Y; double px = prev.X = curr.X; double py = prev.Y = curr.Y; curr.X += engine.CoeffDamp * ( px - ox ); curr.Y += engine.CoeffDamp * ( py - oy ); // hold the rim particle in place double clen = Math.Sqrt( curr.X * curr.X + curr.Y * curr.Y ); double diff = ( clen - wr ) / clen; if ( Math.Abs( diff ) < 0.0001 ) diff = 0; curr.X -= curr.X * diff; curr.Y -= curr.Y * diff; }
// 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; }
public void ResolveCircleCollision( CircleParticle p, Engine engine ) { if ( IsCircleColliding( p ) ) { OnContact(); p.OnContact(); p.ResolveCollision( normal, engine ); } }
public override void ResolveCircleCollision( CircleParticle p, Engine engine, ref CollisionState state ) { if ( Collision.IsEllipseCollision( curr, Size, 0, p.curr, p.Size, 0, out state ) ) { Vector normal = state.Depth.Clone().Normalize(); Vector vel1 = curr.MinusNew( prev ); Vector vel2 = p.curr.MinusNew( p.prev ); p.prev = p.curr.PlusNew( state.Depth ); prev = curr.MinusNew( state.Depth ); } }