Ejemplo n.º 1
0
        public Line(MatrixPoint p1, MatrixPoint p2)
        {
            point1 = p1;
            point2 = p2;

            rise = RightPoint.Yd - LeftPoint.Yd;
            run = RightPoint.Xd - LeftPoint.Xd;
        }
Ejemplo n.º 2
0
        public Line(Line l)
        {
            this.point1 = l.point1;
            this.point2 = l.point2;

            rise = RightPoint.Yd - LeftPoint.Yd;
            run = RightPoint.Xd - LeftPoint.Xd;
        }
Ejemplo n.º 3
0
 public Entity(GameController ga)
 {
     this.parent = ga;
     this.Outline = new List<Line>();
     this.centre = new MatrixPoint(0, 0);
     this.Expired = false;
     this.parent.AddGameObject(this);
 }
Ejemplo n.º 4
0
        public Missile(GameController ga, Angle orientation, MatrixPoint centre, double range)
            : base(ga)
        {
            //body
            this.Outline.Add(new Line(new MatrixPoint(0, -2), new MatrixPoint(0, 2)));

            Rotate(orientation.Radians);
            this.Centre = centre;
            this.Move(5); // we make an initial move so we don't destroy whatever ever fired us

            this.Range = range;
            this.trace = this.Centre;

            distanceTravelled = 0;
        }
Ejemplo n.º 5
0
        public static Angle OrientationBetween(MatrixPoint p1, MatrixPoint p2)
        {
            MatrixPoint p = p2 - p1;

            double rise = p.Yd;
            double run = p.Xd;

            if (rise != 0.0 && run != 0.0)
            {
                if (rise > 0 && run > 0)
                {
                    return new Angle(Math.Atan(run / rise));
                }
                else if (rise < 0 && run > 0)
                {
                    return new Angle(Math.PI + Math.Atan(run / rise));
                }
                else if (rise < 0 && run < 0)
                {
                    return new Angle(Math.PI + Math.Atan(run / rise));
                }
                else if (rise > 0 && run < 0)
                {
                    return new Angle((2 * Math.PI) + Math.Atan(run / rise));
                }
            }
            else
            {
                if (rise == 0 && run > 0)
                {
                    return new Angle(Math.PI/2);
                }
                else if (rise < 0 && run == 0)
                {
                    return new Angle(Math.PI);
                }
                else if (rise == 0 && run < 0)
                {
                    return new Angle((Math.PI / 2) + Math.PI);
                }
                else if (rise > 0 && run == 0)
                {
                    return new Angle(0);
                }
            }
            return new Angle();
        }
Ejemplo n.º 6
0
 public static double DistanceBetween(MatrixPoint p1, MatrixPoint p2)
 {
     double rise = p2.Yd - p1.Yd;
     double run = p2.Xd - p1.Xd;
     return Math.Sqrt(rise * rise + run * run);
 }
Ejemplo n.º 7
0
        public virtual void Move(double speed)
        {
            // we want the speed to be constant whatever direction the item is travelling
            // so when direction is non-orthogonal make the distance driven the length of the hypotenuse
            // and determine the x,y values accordingly

            double p1y = CentreLine.Point1.Matrix.GetValue(2, 1);
            double p1x = CentreLine.Point1.Matrix.GetValue(1, 1);

            double p2y = CentreLine.Point2.Matrix.GetValue(2, 1);
            double p2x = CentreLine.Point2.Matrix.GetValue(1, 1);

            double rise = p1y - p2y;
            double run = p1x - p2x;

            double h = Math.Sqrt((rise * rise) + (run * run));
            double factor = speed / h;

            Centre -= new MatrixPoint(factor * run, factor * rise);
        }
Ejemplo n.º 8
0
        public void TestOrientationCalcs2()
        {
            MatrixPoint centre = new MatrixPoint(1, 1);

            MatrixPoint p1 = new MatrixPoint(6, 6);
            MatrixPoint p2 = new MatrixPoint(6, -4);
            MatrixPoint p3 = new MatrixPoint(-4, -4);
            MatrixPoint p4 = new MatrixPoint(-4, 6);

            Assert.AreEqual(Math.Round(Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p1).Radians, 9), "Orientation check 1");
            Assert.AreEqual(Math.Round(3 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p2).Radians, 9), "Orientation check 2");
            Assert.AreEqual(Math.Round(5 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p3).Radians, 9), "Orientation check 3");
            Assert.AreEqual(Math.Round(7 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p4).Radians, 9), "Orientation check 4");
        }
Ejemplo n.º 9
0
        public void TestOrientationCalcs1()
        {
            MatrixPoint centre = new MatrixPoint(0, 0);

            MatrixPoint p1 = new MatrixPoint(5, 5);
            MatrixPoint p2 = new MatrixPoint(5, -5);
            MatrixPoint p3 = new MatrixPoint(-5, -5);
            MatrixPoint p4 = new MatrixPoint(-5, 5);

            MatrixPoint p5 = new MatrixPoint(0, 5);
            MatrixPoint p6 = new MatrixPoint(5, 0);
            MatrixPoint p7 = new MatrixPoint(0, -5);
            MatrixPoint p8 = new MatrixPoint(-5, 0);

            MatrixPoint p1a = new MatrixPoint(4, 5);
            MatrixPoint p1b = new MatrixPoint(6, 5);
            MatrixPoint p2a = new MatrixPoint(6, -5);
            MatrixPoint p2b = new MatrixPoint(4, -5);
            MatrixPoint p3a = new MatrixPoint(-4, -5);
            MatrixPoint p3b = new MatrixPoint(-6, -5);
            MatrixPoint p4a = new MatrixPoint(-6, 5);
            MatrixPoint p4b = new MatrixPoint(-4, 5);

            Assert.AreEqual(Math.Round(0.674740942, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p1a).Radians, 9), "Orientation check 1a");
            Assert.AreEqual(Math.Round(Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p1).Radians, 9), "Orientation check 1");
            Assert.AreEqual(Math.Round(0.876058051, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p1b).Radians, 9), "Orientation check 1b");

            Assert.AreEqual(Math.Round(0.6947382762 + Math.PI / 2, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p2a).Radians, 9), "Orientation check 2a");
            Assert.AreEqual(Math.Round(3 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p2).Radians, 9), "Orientation check 2");
            Assert.AreEqual(Math.Round(0.89605538457134 + Math.PI / 2, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p2b).Radians, 9), "Orientation check 2b");

            Assert.AreEqual(Math.Round(0.67474094222 + Math.PI, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p3a).Radians, 9), "Orientation check 3a");
            Assert.AreEqual(Math.Round(5 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p3).Radians, 9), "Orientation check 3");
            Assert.AreEqual(Math.Round(0.87605805060 + Math.PI, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p3b).Radians, 9), "Orientation check 3b");

            Assert.Greater(Math.Round(7 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p4a).Radians, 9), "Orientation check 4a");
            Assert.AreEqual(Math.Round(7 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p4).Radians, 9), "Orientation check 4");
            Assert.Less(Math.Round(7 * Math.PI / 4, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p4b).Radians, 9), "Orientation check 4b");

            Assert.AreEqual(Math.Round(0.0, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p5).Radians, 9), "Orientation check 5");
            Assert.AreEqual(Math.Round(Math.PI / 2, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p6).Radians, 9), "Orientation check 6");
            Assert.AreEqual(Math.Round(Math.PI, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p7).Radians, 9), "Orientation check 7");
            Assert.AreEqual(Math.Round(Math.PI + Math.PI / 2, 9), Math.Round(MatrixPoint.OrientationBetween(centre, p8).Radians, 9), "Orientation check 8");
        }