Ejemplo n.º 1
0
        //methods

        public void checkforwall(Physics_Entity entity, float wall_k, Vector2 pos, float min_x, float max_x, float min_y, float max_y)
        {
            if (entity.Position.X < min_x + pos.X)
            {
                Vector2 changeForce = new Vector2(entity.Force.X - (entity.Position.X - (min_x + pos.X)) * wall_k, entity.Force.Y);
                entity.Force = changeForce;
            }

            if (entity.Position.X > max_x + pos.X)
            {
                Vector2 changeForce = new Vector2(entity.Force.X - (entity.Position.X - (max_x + pos.X)) * wall_k, entity.Force.Y);
                entity.Force = changeForce;
            }

            if (entity.Position.Y < min_y + pos.Y)
            {
                Vector2 changeForce = new Vector2(entity.Force.X, entity.Force.Y - (entity.Position.Y - (min_y + pos.Y)) * wall_k);
                entity.Force = changeForce;
            }

            if (entity.Position.Y > max_y + pos.Y)
            {
                Vector2 changeForce = new Vector2(entity.Force.X, entity.Force.Y - (entity.Position.Y - (max_y + pos.Y)) * wall_k);
                entity.Force = changeForce;
            }
        }
Ejemplo n.º 2
0
        //Methods
        public void updatevel(Physics_Entity entity, float dt)
        {
            Vector2 newpos;

            newpos          = entity.Position + entity.Force * dt;
            entity.Velocity = (newpos - entity.Oldposition) / (dt);
        }
Ejemplo n.º 3
0
        //Methods
        public Vector2 CalculateForce(Vector2 force, Spring spring, Physics_Entity p1, Physics_Entity p2)
        {
            Vector2 vector_between_p1_p2;
            float   current_length;

            vector_between_p1_p2.X = p2.Position.X - p1.Position.X;
            vector_between_p1_p2.Y = p2.Position.Y - p1.Position.Y;

            current_length = vector_between_p1_p2.Length();
            vector_between_p1_p2.Normalize();
            force = vector_between_p1_p2 * (spring.Restlength - current_length) * spring.Coefficient;
            return(force);
        }
Ejemplo n.º 4
0
        public void checkwall(Physics_Entity entity, float top, float bottom, float left, float right)
        {
            if (entity.Position.X < left || entity.Position.X > right)
            {
                Vector2 newvel = new Vector2(entity.Velocity.X * -1, entity.Velocity.Y);
                entity.Velocity = newvel;
            }

            if (entity.Position.Y < bottom || entity.Position.Y > top)
            {
                Vector2 newvel = new Vector2(entity.Velocity.X, entity.Velocity.Y * -1);
                entity.Velocity = newvel;
            }
        }
Ejemplo n.º 5
0
 public void updatepos(Physics_Entity entity, float dt)
 {
     entity.Position    = entity.Position + entity.Force * dt;
     entity.Oldposition = entity.Position;
     entity.Position    = entity.Position + entity.Velocity * dt;
 }