Esempio n. 1
0
 public void RemoveBody( PhysBody body )
 {
     #if DEBUG
       //if ( !bodies.Contains( body ) || body.Released )
       //  throw new InvalidOperationException( "invalid body release" );
     #endif
       body.Released = true;
 }
 public Collision( bool collided, float time, PhysBody bodyA, PhysBody bodyB, Vector2 normal, Vector2 isect )
 {
     Collided = collided;
       Time = time;
       BodyA = bodyA;
       BodyB = bodyB;
       Normal = normal;
       Intersection = isect;
 }
Esempio n. 3
0
 // public methods
 public void AddBody( PhysBody body )
 {
     #if DEBUG
       if ( bodies.Contains( body ) && !body.Released )
     throw new InvalidOperationException( "body already in space" );
     #endif
       // if Released is marked true, then the body hasn't been removed yet
       if ( !bodies.Contains( body ) )
     bodies.Add( body );
       body.Released = false;
 }
        public static Collision TestForCollision( PhysBody bodyA, PhysBody bodyB, float elapsed )
        {
            if ( bodyA.MotionBounds.Left > bodyB.MotionBounds.Right ||
               bodyB.MotionBounds.Left > bodyA.MotionBounds.Right ||
               bodyA.MotionBounds.Top < bodyB.MotionBounds.Bottom ||
               bodyB.MotionBounds.Top < bodyA.MotionBounds.Bottom )
            return new Collision();

              if ( bodyA is PhysCircle && bodyB is PhysCircle )
            return CircleVsCircle( (PhysCircle)bodyA, (PhysCircle)bodyB, elapsed );

              if ( bodyA is PhysCircle && bodyB is PhysPolygon )
            return CircleVsPolygon( (PhysCircle)bodyA, (PhysPolygon)bodyB, elapsed );

              if ( bodyA is PhysPolygon && bodyB is PhysCircle )
            return CircleVsPolygon( (PhysCircle)bodyB, (PhysPolygon)bodyA, elapsed ).GetInvert();

              if ( bodyA is PhysPolygon && bodyB is PhysPolygon )
            return PolygonVsPolygon( (PhysPolygon)bodyA, (PhysPolygon)bodyB, elapsed );

              throw new InvalidCastException( "Unknown physbody type." );
        }
Esempio n. 5
0
        // Constructor
        public PhysBody( Vector2 pos, Vector2 vel, float mass )
        {
            Position        = pos;
              Velocity        = vel;
              Mass            = mass;

              MomentOfInertia = 1f;
              Force           = Vector2.Zero;
              Angle           = 0.0f;
              AngularVelocity = 0.0f;
              Torque          = 0f;
              Flags           = BodyFlags.None;
              Elasticity      = .5f;
              Friction        = .5f;
              TouchNormal     = Vector2.Zero;
              Touching        = null;
              Parent          = null;

              CollisionList = new List<PhysBody>( 4 );
        }
Esempio n. 6
0
 public BoundaryTubeObject()
 {
     Body = null;
       Object = null;
       Path = new Path();
       StartSpeed = 10f;
       FinalSpeed = 3.5f;
       Time = 0f;
 }
Esempio n. 7
0
        // private helpers
        private void MoveBody( PhysBody body, float timeStep, float pullBackPct )
        {
            if ( body.Velocity == Vector2.Zero ) return;
              if ( timeStep <= 0f ) return;

              body.Moved = true;
              Vector2 disp = body.Velocity * timeStep;
              if ( pullBackPct != 0f )
            disp *= ( 1f - pullBackPct );
              body.Position += disp;
              body.Angle += body.AngularVelocity * timeStep;
        }