public void TestBoundingLineReflect180Bot()
        {
            //Preconfig
            Vector position1 = new Vector(0f, 50f);
            Vector target1 = new Vector(50f, 50f);

            Vector ballSpeed = new Vector(0, -10);
            Vector ballPos = new Vector(20f, 100f);

            Vector hitPoint = new Vector(20, 50);
            Vector expectedReflection = -ballSpeed;
            expectedReflection.Normalize();
            Vector reflection;

            //Creation
            Line parent = new Line();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingLine bL1 = new BoundingLine(position1, target1);
            bCont.AddBoundingBox(bL1);
            parent.Location = (new Vector(0, 0));

            //Operation
            reflection = bL1.Reflect(ballSpeed, hitPoint, ballPos);
            reflection.Normalize();

            //Assertion
            Assert.AreEqual(expectedReflection, reflection);
        }
        public void TestIntersect1pxOverlapBot()
        {
            //Preconfig
            Vector position1 = new Vector(0f, 50f);
            Vector target1 = new Vector(50f, 50f);

            int radius2 = 20;
            Vector center2 = new Vector(20, 49);
            Vector ballSpeed = new Vector(0, -5);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Line parent = new Line();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);

            BoundingLine bL1 = new BoundingLine(position1, target1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);

            bCont.AddBoundingBox(bL1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;
            parent.Location = (new Vector(0, 0));

            //Operation
            isIntersec = bC2.Intersect(bL1, out hitPoint);

            //Assertion
            Assert.IsTrue(isIntersec);
            Assert.AreEqual(new Vector(40,50), hitPoint);
        }
        public void TestPushBackBotRightToCenter()
        {
            //Preconfig
            Vector position1 = new Vector(0f, 50f);
            Vector target1 = new Vector(50f, 50f);

            int radius2 = 20;
            Vector center2 = new Vector(25, 55);
            Vector ballSpeed = new Vector(-5, -5);

            Vector hitPoint = new Vector(20, 50);
            Vector pushBackVec;
            Vector estimatedPushBackVec = new Vector(0, 1);
            estimatedPushBackVec.Normalize();

            //Creation
            Line parent = new Line();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingLine bL1 = new BoundingLine(position1, target1);

            bCont.AddBoundingBox(bL1);
            parent.Location = (new Vector(0, 0));

            //Operation
            pushBackVec = bL1.GetOutOfAreaPush(radius2 * 2, hitPoint, -ballSpeed, center2);
            pushBackVec.Normalize();

            //Assertion
            Assert.AreEqual(estimatedPushBackVec, pushBackVec);
        }
