Ejemplo n.º 1
0
 public PointMass(float mass, Vec2 pos, Vec2 vel)
 {
     //parameterized constructor
     this.mass = mass;
     this.pos = pos;
     this.vel = vel;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 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
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 9
0
 //add the force vector to the current force
 public void AddForce(Vec2 f)
 {
     forceAccumulator += f;
 }
Ejemplo n.º 10
0
 public PointMass(float mass)
 {
     this.mass = mass;
     this.vel = new Vec2();
     pos = new Vec2();
 }
Ejemplo n.º 11
0
 public CollisionPair(CollisionShell a, CollisionShell b, Vec2 force)
 {
     this.a = a;
     this.b = b;
     this.userData = force;
 }
Ejemplo n.º 12
0
 public CollisionShell(Vec2 pos)
 {
     this.position = pos;
 }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
 public CircleShell(Vec2 p, float r)
     : base(p)
 {
     this.radius = r;
 }
Ejemplo n.º 15
0
 public CircleShell(Vec2 p, float r, Object userData)
     : base(p, userData)
 {
     this.radius = r;
 }