public void TestMovingBoxImpactPoint() { AxisAlignedBox3 leftBox = new AxisAlignedBox3( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(10.0f, 10.0f, 10.0f) ); AxisAlignedBox3 rightBox = new AxisAlignedBox3( new Vector3(100.0f, 0.0f, 0.0f), new Vector3(110.0f, 10.0f, 10.0f) ); /* * Assert.AreEqual( * new float[] { 0.0f }, * leftBox.LocateImpact(new Vector3(0.0f, 0.0f, 0.0f), leftBox), * "Contact with clone occured immediately" * ); * * Assert.AreEqual( * new float[] { 0.45f }, * leftBox.LocateImpact(new Vector3(200.0f, 0.0f, 0.0f), rightBox), * "Fast moving contact with right box is determined exactly" * ); * * Assert.AreEqual( * new float[] { 0.45f }, * rightBox.LocateImpact(new Vector3(-200.0f, 0.0f, 0.0f), leftBox), * "Fast moving contact with left box is determined exactly" * ); */ }
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" ); }
public void TestMovingBoxImpactPoint() { AxisAlignedBox3 leftBox = new AxisAlignedBox3( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(10.0f, 10.0f, 10.0f) ); AxisAlignedBox3 rightBox = new AxisAlignedBox3( new Vector3(100.0f, 0.0f, 0.0f), new Vector3(110.0f, 10.0f, 10.0f) ); /* Assert.AreEqual( new float[] { 0.0f }, leftBox.LocateImpact(new Vector3(0.0f, 0.0f, 0.0f), leftBox), "Contact with clone occured immediately" ); Assert.AreEqual( new float[] { 0.45f }, leftBox.LocateImpact(new Vector3(200.0f, 0.0f, 0.0f), rightBox), "Fast moving contact with right box is determined exactly" ); Assert.AreEqual( new float[] { 0.45f }, rightBox.LocateImpact(new Vector3(-200.0f, 0.0f, 0.0f), leftBox), "Fast moving contact with left box is determined exactly" ); */ }
public void TestBoundingBox() { AxisAlignedBox3 box = new AxisAlignedBox3( new Vector3(10.0f, 10.0f, 10.0f), new Vector3(20.0f, 20.0f, 20.0f) ); AxisAlignedBox3 boundingBox = box.BoundingBox; Assert.AreEqual( box, boundingBox, "Bounding box for axis aligned box is identical to the box itself" ); }
public void TestMassProperties() { AxisAlignedBox3 testBox = new AxisAlignedBox3(new Vector3(100, 100, 100), new Vector3(110, 120, 130)); Assert.AreEqual( new Vector3(105, 110, 115), testBox.CenterOfMass, "Center of mass is correctly positioned" ); Assert.AreEqual(6000, testBox.Mass, "Mass of box is exactly determined"); Assert.AreEqual(2200, testBox.SurfaceArea, "Surface area of box is exactly determined"); }
public void TestMassProperties() { AxisAlignedBox3 testBox = new AxisAlignedBox3(new Vector3(100, 100, 100), new Vector3(110, 120, 130)); Assert.AreEqual( new Vector3(105, 110, 115), testBox.CenterOfMass, "Center of mass is correctly positioned" ); Assert.AreEqual(6000, testBox.Mass, "Mass of box is exactly determined"); Assert.AreEqual(2200, testBox.SurfaceArea, "Surface area of box is exactly determined"); }
public void TestBoundingBox() { AxisAlignedBox3 box = new AxisAlignedBox3( new Vector3(10.0f, 10.0f, 10.0f), new Vector3(20.0f, 20.0f, 20.0f) ); AxisAlignedBox3 boundingBox = box.BoundingBox; Assert.AreEqual( box, boundingBox, "Bounding box for axis aligned box is identical to the box itself" ); }
/// <summary>Determines if an object is identical to the axis aligned box</summary> /// <param name="obj">Object to compare to</param> /// <returns>True if the object is identical to the axis aligned box</returns> public override bool Equals(object obj) { AxisAlignedBox3 box = obj as AxisAlignedBox3; if (!ReferenceEquals(box, null)) { return(this == box); } else { return(false); } }
public void TestAlmostEqualWithAxisAlignedBoxes() { Vector3 exactVector = new Vector3(exactFloat, exactFloat, exactFloat); Vector3 minusOneVector = new Vector3(minusOneFloat, minusOneFloat, minusOneFloat); Vector3 plusOneVector = new Vector3(plusOneFloat, plusOneFloat, plusOneFloat); Volumes.AxisAlignedBox3 oneOffAabb = new Volumes.AxisAlignedBox3( minusOneVector, plusOneVector ); Volumes.AxisAlignedBox3 exactAabb = new Volumes.AxisAlignedBox3( exactVector, exactVector ); GeoAssertHelper.AreAlmostEqual(exactAabb, oneOffAabb, 1); }
public void TestBoundingSphere() { AxisAlignedBox3 box = new AxisAlignedBox3( new Vector3(10.0f, 10.0f, 10.0f), new Vector3(20.0f, 20.0f, 20.0f) ); Sphere3 boundingSphere = box.BoundingSphere; Assert.AreEqual( new Vector3(15.0f, 15.0f, 15.0f), boundingSphere.Center, "Center of bounding sphere correctly determined" ); Assert.AreEqual( (float)Math.Sqrt(75.0f), boundingSphere.Radius, "Radius of bounding sphere exactly encloses the box" ); }
public void TestThrowOnAlmostEqualWithTooLargeAxisAlignedBox() { Vector3 exactVector = new Vector3(exactFloat, exactFloat, exactFloat); Vector3 minusTwoVector = new Vector3(minusTwoFloat, minusTwoFloat, minusTwoFloat); Vector3 plusTwoVector = new Vector3(plusTwoFloat, plusTwoFloat, plusTwoFloat); Volumes.AxisAlignedBox3 twoOffAabb = new Volumes.AxisAlignedBox3( minusTwoVector, plusTwoVector ); Volumes.AxisAlignedBox3 exactAabb = new Volumes.AxisAlignedBox3( exactVector, exactVector ); Assert.Throws <AssertionException>( delegate() { GeoAssertHelper.AreAlmostEqual(exactAabb, twoOffAabb, 1); } ); }
public void TestBoundingBox() { Sphere3 sphere = new Sphere3( new Vector3(15.0f, 15.0f, 15.0f), 5.0f ); AxisAlignedBox3 boundingBox = sphere.BoundingBox; Assert.AreEqual( new Vector3(10.0f, 10.0f, 10.0f), boundingBox.Min, "Minimum corner of bounding box correctly determined" ); Assert.AreEqual( new Vector3(20.0f, 20.0f, 20.0f), boundingBox.Max, "Maximum corner of bounding box correctly determined" ); }
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" ); }
/// <summary>Ensures that two axis aligned boxes are equal</summary> /// <param name="expected">Expected box</param> /// <param name="actual">Actual box</param> /// <param name="deltaUlps">Allowed deviation in representable floating point values</param> /// <param name="message">Message to display when the boxes are not equal</param> public static void AreAlmostEqual( Volumes.AxisAlignedBox3 expected, Volumes.AxisAlignedBox3 actual, int deltaUlps, string message ) { bool almostEqual = FloatHelper.AreAlmostEqual(expected.Min.X, actual.Min.X, deltaUlps) && FloatHelper.AreAlmostEqual(expected.Min.Y, actual.Min.Y, deltaUlps) && FloatHelper.AreAlmostEqual(expected.Min.Z, actual.Min.Z, deltaUlps) && FloatHelper.AreAlmostEqual(expected.Max.X, actual.Max.X, deltaUlps) && FloatHelper.AreAlmostEqual(expected.Max.Y, actual.Max.Y, deltaUlps) && FloatHelper.AreAlmostEqual(expected.Max.Z, actual.Max.Z, deltaUlps); if (almostEqual) { return; } // Now we already know that the two boxes are not equal even within the allowed // deviation (delta argument). In order to force NUnit to output a good error // message, we now let NUnit do the job again fully well knowing that it will // fail. This allows for deltas and good NUnit integration at the same time. Assert.AreEqual(expected, actual, message); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return Collisions.AabbObbCollider.CheckContact( box.Extents, this.Transform, this.Extents ); }
public void TestThrowOnAlmostEqualWithTooLargeAxisAlignedBox() { Vector3 exactVector = new Vector3(exactFloat, exactFloat, exactFloat); Vector3 minusTwoVector = new Vector3(minusTwoFloat, minusTwoFloat, minusTwoFloat); Vector3 plusTwoVector = new Vector3(plusTwoFloat, plusTwoFloat, plusTwoFloat); Volumes.AxisAlignedBox3 twoOffAabb = new Volumes.AxisAlignedBox3( minusTwoVector, plusTwoVector ); Volumes.AxisAlignedBox3 exactAabb = new Volumes.AxisAlignedBox3( exactVector, exactVector ); Assert.Throws<AssertionException>( delegate() { GeoAssertHelper.AreAlmostEqual(exactAabb, twoOffAabb, 1); } ); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return Collisions.AabbSphereCollider.CheckContact( box.Min, box.Max, this.Center, this.Radius ); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return Collisions.AabbMeshCollider.CheckContact( box.Min, box.Max, this ); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return(Collisions.AabbObbCollider.CheckContact( box.Extents, this.Transform, this.Extents )); }
/// <summary>Ensures that two axis aligned boxes are equal</summary> /// <param name="expected">Expected box</param> /// <param name="actual">Actual box</param> /// <param name="deltaUlps">Allowed deviation in representable floating point values</param> public static void AreAlmostEqual( Volumes.AxisAlignedBox3 expected, Volumes.AxisAlignedBox3 actual, int deltaUlps ) { AreAlmostEqual(expected, actual, deltaUlps, null); }
/// <summary>Determines where the range clips an axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>The times at which the range enters or leaves the volume</returns> /// <remarks> /// Taken from the article "Simple Intersection Tests for Games" on /// Gamasutra by Gomez et al. /// </remarks> public bool Intersects(AxisAlignedBox3 box) { Vector3 lineDirection = (End - Start); float lineHalfLength = lineDirection.Length(); lineDirection /= lineHalfLength; lineHalfLength /= 2.0f; // ALGORITHM: Use the separating axis theorem to see if the line segment and // the box overlap. A line segment is a degenerate OBB. Vector3 distance = box.Center - (Start + End) / 2.0f; float r; // Do any of the principal axes form a separating axis? Vector3 scaledDimensions = new Vector3( box.Dimensions.X * lineHalfLength * Math.Abs(lineDirection.X), box.Dimensions.Y * lineHalfLength * Math.Abs(lineDirection.Y), box.Dimensions.Z * lineHalfLength * Math.Abs(lineDirection.Z) ); if(Math.Abs(distance.X) > scaledDimensions.X) return false; if(Math.Abs(distance.Y) > scaledDimensions.Y) return false; if(Math.Abs(distance.Z) > scaledDimensions.Z) return false; // NOTE: Since the separating axis is perpendicular to the line in these // last four cases, the line does not contribute to the projection. //l.cross(x-axis)? r = box.Dimensions.Y * Math.Abs(lineDirection.Z) + box.Dimensions.Z * Math.Abs(lineDirection.Y); if(Math.Abs(distance.Y * lineDirection.Z - distance.Z * lineDirection.Y) > r) return false; //l.cross(y-axis)? r = box.Dimensions.X * Math.Abs(lineDirection.Z) + box.Dimensions.Z * Math.Abs(lineDirection.X); if(Math.Abs(distance.Z * lineDirection.X - distance.X * lineDirection.Z) > r) return false; //l.cross(z-axis)? r = box.Dimensions.X * Math.Abs(lineDirection.Y) + box.Dimensions.Y * Math.Abs(lineDirection.X); if(Math.Abs(distance.X * lineDirection.Y - distance.Y * lineDirection.X) > r) return false; return true; }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { throw new NotImplementedException("Not implemented yet"); }
public AxisAlignedBox3(AxisAlignedBox3 other) : this(other.Min, other.Max) { }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { throw new NotImplementedException("Not implemented yet"); }
public void TestAlmostEqualWithAxisAlignedBoxes() { Vector3 exactVector = new Vector3(exactFloat, exactFloat, exactFloat); Vector3 minusOneVector = new Vector3(minusOneFloat, minusOneFloat, minusOneFloat); Vector3 plusOneVector = new Vector3(plusOneFloat, plusOneFloat, plusOneFloat); Volumes.AxisAlignedBox3 oneOffAabb = new Volumes.AxisAlignedBox3( minusOneVector, plusOneVector ); Volumes.AxisAlignedBox3 exactAabb = new Volumes.AxisAlignedBox3( exactVector, exactVector ); GeoAssertHelper.AreAlmostEqual(exactAabb, oneOffAabb, 1); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return(Collisions.AabbSphereCollider.CheckContact( box.Min, box.Max, this.Center, this.Radius )); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return(Collisions.AabbMeshCollider.CheckContact( box.Min, box.Max, this )); }
/// <summary>Visit an axis aligned box</summary> /// <param name="box">Box to visit</param> public abstract void Visit(AxisAlignedBox3 box);
public AxisAlignedBox3(AxisAlignedBox3 other) : this(other.Min, other.Max) { }
/// <summary>Determines where the range clips an axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>The times at which the range enters or leaves the volume</returns> public LineContacts FindContacts(AxisAlignedBox3 box) { return Collisions.Ray3Aabb3Collider.FindContacts( Origin - box.Center, Direction, box.Extents ); }
public void TestBoundingSphere() { AxisAlignedBox3 box = new AxisAlignedBox3( new Vector3(10.0f, 10.0f, 10.0f), new Vector3(20.0f, 20.0f, 20.0f) ); Sphere3 boundingSphere = box.BoundingSphere; Assert.AreEqual( new Vector3(15.0f, 15.0f, 15.0f), boundingSphere.Center, "Center of bounding sphere correctly determined" ); Assert.AreEqual( (float)Math.Sqrt(75.0f), boundingSphere.Radius, "Radius of bounding sphere exactly encloses the box" ); }
/// <summary>Determines if the volume clips the axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>True if the objects overlap</returns> public bool Intersects(AxisAlignedBox3 box) { return Collisions.AabbAabbCollider.CheckContact( this.Min, this.Max, box.Min, box.Max ); }
/// <summary>Determines where the range clips an axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>The times at which the range enters or leaves the volume</returns> public LineContacts FindContacts(AxisAlignedBox3 box) { throw new NotImplementedException(); /* return filterContacts( Collisions.Line3Aabb3Collider.FindContacts( this.Start - box.Center, this.End - this.Start, box.Dimensions / 2.0f ) ); */ }
/// <summary>Visit an axis aligned box</summary> /// <param name="box">Box to visit</param> public abstract void Visit(AxisAlignedBox3 box);
/// <summary>Determines where the range clips an axis aligned box</summary> /// <param name="box">Box that will be checked for intersection</param> /// <returns>The times at which the range enters or leaves the volume</returns> public LineContacts FindContacts(AxisAlignedBox3 box) { return Collisions.Line3Aabb3Collider.FindContacts( Offset - box.Center, Direction, box.Dimensions / 2.0f ); }