Пример #1
0
 public GameObject(uint id, Vector2f position, Vector2f size, double weight,
                   Vector2f colliderOffset, bool isSolid, bool isStatic)
 {
     Init();
     ID   = id;
     Body = new PhysicalModel(position, size, weight, colliderOffset, isSolid, isStatic);
 }
Пример #2
0
        private void ChangeVelocity(PhysicalModel first, PhysicalModel second)
        {
            var ox = (first.Incircle.Center - second.Incircle.Center).Normalize();
            var oy = ox.Orthogonal();

            var v1x = first.Velocity.ProectionTo(ox).X / ox.X;
            var v1y = first.Velocity - first.Velocity.ProectionTo(ox);

            var v2x = second.Velocity.ProectionTo(ox).X / ox.X;
            var v2y = second.Velocity - second.Velocity.ProectionTo(ox);

            var m1 = first.Weight;
            var m2 = second.Weight;

            var newV1x = ((m1 - m2) * v1x + 2 * m2 * v2x) / (m1 + m2);
            var newV2x = ((m2 - m1) * v2x + 2 * m1 * v1x) / (m1 + m2);

            // if one of the objects is static
            // it will just reflect non-static object speed
            newV1x = Double.IsNaN(newV1x) ? -v1x * StaticResistance : newV1x;
            newV2x = Double.IsNaN(newV2x) ? -v2x * StaticResistance : newV2x;

            newV1x = Double.IsNaN(newV1x) ? 0 : newV1x;
            newV2x = Double.IsNaN(newV2x) ? 0 : newV2x;

            first.Velocity  = ox.Normalize() * (float)newV1x + v1y;
            second.Velocity = ox.Normalize() * (float)newV2x + v2y;
        }
Пример #3
0
 public GameObject(uint id, Vector2f position, Vector2f size, double weight, 
     Vector2f colliderOffset, bool isSolid, bool isStatic)
 {
     Init();
     ID = id;
     Body = new PhysicalModel(position, size, weight, colliderOffset, isSolid, isStatic);
 }
Пример #4
0
        public Camera(Vector2f position)
        {
            Body          = new PhysicalModel(position, new Vector2f(), 0, false, true);
            Lighting      = new List <Light>();
            LockOffset    = new Vector2f();
            ReactionSpeed = 1.0f;

            myActionScripts    = new List <IActionScript>();
            myKeyboardScripts  = new List <IKeyboardScript>();
            myCollisionScripts = new List <ICollisionScript>();
        }
Пример #5
0
        public Camera(Vector2f position)
        {
            Body = new PhysicalModel(position, new Vector2f(), 0, false, true);
            Lighting = new List<Light>();
            LockOffset = new Vector2f();
            ReactionSpeed = 1.0f;

            myActionScripts = new List<IActionScript>();
            myKeyboardScripts = new List<IKeyboardScript>();
            myCollisionScripts = new List<ICollisionScript>();
        }
Пример #6
0
        private void UpdatePosition(PhysicalModel body)
        {
            body.Position += body.Velocity;

            // check if solid object is outside map borders
            if (body.IsSolid)
            {
                var target = body.Collider;
                var x      = Math.Max(Math.Min(body.Collider.Position.X, master.Size.X - body.Collider.Size.X), 0);
                var y      = Math.Max(Math.Min(body.Collider.Position.Y, master.Size.Y - body.Collider.Size.Y), 0);
                body.Position = new Vector2f(x, y) - body.ColliderOffset;
            }
        }
Пример #7
0
        private bool AreIntersect(PhysicalModel first, PhysicalModel second)
        {
            switch (mode)
            {
            case PhysicsMode.Incircle:
                return(first.Incircle.Intersects(second.Incircle));

            case PhysicsMode.Сircumcircle:
                return(first.Circumcircle.Intersects(second.Circumcircle));

            default:
                return(first.Collider.Intersects(second.Collider));
            }
        }
Пример #8
0
        private Vector2f GetDelta(PhysicalModel first, PhysicalModel second)
        {
            switch (mode)
            {
            case PhysicsMode.Incircle:
                return(RoundShape.GetEjectingVector(first.Incircle, second.Incircle));

            case PhysicsMode.Сircumcircle:
                return(RoundShape.GetEjectingVector(first.Circumcircle, second.Circumcircle));

            default:
                return(AABB.GetEjectingVector(first.Collider, second.Collider));
            }
        }
Пример #9
0
        private void ChangeVelocity(PhysicalModel first, PhysicalModel second)
        {
            var ox = (first.Incircle.Center - second.Incircle.Center).Normalize();
            var oy = ox.Orthogonal();

            var v1x = first.Velocity.ProectionTo(ox).X / ox.X;
            var v1y = first.Velocity - first.Velocity.ProectionTo(ox);

            var v2x = second.Velocity.ProectionTo(ox).X / ox.X;
            var v2y = second.Velocity - second.Velocity.ProectionTo(ox);

            var m1 = first.Weight;
            var m2 = second.Weight;

            var newV1x = ((m1 - m2) * v1x + 2 * m2 * v2x) / (m1 + m2);
            var newV2x = ((m2 - m1) * v2x + 2 * m1 * v1x) / (m1 + m2);

            // if one of the objects is static
            // it will just reflect non-static object speed
            newV1x = Double.IsNaN(newV1x) ? -v1x * StaticResistance : newV1x;
            newV2x = Double.IsNaN(newV2x) ? -v2x * StaticResistance : newV2x;

            newV1x = Double.IsNaN(newV1x) ? 0 : newV1x;
            newV2x = Double.IsNaN(newV2x) ? 0 : newV2x;

            first.Velocity = ox.Normalize() * (float)newV1x + v1y;
            second.Velocity = ox.Normalize() * (float)newV2x + v2y;
        }
Пример #10
0
 private bool AreIntersect(PhysicalModel first, PhysicalModel second)
 {
     switch (mode)
     {
         case PhysicsMode.Incircle:
             return first.Incircle.Intersects(second.Incircle);
         case PhysicsMode.Сircumcircle:
             return first.Circumcircle.Intersects(second.Circumcircle);
         default:
             return first.Collider.Intersects(second.Collider);
     }
 }
Пример #11
0
        private void UpdatePosition(PhysicalModel body)
        {
            body.Position += body.Velocity;

            // check if solid object is outside map borders
            if (body.IsSolid)
            {
                var target = body.Collider;
                var x = Math.Max(Math.Min(body.Collider.Position.X, master.Size.X - body.Collider.Size.X), 0);
                var y = Math.Max(Math.Min(body.Collider.Position.Y, master.Size.Y - body.Collider.Size.Y), 0);
                body.Position = new Vector2f(x, y) - body.ColliderOffset;
            }
        }
Пример #12
0
 private Vector2f GetDelta(PhysicalModel first, PhysicalModel second)
 {
     switch (mode)
     {
         case PhysicsMode.Incircle:
             return RoundShape.GetEjectingVector(first.Incircle, second.Incircle);
         case PhysicsMode.Сircumcircle:
             return RoundShape.GetEjectingVector(first.Circumcircle, second.Circumcircle);
         default:
             return AABB.GetEjectingVector(first.Collider, second.Collider);
     }
 }