Example #1
0
 public PointMass(float mass, Vec2 pos, Vec2 vel)
 {
     //parameterized constructor
     this.mass = mass;
     this.pos = pos;
     this.vel = vel;
 }
Example #2
0
 public static float Dot(Vec2 a, Vec2 b)
 {
     //calculates the Dot product of two vectors
     float dotprod;
     dotprod = (a.x * b.x) + (a.y * b.y);
     return (float)dotprod;
 }
        protected bool collide(List<CollisionPair> collisions, CircleShell a, CircleShell b)
        {
            //for future use: will have conditionals here for the different shell types

            float collision = a.radius + b.radius;

            //calc current distance
            Vec2 distance = new Vec2((b.position.x - a.position.x), (b.position.y - a.position.y));

            //check if they overlap
            float overlap = collision - distance.GetMag();

            //if they overlap, create a new pair and add it to the list
            if (overlap <= collision && overlap >= 0.0f)
            {
                CollisionPair cpair = new CollisionPair(a, b, (distance * overlap));
                collisions.Add(cpair);
                return true;
            }

            else
            {
                return false;
            }
        }
Example #4
0
 //each timestep, do this.
 public override void Step(float dt)
 {
     Vec2 a = (1.0f/mass) * forceAccumulator;
     Vec2 v = a * dt + vel;
     pos = vel * dt + Pos;
     vel = v;
     forceAccumulator = new Vec2(); //zero out the force
 }
Example #5
0
        public Circle(EWorld ew, Vec2 pos, Vec2 vel, float radius, float mass, Color color)
        {
            this.eworld = ew;

            this.cshell = new CircleShell(pos, radius);
            this.pm = new PhysicsWorld.PointMass(mass, pos, vel);
            this.gobj = new GraphicsWorld.Circle(pos.x, pos.y, radius, color);
            this.cshell.userData = this;
            this.pm.userData = this;

            eworld.Gworld.Add(this.gobj);
            eworld.Cworld.Add(this.cshell);
            eworld.Pworld.Add(this.pm);
        }
Example #6
0
 public static Vec2 operator -(Vec2 a, Vec2 b)
 {
     //for subtracting 2 vectors
     Vec2 newVector = new Vec2((a.x - b.x), (a.y - b.y));
     return newVector;
 }
Example #7
0
 public static Vec2 operator +(Vec2 a, Vec2 b)
 {
     //For adding 2 vectors
     Vec2 newVector = new Vec2((a.x + b.x), (a.y + b.y));
     return newVector;
 }
Example #8
0
 public static Vec2 operator *(Vec2 v, float k)
 {
     //for multiplying 2 vectors
     Vec2 newVector = new Vec2((v.x * k), (v.y * k));
     return newVector;
 }
Example #9
0
 //add the force vector to the current force
 public void AddForce(Vec2 f)
 {
     forceAccumulator += f;
 }
Example #10
0
 public PointMass(float mass)
 {
     this.mass = mass;
     this.vel = new Vec2();
     pos = new Vec2();
 }
 public CollisionPair(CollisionShell a, CollisionShell b, Vec2 force)
 {
     this.a = a;
     this.b = b;
     this.userData = force;
 }
 public CollisionShell(Vec2 pos)
 {
     this.position = pos;
 }
        public Object userData; //will be used in the future to help with encapsulation

        #endregion Fields

        #region Constructors

        public CollisionShell(Vec2 pos, Object userData)
        {
            position = new Vec2(pos.x, pos.y);
            this.userData = userData;
        }
 public CircleShell(Vec2 p, float r)
     : base(p)
 {
     this.radius = r;
 }
 public CircleShell(Vec2 p, float r, Object userData)
     : base(p, userData)
 {
     this.radius = r;
 }