Exemplo n.º 4
0
        protected override void Init()
        {
            base.Init();

            int r1 = 70;
            int r2 = 16;
            Vector mitteKreis = new Vector(140, 295);
            Vector obenKreisLinie = new Vector(180, 241);
            Vector p3 = new Vector(678, 505);
            Vector p4 = new Vector(700, 534);
            Vector circle2 = new Vector(692,546);
            Vector p5 = new Vector(692, 561);
            Vector p6 = new Vector(645, 566);
            Vector p7 = new Vector(116, 355);
            Vector peak = new Vector(707,553);

            r1 = (int)(r1/factor);
            r2 = (int)(r2 / factor);
            mitteKreis /= factor;
            obenKreisLinie /= factor;
            p3 /= factor;
            p4 /= factor;
            circle2 /= factor;
            p5 /= factor;
            p6 /= factor;
            p7 /= factor;
            peak /= factor;

            BoundingCircle bC1 = new BoundingCircle(r1, mitteKreis- new Vector(r1,r1));
            BoundingLine bL1 = new BoundingLine(obenKreisLinie, peak);
            BoundingLine bL2 = new BoundingLine(p3, p4);
            BoundingCircle bC2 = new BoundingCircle(r2, circle2 - new Vector(r2, r2));
            BoundingLine bL3 = new BoundingLine(p5, p6);
            BoundingLine bL4 = new BoundingLine(peak, p7);

            //bL1.bounceFactor = 2;
            this.BoundingContainer.AddBoundingBox(bC1);
            this.BoundingContainer.AddBoundingBox(bL1);
            //this.BoundingContainer.AddBoundingBox(bL2);
            //this.BoundingContainer.AddBoundingBox(bC2);
            //this.BoundingContainer.AddBoundingBox(bL3);
            this.BoundingContainer.AddBoundingBox(bL4);

            /* Version with exact BB
             *  BoundingCircle bC1 = new BoundingCircle(r1, mitteKreis- new Vector(r1,r1));
            BoundingLine bL1 = new BoundingLine(obenKreisLinie, p3);
            BoundingLine bL2 = new BoundingLine(p3, p4);
            BoundingCircle bC2 = new BoundingCircle(r2, circle2 - new Vector(r2, r2));
            BoundingLine bL3 = new BoundingLine(p5, p6);
            BoundingLine bL4 = new BoundingLine(p6, p7);

            //bL1.bounceFactor = 2;
            this.BoundingContainer.AddBoundingBox(bC1);
            this.BoundingContainer.AddBoundingBox(bL1);
            this.BoundingContainer.AddBoundingBox(bL2);
            this.BoundingContainer.AddBoundingBox(bC2);
            this.BoundingContainer.AddBoundingBox(bL3);
            this.BoundingContainer.AddBoundingBox(bL4);
             * */
        }
        public void TakeOverBoundingContainerWithLineSmallDiagonal()
        {
            //preconfig
            int cols = 10;
            int rows = 10;
            int width = 100;
            int height = 100;

            int expectedFieldHeight = height / rows;
            int expectedFieldWidth = width / cols;

            Vector position1 = new Vector(0, 0);
            Vector target1 = new Vector(50, 50);

            //creation
            BoundingRaster br = new BoundingRaster(cols, rows, width, height);

            Line parent1 = new Line();
            BoundingLine bL1 = new BoundingLine(position1, target1);
            BoundingContainer bCont1 = new BoundingContainer(parent1);
            bCont1.AddBoundingBox(bL1);
            parent1.Location = (new Vector(0, 0));

            //operation
            br.TakeOverBoundingContainer(bCont1);

            //assertion
            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    if ((x == y) && x >= 0 && x <= 5)
                    {
                        bool found = false;
                        foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences())
                        {
                            Assert.AreEqual(bL1, b);
                            found = true;
                        }
                        if (!found)
                        {
                            Assert.Fail();
                        }
                    }
                    else
                    {
                        foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences())
                        {
                            if (bL1.Equals(b))
                            {
                                Assert.Fail();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        protected override void Init()
        {
            base.Init();

            double x0 = p1.X;
            double x1 = p2.X;
            double y0 = p1.Y;
            double y1 = p2.Y;

            size = new Size((int)Math.Abs(x1 - x0), (int)Math.Abs(y1 - y0));

            //set up of bounding box
            BoundingLine bL = new BoundingLine(new Vector(x0, y0), new Vector(x1, y1));
            this.BoundingContainer.AddBoundingBox(bL);
        }
        public void TestCreation()
        {
            //Preconfig
            Vector position1 = new Vector(0f,50f);
            Vector target1 = new Vector(50f, 50f);

            //Creation
            BoundingLine bL = new BoundingLine(position1, target1);

            //Operation

            //Assertion
            Assert.IsNotNull(bL);
            Assert.AreEqual(bL.Position, position1);
            Assert.AreEqual(bL.target, target1);
        }
Exemplo n.º 8
0
        protected override void Init()
        {
            //set up of bounding box
            BoundingLine bL1 = new BoundingLine(new Vector(0, 200), new Vector(100, 0));
            BoundingLine bL2 = new BoundingLine(new Vector(100, 0), new Vector(200, 200));
            BoundingLine bL3 = new BoundingLine(new Vector(200, 200), new Vector(0, 200));

            this.BoundingContainer.AddBoundingBox(bL1);
            this.BoundingContainer.AddBoundingBox(bL2);
            this.BoundingContainer.AddBoundingBox(bL3);

            bL1.AssignToContainer(this.BoundingContainer);
            bL2.AssignToContainer(this.BoundingContainer);
            bL3.AssignToContainer(this.BoundingContainer);
            turnaround();
        }
Exemplo n.º 9
0
        protected override void Init()
        {
            base.Init();
            RotationRange = -RotationRange;

            Vector offset = new Vector(-10, -10);
            int r1 = 70;
            int r2 = 16;
            Vector mitteKreis = new Vector(-(140 - 400) + 400, 295) + offset;
            Vector obenKreisLinie = new Vector(-(180 - 400) + 400, 241) + offset;
            Vector p3 = new Vector(-(678 - 400) + 400, 505) + offset;
            Vector p4 = new Vector(-(700 - 400) + 400, 534) + offset;
            Vector circle2 = new Vector(-(692 - 400) + 400, 546) + offset;
            Vector p5 = new Vector(-(692 - 400) + 400, 561) + offset;
            Vector p6 = new Vector(-(645 - 400) + 400, 566) + offset;
            Vector p7 = new Vector(-(116 - 400) + 400, 355) + offset;
            Vector peak = new Vector(-(707 - 400) + 400, 553) + offset;

            r1 = (int)(r1 / factor);
            r2 = (int)(r2 / factor);
            mitteKreis /= factor;
            obenKreisLinie /= factor;
            p3 /= factor;
            p4 /= factor;
            circle2 /= factor;
            p5 /= factor;
            p6 /= factor;
            p7 /= factor;
            peak /= factor;

            BoundingCircle bC1 = new BoundingCircle(r1, mitteKreis - new Vector(r1, r1));
            BoundingLine bL1 = new BoundingLine(obenKreisLinie, peak);
            BoundingLine bL2 = new BoundingLine(p3, p4);
            BoundingCircle bC2 = new BoundingCircle(r2, circle2 - new Vector(r2, r2));
            BoundingLine bL3 = new BoundingLine(p5, p6);
            BoundingLine bL4 = new BoundingLine(peak, p7);

            //bL1.bounceFactor = 2;
            this.BoundingContainer.AddBoundingBox(bC1);
            this.BoundingContainer.AddBoundingBox(bL1);
            //this.BoundingContainer.AddBoundingBox(bL2);
               // this.BoundingContainer.AddBoundingBox(bC2);
            //this.BoundingContainer.AddBoundingBox(bL3);
            this.BoundingContainer.AddBoundingBox(bL4);
        }
        public void TestIntersectIntersectleft1pxOverlap()
        {
            //Preconfig
            Vector target1 = new Vector(40, 50);
            Vector position1 = new Vector(0f, 50f);

            int radius2 = 20;
            Vector center2 = new Vector(-39, 30);
            Vector ballSpeed = new Vector(0, 5);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Line parent = new Line();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);
            BoundingLine bL1 = new BoundingLine(position1, target1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);
            bCont.AddBoundingBox(bL1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;
            ball.Location = (new Vector(0, 0));
            ball.Width = 20;
            ball.Height = 20;
            parent.Location = (new Vector(0, 0));
            parent.Width = 40;
            parent.Height = 0;

            //Operation
            isIntersec = bL1.Intersect(bC2, out hitPoint);

            //Assertion
            Assert.IsTrue(isIntersec);
            Assert.AreEqual(0, hitPoint.X, 2);
            Assert.AreEqual(50f, hitPoint.Y, 2);
        }
Exemplo n.º 11
0
        protected override void Init()
        {
            Vector p1 = new Vector(127, 60);
            Vector p2 = new Vector(364, 335);
            Vector p3 = new Vector(316, 366);
            Vector p4 = new Vector(87, 239);

            p1 /= 4;
            p2 /= 4;
            p3 /= 4;
            p4 /= 4;

            BoundingLine bL1 = new BoundingLine(p1, p2);
            BoundingLine bL2 = new BoundingLine(p2, p3);
            BoundingLine bL3 = new BoundingLine(p3, p4);
            BoundingLine bL4 = new BoundingLine(p4, p1);

            bL1.BounceFactor = 2;
            this.BoundingContainer.AddBoundingBox(bL1);
            this.BoundingContainer.AddBoundingBox(bL2);
            this.BoundingContainer.AddBoundingBox(bL3);
            this.BoundingContainer.AddBoundingBox(bL4);
        }
Exemplo n.º 12
0
        protected override void Init()
        {
            //Todo: Correct
            Vector p1 = new Vector(311, 59);
            Vector p2 = new Vector(353, 239);
            Vector p3 = new Vector(123, 367);
            Vector p4 = new Vector(72, 337);

            p1 /= 4;
            p2 /= 4;
            p3 /= 4;
            p4 /= 4;

            BoundingLine bL1 = new BoundingLine(p1, p2);
            BoundingLine bL2 = new BoundingLine(p2, p3);
            BoundingLine bL3 = new BoundingLine(p3, p4);
            BoundingLine bL4 = new BoundingLine(p4, p1);

            bL1.BounceFactor = 2;
            this.BoundingContainer.AddBoundingBox(bL1);
            this.BoundingContainer.AddBoundingBox(bL2);
            this.BoundingContainer.AddBoundingBox(bL3);
            this.BoundingContainer.AddBoundingBox(bL4);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Submethod of intersect => checks for an intersection of this bounding box and a Bounding line
 /// </summary>
 /// <param name="bL">Bounding line which might intersect this bounding box</param>
 /// <param name="hitPoint">Point where this bounding box intersects with bL</param>
 /// <returns>true if intersection</returns>
 public abstract bool LineIntersect(BoundingLine bL, out Vector hitPoint);
Exemplo n.º 14
0
        protected override void Init()
        {
            Vector p1 = new Vector(21,1128);
            Vector p2 = new Vector(16, 233);
            Vector p3 = new Vector(35, 158);
            Vector p4 = new Vector(58, 230);
            Vector p5 = new Vector(68, 1128);

            Vector p21 = new Vector(149, 1128);
            Vector p22 = new Vector(131, 231);
            Vector p23 = new Vector(102, 26);
            Vector p24 = new Vector(121, 12);
            Vector p25 = new Vector(154, 230);
            Vector p26 = new Vector(175, 1128);

            Vector pPs = new Vector(65, this.BaseSize.Height + pencilOffsetY-20);
            Vector pPe = new Vector(152, this.BaseSize.Height + pencilOffsetY-20);

            BoundingLine bL1 = new BoundingLine(p1, p2);
            BoundingLine bL2 = new BoundingLine(p2, p3);
            BoundingLine bL3 = new BoundingLine(p3, p4);
            BoundingLine bL4 = new BoundingLine(p4, p5);
            BoundingLine bL5 = new BoundingLine(p5, p1);

            BoundingLine bL21 = new BoundingLine(p21, p22);
            BoundingLine bL22 = new BoundingLine(p22, p23);
            BoundingLine bL23 = new BoundingLine(p23, p24);
            BoundingLine bL24 = new BoundingLine(p24, p25);
            BoundingLine bL25 = new BoundingLine(p25, p26);
            BoundingLine bL26 = new BoundingLine(p26, p21);

            powerLine = new BoundingLine(pPs, pPe);
            BoundingLine subPowerLine = new BoundingLine(pPs + new Vector(0, pencilPullback), pPe + new Vector(0, pencilPullback));

            bL4.BounceFactor = 0.5f;
            bL1.BounceFactor = 0.5f;
            powerLine.BounceFactor = 0.2f;
            subPowerLine.BounceFactor = 0.2f;

            this.BoundingContainer.AddBoundingBox(bL1);
            this.BoundingContainer.AddBoundingBox(bL2);
            this.BoundingContainer.AddBoundingBox(bL3);
            this.BoundingContainer.AddBoundingBox(bL4);
            this.BoundingContainer.AddBoundingBox(bL5);

            this.BoundingContainer.AddBoundingBox(bL21);
            this.BoundingContainer.AddBoundingBox(bL22);
            this.BoundingContainer.AddBoundingBox(bL23);
            this.BoundingContainer.AddBoundingBox(bL24);
            this.BoundingContainer.AddBoundingBox(bL25);
            this.BoundingContainer.AddBoundingBox(bL26);

            this.BoundingContainer.AddBoundingBox(powerLine);
            // Makes sure that the ball doesn't fall through
            BoundingContainer.AddBoundingBox(subPowerLine);

            Scale = 1 / 2f;
        }
Exemplo n.º 15
0
 public override IBoundingBox Clone()
 {
     BoundingLine bL =  new BoundingLine(new Vector(this.Position.X, this.Position.Y), new Vector(this.target.X, this.target.Y));
     //do not forget to assinge BoundingContainer after clone
     return bL;
 }
        public void TakeOverBoundingContainerWithLineTotalOutside()
        {
            //preconfig
            int cols = 10;
            int rows = 10;
            int width = 100;
            int height = 100;

            int expectedFieldHeight = height / rows;
            int expectedFieldWidth = width / cols;

            Vector position1 = new Vector(-20, -20);
            Vector target1 = new Vector(-50, -50);

            //creation
            BoundingRaster br = new BoundingRaster(cols, rows, width, height);

            Line parent1 = new Line();
            BoundingLine bL1 = new BoundingLine(position1, target1);
            BoundingContainer bCont1 = new BoundingContainer(parent1);
            bCont1.AddBoundingBox(bL1);
            parent1.Location = (new Vector(0, 0));

            //operation
            br.TakeOverBoundingContainer(bCont1);

            //assertion
            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {

                    foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences())
                    {
                        if (bL1.Equals(b))
                        {
                            Assert.Fail();
                        }
                    }

                }
            }
        }
Exemplo n.º 17
0
        //TODO: UNTESTED
        public override bool LineIntersect(BoundingLine bL, out Vector hitPoint)
        {
            hitPoint = new Vector(0, 0);

            Vector thisWorldTras = this.BoundingContainer.ParentElement.Location;
            Vector bLWorldTrans = bL.BoundingContainer.ParentElement.Location;

            Vector bLWorldPos = bL.Position + bLWorldTrans;
            Vector bLWorldTar = bL.target + bLWorldTrans;
            Vector thisWorldTar = this.target + thisWorldTras;
            Vector thisWorldPos = this.Position + thisWorldTras;

            double Ax = thisWorldPos.X;
            double Ay = thisWorldPos.Y;

            double Bx = thisWorldTar.X;
            double By = thisWorldTar.Y;

            double Cx = bLWorldPos.X;
            double Cy = bLWorldPos.Y;

            double Dx = bLWorldTar.X;
            double Dy = bLWorldTar.Y;

            if (((Cx - Dx) * By + (Cy - Dy) * Ax - (Cx - Dx) * Ay - (Cy - Dy) * Bx) == 0)
            {
                int i = 0;
            }

            double d = (-(By * (Ax - Cx) - Cy * Ax - Ay * (Bx - Cx) + Cy * Bx) / ((Cx - Dx) * By + (Cy - Dy) * Ax - (Cx - Dx) * Ay - (Cy - Dy) * Bx));

            if (d <= 0 || d >= 1)
            {
                return false;
            }

            double t = (Cx + d * (Dx - Cx) - Ax) / (Bx - Ax);
            if (t <= 0 || t>= 1)
            {
                return false;
            }

            hitPoint = thisWorldPos + t * (bLWorldTar - thisWorldPos);
            return true;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Submethod to TakeOverBoundingContainer - not intended to be called outside of TakeOverBoundingContainer
        /// </summary>
        private void takeOverBoundingLineRightToLeft(Vector unitV, double posX, double posY, ref int x, ref int y, BoundingLine bL, Vector worldTrans)
        {
            if (unitV.X == 0)
            {
                return;     //just y remains => the whole line is on one column
            }

            double deltaLeft = (posX - FieldWidth * x);     //distance from right end of field to the position
            double factorToNextXCross = deltaLeft / -unitV.X;

            while (posX > (bL.target.X + worldTrans.X))
            {
                factorToNextXCross = deltaLeft / -unitV.X;

                //direction left to right
                double nextXCross = posX - deltaLeft;
                double nextXCrossY = posY + factorToNextXCross * unitV.Y;      //because factorToNextXCross time unitvector in x direction = new point

                //float newFieldXIdx = ((int)nextXCross / fieldWidth);
                int newFieldYIdx = (int)((nextXCrossY-1) / FieldHeight);

                if (unitV.Y > 0)        //heading down
                {
                    if (newFieldYIdx > y)
                    {
                        //we entered new y field(s)
                        for (int i = y; i < newFieldYIdx; i++)
                        {
                            if (IsWithinBounds(x, i))
                                this.fields[x, i].addReference(bL);      //this is a field that the line goes through
                        }
                    }
                }
                else
                {
                    //heading up
                    if (newFieldYIdx < y)
                    {
                        //we entered new y field(s)
                        for (int i = y; i > newFieldYIdx; i--)
                        {
                            if (IsWithinBounds(x, i))
                                this.fields[x, i].addReference(bL);      //this is a field that the line goes through
                        }
                    }
                }

                //update field index
                x--;
                y = newFieldYIdx;

                //update position
                posX = nextXCross;
                posY = nextXCrossY;

                //since we are at the border of a field the deltaRight will allways be the full field width
                deltaLeft = FieldWidth;
                if (x >= 0)
                {
                    if (IsWithinBounds(x, newFieldYIdx))
                        this.fields[x, newFieldYIdx].addReference(bL);       //add the next x field (since the line just gets crossed)
                }

            }
        }
Exemplo n.º 19
0
            protected override void Init()
            {
                var totalWidth = (int)this.Width;
                int totalHeight = (int)this.Height;

                Vector p1 = new Vector(316, 1344);
                Vector p2 = new Vector(107, 1207);
                Vector p3 = new Vector(88, 361);
                Vector p4 = new Vector(125, 215);
                Vector p5 = new Vector(184, 127);
                Vector p6 = new Vector(262, 61);
                Vector p7 = new Vector(417, 26);
                Vector p8 = new Vector(601, 29);
                Vector p9 = new Vector(733, 55);
                Vector p10 = new Vector(832, 133);
                Vector p11 = new Vector(876, 199);
                Vector p12 = new Vector(898, 267);
                Vector p13 = new Vector(931, 487);
                Vector p14 = new Vector(952, 1385);

                Vector p15 = new Vector(799, 1233);
                Vector p16 = new Vector(569, 1348);

                BoundingLine bL1 = new BoundingLine(p1, p2);
                BoundingLine bL2 = new BoundingLine(p2, p3);
                BoundingLine bL3 = new BoundingLine(p3, p4);
                BoundingLine bL4 = new BoundingLine(p4, p5);
                BoundingLine bL5 = new BoundingLine(p5, p6);
                BoundingLine bL6 = new BoundingLine(p6, p7);
                BoundingLine bL7 = new BoundingLine(p7, p8);
                BoundingLine bL8 = new BoundingLine(p8, p9);
                BoundingLine bL9 = new BoundingLine(p9, p10);
                BoundingLine bL10 = new BoundingLine(p10, p11);
                BoundingLine bL11 = new BoundingLine(p11, p12);
                BoundingLine bL12 = new BoundingLine(p12, p13);
                BoundingLine bL13 = new BoundingLine(p13, p14);

                BoundingLine bL14 = new BoundingLine(p15, p16);

                this.BoundingContainer.AddBoundingBox(bL1);
                this.BoundingContainer.AddBoundingBox(bL2);
                this.BoundingContainer.AddBoundingBox(bL3);
                this.BoundingContainer.AddBoundingBox(bL4);
                this.BoundingContainer.AddBoundingBox(bL5);
                this.BoundingContainer.AddBoundingBox(bL6);
                this.BoundingContainer.AddBoundingBox(bL7);
                this.BoundingContainer.AddBoundingBox(bL8);
                this.BoundingContainer.AddBoundingBox(bL9);
                this.BoundingContainer.AddBoundingBox(bL10);
                this.BoundingContainer.AddBoundingBox(bL11);
                this.BoundingContainer.AddBoundingBox(bL12);
                this.BoundingContainer.AddBoundingBox(bL13);
                this.BoundingContainer.AddBoundingBox(bL14);

                Scale = 1 / 2f;
            }
Exemplo n.º 20
0
        public override bool LineIntersect(BoundingLine bL, out Vector hitPoint)
        {
            //strategy: connect center of ball with start of line. calc where the normal from center of ball on line hits (pointNormalDirectionPice). If len from center of ball to this point
            //is smaller then radius then it is a hit. Should pointNormalDirectionPice be smaller then start - radius of ball or bigger then end+ radius of ball => ignore

            hitPoint = new Vector(0, 0);

            Vector bLWorldPos = bL.Position + bL.BoundingContainer.ParentElement.Location;
            Vector bLWorldTar = bL.target + bL.BoundingContainer.ParentElement.Location;
            Vector thisWorldPos = this.Position + this.BoundingContainer.ParentElement.Location ;

            Vector centerOfCircle = thisWorldPos;
            Vector directionLine = bLWorldTar - bLWorldPos;
            Vector normalLine = new Vector(-directionLine.Y, directionLine.X);

            double lenDirectionPiece = Vector.Multiply((centerOfCircle - bLWorldPos) , NormalizeVector(directionLine));
               // Console.WriteLine(bL.position+" "+bL.target+" "+lenDirectionPiece);
            if (lenDirectionPiece < -this.radius || lenDirectionPiece >= (directionLine.Length+this.radius))
            {
                return false;
            }

            Vector pointNormalDirectionPice = bLWorldPos + lenDirectionPiece * NormalizeVector(directionLine);
            Vector normalFromDirLineToCenter = centerOfCircle - pointNormalDirectionPice;

            double diff = normalFromDirLineToCenter.Length;

            if (diff < this.radius)
            {
                if (lenDirectionPiece < 0)
                {
                    hitPoint = bLWorldPos;
                    return true;
                }

                if (lenDirectionPiece > (directionLine.Length))
                {
                    hitPoint = bLWorldTar;
                    return true;
                }
                //in this case T lies in the circle
                hitPoint = pointNormalDirectionPice;
                return true;
            }

            return false;
        }
        public void TestIntersectIntersectNone()
        {
            //Preconfig
            Vector target1 = new Vector(20, 50);
            Vector position1 = new Vector(0f, 50f);

            int radius2 = 20;
            Vector center2 = new Vector(10, 0f);
            Vector ballSpeed = new Vector(0, 5);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Line parent = new Line();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);
            BoundingLine bL1 = new BoundingLine(position1, target1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);
            bCont.AddBoundingBox(bL1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;
            parent.Location = new Vector(0, 0);
            parent.Width = 20;
            parent.Height = 0;

            //Operation
            isIntersec = bC2.Intersect(bL1, out hitPoint);

            //Assertion
            Assert.IsFalse(isIntersec);
        }