Ejemplo n.º 1
0
        public void PerpendicularVector2DTest()
        {
            Vector test = new Vector(3, 2);
            Vector perpendicular = test.PerpendicularVector2D();

            Assert.AreEqual(0, test.DotProduct(perpendicular), "Error: the dot product of orthoginal vectors should be 0.");
            Assert.AreEqual(test.Magnitude, perpendicular.Magnitude, "Error: the magnitude of orthoginal vectors should be the same.");
        }
        /// <summary>
        /// Constructs bullet entity.
        /// </summary>
        /// <param name="bulletColour">Colour of bullet.</param>
        /// <param name="bulletType">Type of bullet.</param>
        /// <param name="owner">Owner of bullet.</param>
        /// <param name="position">Spawn position of bullet.</param>
        /// <param name="trajectory">Trajectory of bullet.</param>
        public BulletEntity(BulletColour bulletColour, BulletType bulletType, Entity owner, Point position, Vector trajectory) : base(bulletType.ToString() + bulletColour.ToString(), InitBounding(bulletType, position, trajectory), 1)
        {
            _bulletColour = bulletColour;
            _bulletType   = bulletType;
            _owner        = owner;
            _trajectory   = trajectory;
            _grazed       = false;

            _movement = new Linear(trajectory);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs bullet entity.
        /// </summary>
        /// <param name="bulletColour">Colour of bullet.</param>
        /// <param name="bulletType">Type of bullet.</param>
        /// <param name="owner">Owner of bullet.</param>
        /// <param name="position">Spawn position of bullet.</param>
        /// <param name="trajectory">Trajectory of bullet.</param>
        public BulletEntity(BulletColour bulletColour, BulletType bulletType, Entity owner, Point position, Vector trajectory)
            : base(bulletType.ToString() + bulletColour.ToString(), InitBounding(bulletType, position, trajectory), 1)
        {
            _bulletColour = bulletColour;
            _bulletType = bulletType;
            _owner = owner;
            _trajectory = trajectory;
            _grazed = false;

            _movement = new Linear(trajectory);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes step in movement.
        /// </summary>
        public override void step()
        {
            UM.Vector v = Velocity;
            v += Acceleration;

            if (v.Magnitude > _terminal)
            {
                v.Magnitude = _terminal;
            }

            Velocity = v;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Processes entity movement.
        /// </summary>
        public override void ProcessMovement()
        {
            if (_flag)
            {
                Vector velocity = new Vector(GameObjects.Player.Hitbox.Centroid, Hitbox.Centroid);

                if (velocity.Magnitude > 5)
                {
                    velocity.Magnitude = 5;
                }

                _movement = new Linear(velocity);
            }

            _movement.step();
            Offset(_movement.Velocity);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Calculates the difference from minuend (minuend - subtrahend = difference).
        /// </summary>
        /// <param name="minuend">Minuend vector.</param>
        /// <returns>Difference.</returns>
        public Vector DifferenceFrom(Vector minuend)
        {
            Vector result = this;

            result.I = result.DifferenceFromI(minuend);
            result.J = result.DifferenceFromJ(minuend);
            result.K = result.DifferenceFromK(minuend);

            return result;
        }
 /// <summary>
 /// Offsets the player by the given movement.
 /// </summary>
 /// <param name="movement">Movement.</param>
 public override void Offset(Vector movement)
 {
     base.Offset(movement);
     _grazebox.Offset(movement);
 }
 public static void ProjectPolygon(Vector axis, Polygon polygon, ref double min, ref double max)
 {
     double dotProduct = axis.DotProduct(polygon.Vertices[0].ToVector());
     min = dotProduct;
     max = dotProduct;
     for(int i = 0; i < polygon.Vertices.Count; i++)
     {
         dotProduct = polygon.Vertices[i].ToVector().DotProduct(axis);
         if(dotProduct < min)
         {
             min = dotProduct;
         }
         else if(dotProduct > max)
         {
             max = dotProduct;
         }
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Constructs basic linear movement.
 /// </summary>
 /// <param name="velocity">Velosity vector.</param>
 public Linear(UM.Vector velocity) : base(velocity)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Calculates sum of j.
 /// </summary>
 /// <param name="addend">Addend vector.</param>
 /// <returns>Sum of j.</returns>
 public double SumInJ(Vector addend)
 {
     return _j + addend.J;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Calculates sum.
        /// </summary>
        /// <param name="addend">Addend vector.</param>
        /// <returns>Sum of vectors.</returns>
        public Vector Sum(Vector addend)
        {
            Vector result = this;

            result.I = result.SumInI(addend);
            result.J = result.SumInJ(addend);
            result.K = result.SumInK(addend);

            return result;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Calculates the dot product.
 /// </summary>
 /// <param name="multiplier">Multiplier vector.</param>
 /// <returns>Dot "scalar" product.</returns>
 public double DotProduct(Vector multiplier)
 {
     return _i * multiplier.I + _j * multiplier.J + _k * multiplier.K;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Offsets the player by the given movement.
 /// </summary>
 /// <param name="movement">Movement.</param>
 public override void Offset(Vector movement)
 {
     base.Offset(movement);
     _grazebox.Offset(movement);
 }
Ejemplo n.º 14
0
        private static Polygon InitBounding(BulletType bulletType, Point position, Vector trajectory)
        {
            Point[] vertices = new Point[]
            {
                new Point(0, 0),
                new Point(15, 0),
                new Point(15, 15),
                new Point(0, 15)
            };

            switch (bulletType)
            {
                case BulletType.Beam:
                    vertices = new Point[]
                    {
                        new Point(0, 0),
                        new Point(15, 0),
                        new Point(15, 15),
                        new Point(0, 15)
                    };
                    break;

                case BulletType.BigStar:
                    vertices = new Point[]
                    {
                        new Point(2, 13),
                        new Point(11, 10),
                        new Point(15, 3),
                        new Point(16, 3),
                        new Point(20, 10),
                        new Point(29, 13),
                        new Point(24, 20),
                        new Point(23, 28),
                        new Point(16, 25),
                        new Point(15, 25),
                        new Point(8, 28),
                        new Point(6, 20)
                    };
                    break;

                case BulletType.Crystal:
                    vertices = new Point[]
                    {
                        new Point(4, 5),
                        new Point(7, 0),
                        new Point(8, 0),
                        new Point(11, 5),
                        new Point(11, 10),
                        new Point(8, 15),
                        new Point(7, 15),
                        new Point(4, 10)
                    };
                    break;

                case BulletType.Dart:
                    vertices = new Point[]
                    {
                        new Point(4, 7),
                        new Point(7, 0),
                        new Point(8, 0),
                        new Point(11, 7),
                        new Point(9, 8),
                        new Point(9, 9),
                        new Point(11, 11),
                        new Point(11, 13),
                        new Point(9, 15),
                        new Point(6, 15),
                        new Point(4, 13),
                        new Point(4, 11),
                        new Point(6, 9),
                        new Point(6, 8)
                    };
                    break;

                case BulletType.HugeSphere:
                    vertices = new Point[]
                    {
                        new Point(7, 27),
                        new Point(10, 19),
                        new Point(14, 14),
                        new Point(19, 10),
                        new Point(27, 7),
                        new Point(36, 7),
                        new Point(44, 10),
                        new Point(49, 14),
                        new Point(53, 19),
                        new Point(56, 27),
                        new Point(56, 36),
                        new Point(53, 44),
                        new Point(49, 49),
                        new Point(44, 53),
                        new Point(36, 56),
                        new Point(27, 56),
                        new Point(19, 53),
                        new Point(14, 49),
                        new Point(10, 44),
                        new Point(7, 36)
                    };
                    break;

                case BulletType.LargeSphere:
                    vertices = new Point[]
                    {
                        new Point(3, 13),
                        new Point(5, 8),
                        new Point(8, 5),
                        new Point(13, 3),
                        new Point(18, 3),
                        new Point(23, 5),
                        new Point(26, 8),
                        new Point(28, 13),
                        new Point(28, 18),
                        new Point(26, 23),
                        new Point(23, 26),
                        new Point(18, 28),
                        new Point(13, 28),
                        new Point(8, 26),
                        new Point(5, 23),
                        new Point(3, 18)
                    };
                    break;

                case BulletType.Palse:
                    vertices = new Point[]
                    {
                        new Point(0, 13),
                        new Point(3, 6),
                        new Point(7, 2),
                        new Point(8, 2),
                        new Point(12, 6),
                        new Point(15, 13),
                        new Point(13, 15),
                        new Point(11, 9),
                        new Point(10, 13),
                        new Point(8, 15),
                        new Point(7, 15),
                        new Point(5, 13),
                        new Point(4, 9),
                        new Point(2, 15)
                    };
                    break;

                case BulletType.Ring:
                    vertices = new Point[]
                    {
                        new Point(0, 6),
                        new Point(2, 2),
                        new Point(6, 0),
                        new Point(9, 0),
                        new Point(13, 2),
                        new Point(15, 6),
                        new Point(15, 9),
                        new Point(13, 13),
                        new Point(9, 15),
                        new Point(6, 15),
                        new Point(2, 13),
                        new Point(0, 9)
                    };
                    break;

                case BulletType.Seed:
                    vertices = new Point[]
                    {
                        new Point(4, 6),
                        new Point(5, 3),
                        new Point(7, 1),
                        new Point(8, 1),
                        new Point(10, 3),
                        new Point(11, 6),
                        new Point(11, 9),
                        new Point(10, 12),
                        new Point(8, 14),
                        new Point(7, 14),
                        new Point(5, 12),
                        new Point(4, 9)
                    };
                    break;

                case BulletType.Shere:
                    vertices = new Point[]
                    {
                        new Point(1, 6),
                        new Point(3, 3),
                        new Point(6, 1),
                        new Point(9, 1),
                        new Point(12, 3),
                        new Point(14, 6),
                        new Point(14, 9),
                        new Point(12, 12),
                        new Point(9, 14),
                        new Point(6, 14),
                        new Point(3, 12),
                        new Point(1, 9)
                    };
                    break;

                case BulletType.SmallRing:
                    vertices = new Point[]
                    {
                        new Point(0, 4),
                        new Point(1, 1),
                        new Point(4, 0),
                        new Point(7, 0),
                        new Point(10, 1),
                        new Point(11, 4),
                        new Point(11, 7),
                        new Point(10, 10),
                        new Point(7, 11),
                        new Point(4, 11),
                        new Point(1, 10),
                        new Point(0, 7)
                    };
                    break;

                case BulletType.SmallSphere:
                    vertices = new Point[]
                    {
                        new Point(1, 4),
                        new Point(4, 1),
                        new Point(7, 1),
                        new Point(10, 4),
                        new Point(10, 7),
                        new Point(7, 10),
                        new Point(4, 10),
                        new Point(1, 7)
                    };
                    break;

                case BulletType.Star:
                    vertices = new Point[]
                    {
                        new Point(1, 6),
                        new Point(5, 5),
                        new Point(7, 2),
                        new Point(8, 2),
                        new Point(10, 5),
                        new Point(14, 6),
                        new Point(11, 10),
                        new Point(11, 14),
                        new Point(8, 12),
                        new Point(7, 12),
                        new Point(4, 14),
                        new Point(4, 10)
                    };
                    break;
            }

            Polygon bounding = new Polygon(vertices, position);

            double angle = 2 * Math.PI - trajectory.Phi - BasicMath.ToRad(90);

            bounding.YawZ(angle, bounding.Middle);

            return bounding;
        }
Ejemplo n.º 15
0
        public void MagnitudeTest()
        {
            Vector test = new Vector(3, 2);

            Assert.AreEqual(Math.Sqrt(13), test.Magnitude, "Error: Magnitude of test vector should be the square route of 13.");
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Offsets the polygon by the given movment vector.
 /// </summary>
 /// <param name="movement">Movement vector.</param>
 public void Offset(Vector movement)
 {
     for(int i = 0; i < _vertices.Count; i++)
     {
         _vertices[i] = _vertices[i].Offset(movement);
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Constructs movement with provided delta.
 /// </summary>
 /// <param name="velocity">Vector with movement information.</param>
 public Movement(UM.Vector velocity)
 {
     _velocity = velocity;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Offsets Game Object by given Movement Vector.
 /// </summary>
 /// <param name="movement">Movement Vector.</param>
 public virtual void Offset(Vector movement)
 {
     _position.Offset(movement);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Offsets Game Object by given Movement Vector.
 /// </summary>
 /// <param name="movement">Movement Vector.</param>
 public virtual void Offset(Vector movement)
 {
     _position.Offset(movement);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Calculates difference from k.
 /// </summary>
 /// <param name="subtrahend">Subtrahend vector.</param>
 /// <returns>Difference from k.</returns>
 public double DifferenceByK(Vector subtrahend)
 {
     return _k - subtrahend.K;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Calculates difference from minuend.
 /// </summary>
 /// <param name="minuend">Minuend Vector.</param>
 /// <returns>Difference from muniend.</returns>
 public double DifferenceFromJ(Vector minuend)
 {
     return minuend.J - _j;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Calculates difference from minuend.
 /// </summary>
 /// <param name="minuend">Minuend Vector.</param>
 /// <returns>Difference from muniend.</returns>
 public double DifferenceFromI(Vector minuend)
 {
     return minuend.I - _i;
 }
Ejemplo n.º 23
0
        private static Polygon InitBounding(BulletType bulletType, Point position, Vector trajectory)
        {
            Point[] vertices = new Point[]
            {
                new Point(0, 0),
                new Point(15, 0),
                new Point(15, 15),
                new Point(0, 15)
            };

            switch (bulletType)
            {
            case BulletType.Beam:
                vertices = new Point[]
                {
                    new Point(0, 0),
                    new Point(15, 0),
                    new Point(15, 15),
                    new Point(0, 15)
                };
                break;

            case BulletType.BigStar:
                vertices = new Point[]
                {
                    new Point(2, 13),
                    new Point(11, 10),
                    new Point(15, 3),
                    new Point(16, 3),
                    new Point(20, 10),
                    new Point(29, 13),
                    new Point(24, 20),
                    new Point(23, 28),
                    new Point(16, 25),
                    new Point(15, 25),
                    new Point(8, 28),
                    new Point(6, 20)
                };
                break;

            case BulletType.Crystal:
                vertices = new Point[]
                {
                    new Point(4, 5),
                    new Point(7, 0),
                    new Point(8, 0),
                    new Point(11, 5),
                    new Point(11, 10),
                    new Point(8, 15),
                    new Point(7, 15),
                    new Point(4, 10)
                };
                break;

            case BulletType.Dart:
                vertices = new Point[]
                {
                    new Point(4, 7),
                    new Point(7, 0),
                    new Point(8, 0),
                    new Point(11, 7),
                    new Point(9, 8),
                    new Point(9, 9),
                    new Point(11, 11),
                    new Point(11, 13),
                    new Point(9, 15),
                    new Point(6, 15),
                    new Point(4, 13),
                    new Point(4, 11),
                    new Point(6, 9),
                    new Point(6, 8)
                };
                break;

            case BulletType.HugeSphere:
                vertices = new Point[]
                {
                    new Point(7, 27),
                    new Point(10, 19),
                    new Point(14, 14),
                    new Point(19, 10),
                    new Point(27, 7),
                    new Point(36, 7),
                    new Point(44, 10),
                    new Point(49, 14),
                    new Point(53, 19),
                    new Point(56, 27),
                    new Point(56, 36),
                    new Point(53, 44),
                    new Point(49, 49),
                    new Point(44, 53),
                    new Point(36, 56),
                    new Point(27, 56),
                    new Point(19, 53),
                    new Point(14, 49),
                    new Point(10, 44),
                    new Point(7, 36)
                };
                break;

            case BulletType.LargeSphere:
                vertices = new Point[]
                {
                    new Point(3, 13),
                    new Point(5, 8),
                    new Point(8, 5),
                    new Point(13, 3),
                    new Point(18, 3),
                    new Point(23, 5),
                    new Point(26, 8),
                    new Point(28, 13),
                    new Point(28, 18),
                    new Point(26, 23),
                    new Point(23, 26),
                    new Point(18, 28),
                    new Point(13, 28),
                    new Point(8, 26),
                    new Point(5, 23),
                    new Point(3, 18)
                };
                break;

            case BulletType.Palse:
                vertices = new Point[]
                {
                    new Point(0, 13),
                    new Point(3, 6),
                    new Point(7, 2),
                    new Point(8, 2),
                    new Point(12, 6),
                    new Point(15, 13),
                    new Point(13, 15),
                    new Point(11, 9),
                    new Point(10, 13),
                    new Point(8, 15),
                    new Point(7, 15),
                    new Point(5, 13),
                    new Point(4, 9),
                    new Point(2, 15)
                };
                break;

            case BulletType.Ring:
                vertices = new Point[]
                {
                    new Point(0, 6),
                    new Point(2, 2),
                    new Point(6, 0),
                    new Point(9, 0),
                    new Point(13, 2),
                    new Point(15, 6),
                    new Point(15, 9),
                    new Point(13, 13),
                    new Point(9, 15),
                    new Point(6, 15),
                    new Point(2, 13),
                    new Point(0, 9)
                };
                break;

            case BulletType.Seed:
                vertices = new Point[]
                {
                    new Point(4, 6),
                    new Point(5, 3),
                    new Point(7, 1),
                    new Point(8, 1),
                    new Point(10, 3),
                    new Point(11, 6),
                    new Point(11, 9),
                    new Point(10, 12),
                    new Point(8, 14),
                    new Point(7, 14),
                    new Point(5, 12),
                    new Point(4, 9)
                };
                break;

            case BulletType.Shere:
                vertices = new Point[]
                {
                    new Point(1, 6),
                    new Point(3, 3),
                    new Point(6, 1),
                    new Point(9, 1),
                    new Point(12, 3),
                    new Point(14, 6),
                    new Point(14, 9),
                    new Point(12, 12),
                    new Point(9, 14),
                    new Point(6, 14),
                    new Point(3, 12),
                    new Point(1, 9)
                };
                break;

            case BulletType.SmallRing:
                vertices = new Point[]
                {
                    new Point(0, 4),
                    new Point(1, 1),
                    new Point(4, 0),
                    new Point(7, 0),
                    new Point(10, 1),
                    new Point(11, 4),
                    new Point(11, 7),
                    new Point(10, 10),
                    new Point(7, 11),
                    new Point(4, 11),
                    new Point(1, 10),
                    new Point(0, 7)
                };
                break;

            case BulletType.SmallSphere:
                vertices = new Point[]
                {
                    new Point(1, 4),
                    new Point(4, 1),
                    new Point(7, 1),
                    new Point(10, 4),
                    new Point(10, 7),
                    new Point(7, 10),
                    new Point(4, 10),
                    new Point(1, 7)
                };
                break;

            case BulletType.Star:
                vertices = new Point[]
                {
                    new Point(1, 6),
                    new Point(5, 5),
                    new Point(7, 2),
                    new Point(8, 2),
                    new Point(10, 5),
                    new Point(14, 6),
                    new Point(11, 10),
                    new Point(11, 14),
                    new Point(8, 12),
                    new Point(7, 12),
                    new Point(4, 14),
                    new Point(4, 10)
                };
                break;
            }

            Polygon bounding = new Polygon(vertices, position);

            double angle = 2 * Math.PI - trajectory.Phi - BasicMath.ToRad(90);

            bounding.YawZ(angle, bounding.Middle);

            return(bounding);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Calculates difference from minuend.
 /// </summary>
 /// <param name="minuend">Minuend Vector.</param>
 /// <returns>Difference from muniend.</returns>
 public double DifferenceFromK(Vector minuend)
 {
     return minuend.K - _k;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Offsets the entity by the given movement vector.
 /// </summary>
 /// <param name="movement">Movement vector.</param>
 public virtual void Offset(Vector movement)
 {
     _hitbox.Offset(movement);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Projects vector onto the vector provided.
 /// </summary>
 /// <param name="vector">Vector to project onto.</param>
 /// <returns>Projected vector.</returns>
 public Vector Project(Vector vector)
 {
     return vector.Unit * (DotProduct(vector) / vector.Magnitude);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Constructs movement with provided delta.
 /// </summary>
 /// <param name="velocity">Vector with movement information.</param>
 public Movement(UM.Vector velocity)
 {
     _velocity = velocity;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Calculates sum of i.
 /// </summary>
 /// <param name="addend">Addend vector.</param>
 /// <returns>Sum of i.</returns>
 public double SumInI(Vector addend)
 {
     return _i + addend.I;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Offsets the entity by the given movement vector.
 /// </summary>
 /// <param name="movement">Movement vector.</param>
 public virtual void Offset(Vector movement)
 {
     _hitbox.Offset(movement);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Calculates sum of k.
 /// </summary>
 /// <param name="addend">Addend vector.</param>
 /// <returns>Sum of k.</returns>
 public double SumInK(Vector addend)
 {
     return _k + addend.K;
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Calculates the corss product.
        /// </summary>
        /// <param name="multiplier">Multiplyer vector.</param>
        /// <returns>Cross "vector" product.</returns>
        public Vector CrossProduct(Vector multiplier)
        {
            Vector result = new Vector(1, -1, 1);

            result.I = result.I * (_j * multiplier.K - _k * multiplier.J);
            result.J = result.J * (_i * multiplier.K - _k * multiplier.I);
            result.K = result.K * (_i * multiplier.J - _j * multiplier.I);

            return result;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Processes entity movement.
        /// </summary>
        public override void ProcessMovement()
        {
            if(_flag)
            {
                Vector velocity = new Vector(GameObjects.Player.Hitbox.Centroid, Hitbox.Centroid);

                if(velocity.Magnitude > 5)
                {
                    velocity.Magnitude = 5;
                }

                _movement = new Linear(velocity);
            }

            _movement.step();
            Offset(_movement.Velocity);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Calculates difference from vector (minuend - subtrahend = difference).
        /// </summary>
        /// <param name="subtrahend">Subtrahend vector.</param>
        /// <returns>Difference.</returns>
        public Vector DifferenceBy(Vector subtrahend)
        {
            Vector result = this;

            result.I = result.DifferenceByI(subtrahend);
            result.J = result.DifferenceByJ(subtrahend);
            result.K = result.DifferenceByK(subtrahend);

            return result;
        }
        public static PolygonCollisionResult PolygonCollision(Polygon a, Polygon b, Vector velocity)
        {
            PolygonCollisionResult result = new PolygonCollisionResult();
            result.WillIntersect = true;
            result.Intersect = true;

            int edgeCountA = a.Edges.Count;
            int edgeCountB = b.Edges.Count;
            double minIntervalDistance = double.PositiveInfinity;
            Vector traslationAxis = new Vector();
            Vector edge;

            for(int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++)
            {
                if(edgeIndex < edgeCountA)
                {
                    edge = a.Edges[edgeIndex];
                }
                else
                {
                    edge = b.Edges[edgeIndex - edgeCountA];
                }

                Vector axis = edge.PerpendicularVector2D();
                axis = axis.Unit;

                double minA = 0;
                double maxA = 0;
                double minB = 0;
                double maxB = 0;

                ProjectPolygon(axis, a, ref minA, ref maxA);
                ProjectPolygon(axis, b, ref minB, ref maxB);

                if (IntervalDisance(minA, maxA, minB, maxB) > 0)
                {
                    result.Intersect = false;
                }

                double velosityProjection = axis.DotProduct(velocity);

                if(velosityProjection < 0)
                {
                    minA += velosityProjection;
                }
                else
                {
                    maxA += velosityProjection;
                }

                double intervalDistance = IntervalDisance(minA, maxA, minB, maxB);
                if(intervalDistance > 0)
                {
                    result.WillIntersect = false;
                }

                if(!result.Intersect && !result.WillIntersect)
                {
                    break;
                }

                intervalDistance = Math.Abs(intervalDistance);
                if(intervalDistance < minIntervalDistance)
                {
                    minIntervalDistance = intervalDistance;
                    traslationAxis = axis;

                    Point d = a.Centroid - b.Centroid;
                    if(d.ToVector().DotProduct(traslationAxis) < 0)
                    {
                        traslationAxis = traslationAxis * -1;
                    }
                }
            }

            if(result.WillIntersect)
            {
                result.MinimumTranslationVector = traslationAxis * minIntervalDistance;
            }

            return result;
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Calculates difference from i.
 /// </summary>
 /// <param name="subtrahend">Subtrahend vector.</param>
 /// <returns>Difference from i.</returns>
 public double DifferenceByI(Vector subtrahend)
 {
     return _i - subtrahend.I;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Constructs a force of gravity.
 /// </summary>
 /// <param name="velocity">Velosity of object.</param>
 /// <param name="acceleration">Acceleration force of gravity.</param>
 /// <param name="terminal">Terminal velosity of object.</param>
 public Gravity(UM.Vector velocity, UM.Vector acceleration, double terminal) : base(velocity)
 {
     _acceleration = acceleration;
     _terminal     = terminal;
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Calculates difference from j.
 /// </summary>
 /// <param name="subtrahend">Subtrahend vector.</param>
 /// <returns>Difference from j.</returns>
 public double DifferenceByJ(Vector subtrahend)
 {
     return _j - subtrahend.J;
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Constructs a force of gravity.
 /// </summary>
 /// <param name="velocity">Velosity of object.</param>
 /// <param name="acceleration">Acceleration force of gravity.</param>
 /// <param name="terminal">Terminal velosity of object.</param>
 public Gravity(UM.Vector velocity, UM.Vector acceleration, double terminal)
     : base(velocity)
 {
     _acceleration = acceleration;
     _terminal = terminal;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Offsets the polyhedron by the given movment vector.
 /// </summary>
 /// <param name="movement">Movement vector.</param>
 public void Offset(Vector movement)
 {
     foreach(Polygon face in _faces)
     {
         face.Offset(movement);
     }
 }