예제 #1
0
        public void TestBoundingBox()
        {
            Volumes.Box3 box = new Volumes.Box3(
                MatrixHelper.Create(
                    new Vector3(15.0f, 15.0f, 15.0f),
                    Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f)),
                    Vector3.Normalize(new Vector3(1.0f, 1.0f, -1.0f)),
                    Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f))
                    ),
                new Vector3(5.0f, 5.0f, 5.0f)
                );

            float growth = (float)Math.Sqrt(75.0f);

            AxisAlignedBox3 expectedBoundingBox = new AxisAlignedBox3(
                new Vector3(15.0f - growth, 15.0f - growth, 15.0f - growth),
                new Vector3(15.0f + growth, 15.0f + growth, 15.0f + growth)
                );

            GeoAssertHelper.AreAlmostEqual(
                expectedBoundingBox, box.BoundingBox,
                Specifications.MaximumDeviation,
                "Bounding box for oriented box is correctly determined"
                );
        }
예제 #2
0
    public void TestBoundingBox() {
      Volumes.Box3 box = new Volumes.Box3(
        MatrixHelper.Create(
          new Vector3(15.0f, 15.0f, 15.0f), 
          Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f)),
          Vector3.Normalize(new Vector3(1.0f, 1.0f, -1.0f)),
          Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f))
        ),
        new Vector3(5.0f, 5.0f, 5.0f)
      );

      float growth = (float)Math.Sqrt(75.0f);

      AxisAlignedBox3 expectedBoundingBox = new AxisAlignedBox3(
        new Vector3(15.0f - growth, 15.0f - growth, 15.0f - growth),
        new Vector3(15.0f + growth, 15.0f + growth, 15.0f + growth)
      );
      GeoAssertHelper.AreAlmostEqual(
        expectedBoundingBox, box.BoundingBox,
        Specifications.MaximumDeviation,
        "Bounding box for oriented box is correctly determined"
      );
    }
예제 #3
0
        public void TestFindContactsOnOrientedBox()
        {
            Volumes.Box3 box = new Volumes.Box3(
                MatrixHelper.Create(
                    new Vector3(15.0f, 15.0f, 15.0f),
                    Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f)),
                    Vector3.Normalize(new Vector3(1.0f, 1.0f, -1.0f)),
                    Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f))
                    ),
                new Vector3(5.0f, 5.0f, 5.0f)
                );

            float boxRadius = (float)Math.Sqrt(5 * 5 + 5 * 5 + 5 * 5);
            float outRadius = boxRadius + Specifications.HullAccuracy;

            float[] contacts =
                new Line3(new Vector3(0.0f, 15.0f, 15.0f), Vector3.Right).FindContacts(box);

            Assert.AreEqual(
                15.0f - boxRadius, contacts[0], Specifications.MaximumDeviation,
                "Contact locations on box for X sweep found"
                );
            Assert.AreEqual(
                15.0f + boxRadius, contacts[1], Specifications.MaximumDeviation,
                "Contact locations on box for X sweep found"
                );

            Assert.IsNull(
                new Line3(new Vector3(0.0f, 15.0f - outRadius, 15.0f), Vector3.Right).FindContacts(box),
                "Close miss of box on Y axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(0.0f, 15.0f + outRadius, 15.0f), Vector3.Right).FindContacts(box),
                "Close miss of box on Y axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(0.0f, 15.0f, 15.0f - outRadius), Vector3.Right).FindContacts(box),
                "Close miss of box on Z axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(0.0f, 15.0f, 15.0f + outRadius), Vector3.Right).FindContacts(box),
                "Close miss of box on Z axis properly handled"
                );

            contacts =
                new Line3(new Vector3(15.0f, 0.0f, 15.0f), Vector3.Up).FindContacts(box);

            Assert.AreEqual(
                15.0f - boxRadius, contacts[0], Specifications.MaximumDeviation,
                "Contact locations on box for Y sweep found"
                );
            Assert.AreEqual(
                15.0f + boxRadius, contacts[1], Specifications.MaximumDeviation,
                "Contact locations on box for Y sweep found"
                );

            Assert.IsNull(
                new Line3(new Vector3(15.0f - outRadius, 0.0f, 15.0f), Vector3.Up).FindContacts(box),
                "Close miss of box on X axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(15.0f + outRadius, 0.0f, 15.0f), Vector3.Up).FindContacts(box),
                "Close miss of box on X axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(15.0f, 0.0f, 15.0f - outRadius), Vector3.Up).FindContacts(box),
                "Close miss of box on Z axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(15.0f, 0.0f, 15.0f + outRadius), Vector3.Up).FindContacts(box),
                "Close miss of box on Z axis properly handled"
                );

            contacts =
                new Line3(new Vector3(15.0f, 15.0f, 0.0f), Vector3.Backward).FindContacts(box);

            Assert.AreEqual(
                15.0f - boxRadius, contacts[0], Specifications.MaximumDeviation,
                "Contact locations on box for Z sweep found"
                );
            Assert.AreEqual(
                15.0f + boxRadius, contacts[1], Specifications.MaximumDeviation,
                "Contact locations on box for Z sweep found"
                );

            Assert.IsNull(
                new Line3(new Vector3(15.0f - outRadius, 15.0f, 0.0f), Vector3.Backward).FindContacts(box),
                "Close miss of box on X axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(15.0f + outRadius, 15.0f, 0.0f), Vector3.Backward).FindContacts(box),
                "Close miss of box on X axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(15.0f, 15.0f - outRadius, 0.0f), Vector3.Backward).FindContacts(box),
                "Close miss of box on Y axis properly handled"
                );
            Assert.IsNull(
                new Line3(new Vector3(15.0f, 15.0f + outRadius, 0.0f), Vector3.Backward).FindContacts(box),
                "Close miss of box on Y axis properly handled"
                );
        }
