/SketchEditor/NUnit/BoxCollisionShapeTests.cs
https://bitbucket.org/spanky/valor3d · C# · 209 lines · 148 code · 61 blank · 0 comment · 0 complexity · a73c7fb2fc13eaf965398c0941c97aaf MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Text;
-
- using NUnit.Framework;
- using Editor;
-
- namespace NUnitTests
- {
- [TestFixture]
- public class BoxCollisionShapeTests
- {
- public Mogre.AxisAlignedBox GetUnitCube()
- {
- return new Mogre.AxisAlignedBox(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f);
- }
-
-
- #region Outside Axis Aligned Colliding Tests
-
- [Test]
- public void RayFromOutsideAgainstPositiveXSide()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
- IntersectionResult result = box.Intersect(null, new Mogre.Vector3(1.0f, 0.0f, 0.0f), new Mogre.Vector3(-1.0f, 0.0f, 0.0f), false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
-
- [Test]
- public void RayFromOutsideAgainstPositiveYSide()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
- IntersectionResult result = box.Intersect(null, new Mogre.Vector3(0.0f, 1.0f, 0.0f), new Mogre.Vector3(0.0f, -1.0f, 0.0f), false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
-
- [Test]
- public void RayFromOutsideAgainstPositiveZSide()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
- IntersectionResult result = box.Intersect(null, new Mogre.Vector3(0.0f, 0.0f, 1.0f), new Mogre.Vector3(0.0f, 0.0f, -1.0f), false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
-
-
- [Test]
- public void RayFromOutsideAgainstNegativeXSide()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
- IntersectionResult result = box.Intersect(null, new Mogre.Vector3(-1.0f, 0.0f, 0.0f), new Mogre.Vector3(1.0f, 0.0f, 0.0f), false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
-
- [Test]
- public void RayFromOutsideAgainstNegativeYSide()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
- IntersectionResult result = box.Intersect(null, new Mogre.Vector3(0.0f, -1.0f, 0.0f), new Mogre.Vector3(0.0f, 1.0f, 0.0f), false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
-
- [Test]
- public void RayFromOutsideAgainstNegativeZSide()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
- IntersectionResult result = box.Intersect(null, new Mogre.Vector3(0.0f, 0.0f, -1.0f), new Mogre.Vector3(0.0f, 0.0f, 1.0f), false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- #endregion
-
-
- #region Corner Testing
-
- [Test]
- public void TopLeftFrontCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(1.0f, -1.0f, -1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(-0.5f, 0.5f, 0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- [Test]
- public void BottomLeftFrontCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(1.0f, 1.0f, -1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(-0.5f, -0.5f, 0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- [Test]
- public void TopRightFrontCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(-1.0f, -1.0f, -1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(0.5f, 0.5f, 0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- [Test]
- public void BottomRightFrontCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(-1.0f, -1.0f, -1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(0.5f, 0.5f, 0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
-
-
-
- [Test]
- public void TopLeftBackCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(1.0f, -1.0f, 1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(-0.5f, 0.5f, -0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- [Test]
- public void BottomLeftBackCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(1.0f, 1.0f, 1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(-0.5f, -0.5f, -0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- [Test]
- public void TopRightBackCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(-1.0f, -1.0f, 1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(0.5f, 0.5f, -0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- [Test]
- public void BottomRightBackCorner()
- {
- BoxCollisionShape box = new BoxCollisionShape(new BoxCollisionShape.RetrieveLocalBoundsHandler(GetUnitCube));
-
-
- Mogre.Vector3 rayDirection = new Mogre.Vector3(-1.0f, -1.0f, 1.0f).NormalisedCopy;
- Mogre.Vector3 rayOrigin = new Mogre.Vector3(0.5f, 0.5f, -0.5f) + (-rayDirection * 0.5f);
-
- IntersectionResult result = box.Intersect(null, rayOrigin, rayDirection, false);
- Assert.IsTrue(result.IsValid, "The intersection result was not valid");
- Assert.AreEqual(0.5f, result.Distance, "The intersection location was not at the correct location");
- }
-
- #endregion
- }
- }