예제 #4
0
    public void TestFindContactsOnOrientedBox() {
      Volumes.Box3 box = new Volumes.Box3(
        MatrixHelper.Create(
          new Vector3(15.0f, 15.0f, 15.0f),
          Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f)),
          Vector3.Normalize(new Vector3(1.0f, 1.0f, -1.0f)),
          Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f))
        ),
        new Vector3(5.0f, 5.0f, 5.0f)
      );

      float boxRadius = (float)Math.Sqrt(5 * 5 + 5 * 5 + 5 * 5);
      float outRadius = boxRadius + Specifications.MaximumDeviation;

      float[] contacts = new Segment3(
        new Vector3(0.0f, 15.0f, 15.0f),
        new Vector3(30.0f, 15.0f, 15.0f)
      ).FindContacts(box);

      Assert.AreEqual(
        (15.0f - boxRadius) / 30.0f, contacts[0], Specifications.MaximumDeviation,
        "Contact locations on box for X sweep found"
      );
      Assert.AreEqual(
        (15.0f + boxRadius) / 30.0f, contacts[1], Specifications.MaximumDeviation,
        "Contact locations on box for X sweep found"
      );

      Assert.IsNull(
        new Segment3(
          new Vector3(0.0f, 15.0f, 15.0f),
          new Vector3(15.0f - outRadius, 15.0f, 15.0f)
        ).FindContacts(box),
        "Close miss of box on X axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f + outRadius, 15.0f, 15.0f),
          new Vector3(30.0f, 15.0f, 15.0f)
        ).FindContacts(box),
        "Close miss of box on X axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(0.0f, 15.0f - outRadius, 15.0f),
          new Vector3(30.0f, 15.0f - outRadius, 15.0f)
        ).FindContacts(box),
        "Close miss of box on Y axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(0.0f, 15.0f + outRadius, 15.0f),
          new Vector3(30.0f, 15.0f + outRadius, 15.0f)
        ).FindContacts(box),
        "Close miss of box on Y axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(0.0f, 15.0f, 15.0f - outRadius),
          new Vector3(30.0f, 15.0f, 15.0f - outRadius)
        ).FindContacts(box),
        "Close miss of box on Z axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(0.0f, 15.0f, 15.0f + outRadius),
          new Vector3(30.0f, 15.0f, 15.0f + outRadius)
        ).FindContacts(box),
        "Close miss of box on Z axis properly handled"
      );

      contacts = new Segment3(
        new Vector3(15.0f, 0.0f, 15.0f),
        new Vector3(15.0f, 30.0f, 15.0f)
      ).FindContacts(box);

      Assert.AreEqual(
        (15.0f - boxRadius) / 30.0f, contacts[0], Specifications.MaximumDeviation,
        "Contact locations on box for Y sweep found"
      );
      Assert.AreEqual(
        (15.0f + boxRadius) / 30.0f, contacts[1], Specifications.MaximumDeviation,
        "Contact locations on box for Y sweep found"
      );

      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 0.0f, 15.0f),
          new Vector3(15.0f, 15.0f - outRadius, 15.0f)
        ).FindContacts(box),
        "Close miss of box on Y axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 15.0f + outRadius, 15.0f),
          new Vector3(15.0f, 30.0f, 15.0f)
        ).FindContacts(box),
        "Close miss of box on Y axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f - outRadius, 0.0f, 15.0f),
          new Vector3(15.0f - outRadius, 30.0f, 15.0f)
        ).FindContacts(box),
        "Close miss of box on X axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f + outRadius, 0.0f, 15.0f),
          new Vector3(15.0f + outRadius, 30.0f, 15.0f)
        ).FindContacts(box),
        "Close miss of box on X axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 0.0f, 15.0f - outRadius),
          new Vector3(15.0f, 30.0f, 15.0f - outRadius)
        ).FindContacts(box),
        "Close miss of box on Z axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 0.0f, 15.0f + outRadius),
          new Vector3(15.0f, 30.0f, 15.0f + outRadius)
        ).FindContacts(box),
        "Close miss of box on Z axis properly handled"
      );

      contacts = new Segment3(
        new Vector3(15.0f, 15.0f, 0.0f),
        new Vector3(15.0f, 15.0f, 30.0f)
      ).FindContacts(box);

      Assert.AreEqual(
        (15.0f - boxRadius) / 30.0, contacts[0], Specifications.MaximumDeviation,
        "Contact locations on boxf for Z sweep found"
      );
      Assert.AreEqual(
        (15.0f + boxRadius) / 30.0f, contacts[1], Specifications.MaximumDeviation,
        "Contact locations on box for Z sweep found"
      );

      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 15.0f, 0.0f),
          new Vector3(15.0f, 15.0f, 15.0f - outRadius)
        ).FindContacts(box),
        "Close miss of box on Z axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 15.0f, 15.0f + outRadius),
          new Vector3(15.0f, 15.0f, 30.0f)
        ).FindContacts(box),
        "Close miss of box on Z axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f - outRadius, 15.0f, 0.0f),
          new Vector3(15.0f - outRadius, 15.0f, 30.0f)
        ).FindContacts(box),
        "Close miss of box on X axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f + outRadius, 15.0f, 0.0f),
          new Vector3(15.0f + outRadius, 15.0f, 30.0f)
        ).FindContacts(box),
        "Close miss of box on X axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 15.0f - outRadius, 0.0f),
          new Vector3(15.0f, 15.0f - outRadius, 30.0f)
        ).FindContacts(box),
        "Close miss of box on Y axis properly handled"
      );
      Assert.IsNull(
        new Segment3(
          new Vector3(15.0f, 15.0f + outRadius, 0.0f),
          new Vector3(15.0f, 15.0f + outRadius, 30.0f)
        ).FindContacts(box),
        "Close miss of box on Y axis properly handled"
      );
    }