Implemented BoundingBox, BoundingSphere and parts of BoundingFrustum. Still some small issues to fix.

This commit is contained in:
SND\xToast_cp 2011-11-05 19:31:10 +00:00
parent e2966f5d1a
commit 85f23ea06d
7 changed files with 896 additions and 204 deletions

View File

@ -98,5 +98,10 @@ namespace ANX.Framework.TestCenter
{ {
get { return r.Next(1000) * RandomBitPlus; } get { return r.Next(1000) * RandomBitPlus; }
} }
public static float RandomValueMinMax(float min, float max)
{
return (float)r.Next((int)min, (int)max) * (float)r.NextDouble();
}
} }
} }

View File

@ -67,52 +67,52 @@ namespace ANX.Framework.TestCenter.Strukturen
#region Helper #region Helper
static object[] sixfloats = static object[] sixfloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
}; };
static object[] ninefloats = static object[] ninefloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
}; };
static object[] tenfloats = static object[] tenfloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
}; };
static object[] twelvefloats = static object[] twelvefloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
}; };
static object[] twentytwofloats = static object[] twentytwofloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f), DataFactory.RandomValueMinMax(0f, 100f) },
}; };
#endregion #endregion
@ -154,7 +154,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox1.Contains(xnaBox2); Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox1.Contains(xnaBox2);
ANX.Framework.ContainmentType containsANX = anxBox1.Contains(anxBox2); ANX.Framework.ContainmentType containsANX = anxBox1.Contains(anxBox2);
if (containsXNA.Equals(containsANX)) if ((int)containsXNA == (int)containsANX)
Assert.Pass("ContainsBoundingBox passed"); Assert.Pass("ContainsBoundingBox passed");
else else
Assert.Fail(String.Format("ContainsBoundingBox failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString())); Assert.Fail(String.Format("ContainsBoundingBox failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString()));
@ -176,7 +176,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox.Contains(xnaFrustum); Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox.Contains(xnaFrustum);
ANX.Framework.ContainmentType containsANX = anxBox.Contains(anxFrustum); ANX.Framework.ContainmentType containsANX = anxBox.Contains(anxFrustum);
if (containsXNA.Equals(containsANX)) if ((int)containsXNA == (int)containsANX)
Assert.Pass("ContainsBoundingFrustum passed"); Assert.Pass("ContainsBoundingFrustum passed");
else else
Assert.Fail(String.Format("ContainsBoundingFrustum failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString())); Assert.Fail(String.Format("ContainsBoundingFrustum failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString()));
@ -194,7 +194,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox.Contains(xnaSphere); Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox.Contains(xnaSphere);
ANX.Framework.ContainmentType containsANX = anxBox.Contains(anxSphere); ANX.Framework.ContainmentType containsANX = anxBox.Contains(anxSphere);
if (containsXNA.Equals(containsANX)) if ((int)containsXNA == (int)containsANX)
Assert.Pass("ContainsBoundingSphere passed"); Assert.Pass("ContainsBoundingSphere passed");
else else
Assert.Fail(String.Format("ContainsBoundingSphere failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString())); Assert.Fail(String.Format("ContainsBoundingSphere failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString()));
@ -212,7 +212,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox.Contains(xnaPoint); Microsoft.Xna.Framework.ContainmentType containsXNA = xnaBox.Contains(xnaPoint);
ANX.Framework.ContainmentType containsANX = anxBox.Contains(anxPoint); ANX.Framework.ContainmentType containsANX = anxBox.Contains(anxPoint);
if (containsXNA.Equals(containsANX)) if ((int)containsXNA == (int)containsANX)
Assert.Pass("ContainsPoint passed"); Assert.Pass("ContainsPoint passed");
else else
Assert.Fail(String.Format("ContainsPoint failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString())); Assert.Fail(String.Format("ContainsPoint failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString()));
@ -284,7 +284,30 @@ namespace ANX.Framework.TestCenter.Strukturen
XNAVector3[] xna = xnaBox.GetCorners(); XNAVector3[] xna = xnaBox.GetCorners();
ANXVector3[] anx = anxBox.GetCorners(); ANXVector3[] anx = anxBox.GetCorners();
if (xna.Equals(anx)) if (xna[0].X == anx[0].X &&
xna[0].Y == anx[0].Y &&
xna[0].Z == anx[0].Z &&
xna[1].X == anx[1].X &&
xna[1].Y == anx[1].Y &&
xna[1].Z == anx[1].Z &&
xna[2].X == anx[2].X &&
xna[2].Y == anx[2].Y &&
xna[2].Z == anx[2].Z &&
xna[3].X == anx[3].X &&
xna[3].Y == anx[3].Y &&
xna[3].Z == anx[3].Z &&
xna[4].X == anx[4].X &&
xna[4].Y == anx[4].Y &&
xna[4].Z == anx[4].Z &&
xna[5].X == anx[5].X &&
xna[5].Y == anx[5].Y &&
xna[5].Z == anx[5].Z &&
xna[6].X == anx[6].X &&
xna[6].Y == anx[6].Y &&
xna[6].Z == anx[6].Z &&
xna[7].X == anx[7].X &&
xna[7].Y == anx[7].Y &&
xna[7].Z == anx[7].Z)
Assert.Pass("GetCorners passed"); Assert.Pass("GetCorners passed");
else else
Assert.Fail(String.Format("GetCorners failed: xna({0}) anx({1})", xna.ToString(), anx.ToString())); Assert.Fail(String.Format("GetCorners failed: xna({0}) anx({1})", xna.ToString(), anx.ToString()));
@ -311,7 +334,7 @@ namespace ANX.Framework.TestCenter.Strukturen
} }
[Test, TestCaseSource("twentytwofloats")] [Test, TestCaseSource("twentytwofloats")]
public void IntersctsFrustum(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44, public void IntersectsFrustum(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44,
float xMin, float yMin, float zMin, float xMax, float yMax, float zMax) float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
{ {
XNABoundingBox xnaBox = new XNABoundingBox(new XNAVector3(xMin, yMin, zMin), new XNAVector3(xMax, yMax, zMax)); XNABoundingBox xnaBox = new XNABoundingBox(new XNAVector3(xMin, yMin, zMin), new XNAVector3(xMax, yMax, zMax));
@ -326,9 +349,9 @@ namespace ANX.Framework.TestCenter.Strukturen
bool anx = anxBox.Intersects(anxFrustum); bool anx = anxBox.Intersects(anxFrustum);
if (xna.Equals(anx)) if (xna.Equals(anx))
Assert.Pass("IntersctsFrustum passed"); Assert.Pass("IntersectsFrustum passed");
else else
Assert.Fail(String.Format("IntersctsFrustum failed: xna({0}) anx({1})", xna.ToString(), anx.ToString())); Assert.Fail(String.Format("IntersectsFrustum failed: xna({0}) anx({1})", xna.ToString(), anx.ToString()));
} }
[Test, TestCaseSource("tenfloats")] [Test, TestCaseSource("tenfloats")]
@ -361,7 +384,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.PlaneIntersectionType xna = xnaBox.Intersects(xnaPlane); Microsoft.Xna.Framework.PlaneIntersectionType xna = xnaBox.Intersects(xnaPlane);
ANX.Framework.PlaneIntersectionType anx = anxBox.Intersects(anxPlane); ANX.Framework.PlaneIntersectionType anx = anxBox.Intersects(anxPlane);
if (xna.Equals(anx)) if ((int)xna == (int)anx)
Assert.Pass("IntersectsPlane passed"); Assert.Pass("IntersectsPlane passed");
else else
Assert.Fail(String.Format("IntersectsPlane failed: xna({0}) anx({1})", xna.ToString(), anx.ToString())); Assert.Fail(String.Format("IntersectsPlane failed: xna({0}) anx({1})", xna.ToString(), anx.ToString()));

View File

@ -67,21 +67,21 @@ namespace ANX.Framework.TestCenter.Strukturen
#region Helper #region Helper
static object[] thirtytwofloats = static object[] thirtytwofloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue,
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue, DataFactory.RandomValue },
}; };
#endregion #endregion
@ -209,7 +209,30 @@ namespace ANX.Framework.TestCenter.Strukturen
XNAVector3[] xna = xnaFrustum.GetCorners(); XNAVector3[] xna = xnaFrustum.GetCorners();
ANXVector3[] anx = anxFrustum.GetCorners(); ANXVector3[] anx = anxFrustum.GetCorners();
if (xna.Equals(anx)) if (xna[0].X == anx[0].X &&
xna[0].Y == anx[0].Y &&
xna[0].Z == anx[0].Z &&
xna[1].X == anx[1].X &&
xna[1].Y == anx[1].Y &&
xna[1].Z == anx[1].Z &&
xna[2].X == anx[2].X &&
xna[2].Y == anx[2].Y &&
xna[2].Z == anx[2].Z &&
xna[3].X == anx[3].X &&
xna[3].Y == anx[3].Y &&
xna[3].Z == anx[3].Z &&
xna[4].X == anx[4].X &&
xna[4].Y == anx[4].Y &&
xna[4].Z == anx[4].Z &&
xna[5].X == anx[5].X &&
xna[5].Y == anx[5].Y &&
xna[5].Z == anx[5].Z &&
xna[6].X == anx[6].X &&
xna[6].Y == anx[6].Y &&
xna[6].Z == anx[6].Z &&
xna[7].X == anx[7].X &&
xna[7].Y == anx[7].Y &&
xna[7].Z == anx[7].Z)
Assert.Pass("GetCorners passed"); Assert.Pass("GetCorners passed");
else else
Assert.Fail(String.Format("GetCorners failed: xna({0}) anx({1})", xna.ToString(), anx.ToString())); Assert.Fail(String.Format("GetCorners failed: xna({0}) anx({1})", xna.ToString(), anx.ToString()));
@ -302,7 +325,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.PlaneIntersectionType xna = xnaFrustum.Intersects(xnaPlane); Microsoft.Xna.Framework.PlaneIntersectionType xna = xnaFrustum.Intersects(xnaPlane);
ANX.Framework.PlaneIntersectionType anx = anxFrustum.Intersects(anxPlane); ANX.Framework.PlaneIntersectionType anx = anxFrustum.Intersects(anxPlane);
if (xna.Equals(anx)) if ((int)xna == (int)anx)
Assert.Pass("IntersectsPlane passed"); Assert.Pass("IntersectsPlane passed");
else else
Assert.Fail(String.Format("IntersectsPlane failed: xna({0}) anx({1})", xna.ToString(), anx.ToString())); Assert.Fail(String.Format("IntersectsPlane failed: xna({0}) anx({1})", xna.ToString(), anx.ToString()));

View File

@ -67,43 +67,43 @@ namespace ANX.Framework.TestCenter.Strukturen
#region Helper #region Helper
static object[] fourfloats = static object[] fourfloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
}; };
static object[] eightfloats = static object[] eightfloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
}; };
static object[] tenfloats = static object[] tenfloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
}; };
static object[] twentyfloats = static object[] twentyfloats =
{ {
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
new object[] { DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, new object[] { DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f),
DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat, DataFactory.RandomFloat }, DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f), DataFactory.RandomValueMinMax(0f, 1000f) },
}; };
#endregion #endregion
@ -169,7 +169,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.ContainmentType containsXNA = xnaSphere.Contains(xnaFrustum); Microsoft.Xna.Framework.ContainmentType containsXNA = xnaSphere.Contains(xnaFrustum);
ANX.Framework.ContainmentType containsANX = anxSphere.Contains(anxFrustum); ANX.Framework.ContainmentType containsANX = anxSphere.Contains(anxFrustum);
if (containsXNA.Equals(containsANX)) if ((int)containsXNA == (int)containsANX)
Assert.Pass("ContainsBoundingFrustum passed"); Assert.Pass("ContainsBoundingFrustum passed");
else else
Assert.Fail(String.Format("ContainsBoundingFrustum failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString())); Assert.Fail(String.Format("ContainsBoundingFrustum failed: xna({0}) anx({1})", containsXNA.ToString(), containsANX.ToString()));
@ -358,7 +358,7 @@ namespace ANX.Framework.TestCenter.Strukturen
Microsoft.Xna.Framework.PlaneIntersectionType xna = xnaSphere.Intersects(xnaPlane); Microsoft.Xna.Framework.PlaneIntersectionType xna = xnaSphere.Intersects(xnaPlane);
ANX.Framework.PlaneIntersectionType anx = anxSphere.Intersects(anxPlane); ANX.Framework.PlaneIntersectionType anx = anxSphere.Intersects(anxPlane);
if (xna.Equals(anx)) if ((int)xna == (int)anx)
Assert.Pass("IntersectsPlane passed"); Assert.Pass("IntersectsPlane passed");
else else
Assert.Fail(String.Format("IntersectsPlane failed: xna({0}) anx({1})", xna.ToString(), anx.ToString())); Assert.Fail(String.Format("IntersectsPlane failed: xna({0}) anx({1})", xna.ToString(), anx.ToString()));
@ -371,9 +371,11 @@ namespace ANX.Framework.TestCenter.Strukturen
{ {
XNABoundingSphere xnaSphere = new XNABoundingSphere(new XNAVector3(xS, yS, zS), r); XNABoundingSphere xnaSphere = new XNABoundingSphere(new XNAVector3(xS, yS, zS), r);
Microsoft.Xna.Framework.Ray xnaRay = new Microsoft.Xna.Framework.Ray(new XNAVector3(xRay, yRay, zRay), new XNAVector3(xDir, yDir, zDir)); Microsoft.Xna.Framework.Ray xnaRay = new Microsoft.Xna.Framework.Ray(new XNAVector3(xRay, yRay, zRay), new XNAVector3(xDir, yDir, zDir));
xnaRay.Direction.Normalize();
ANXBoundingSphere anxSphere = new ANXBoundingSphere(new ANXVector3(xS, yS, zS), r); ANXBoundingSphere anxSphere = new ANXBoundingSphere(new ANXVector3(xS, yS, zS), r);
ANX.Framework.Ray anxRay = new ANX.Framework.Ray(new ANXVector3(xRay, yRay, zRay), new ANXVector3(xDir, yDir, zDir)); ANX.Framework.Ray anxRay = new ANX.Framework.Ray(new ANXVector3(xRay, yRay, zRay), new ANXVector3(xDir, yDir, zDir));
anxRay.Direction.Normalize();
float? xna = xnaSphere.Intersects(xnaRay); float? xna = xnaSphere.Intersects(xnaRay);
float? anx = anxSphere.Intersects(anxRay); float? anx = anxSphere.Intersects(anxRay);

View File

@ -61,7 +61,6 @@ namespace ANX.Framework
public const int CornerCount = 8; public const int CornerCount = 8;
#endregion #endregion
#region constructors #region constructors
public BoundingBox(Vector3 min, Vector3 max) public BoundingBox(Vector3 min, Vector3 max)
{ {
@ -70,7 +69,6 @@ namespace ANX.Framework
} }
#endregion #endregion
#region public methods #region public methods
public ContainmentType Contains(BoundingBox box) public ContainmentType Contains(BoundingBox box)
{ {
@ -78,71 +76,278 @@ namespace ANX.Framework
this.Contains(ref box, out result); this.Contains(ref box, out result);
return result; return result;
} }
public void Contains(ref BoundingBox box, out ContainmentType result) public void Contains(ref BoundingBox box, out ContainmentType result)
{ {
throw new Exception("method has not yet been implemented"); result = ContainmentType.Disjoint;
if (box.Min.X >= this.Min.X && box.Min.X <= this.Max.X &&
box.Min.Y >= this.Min.Y && box.Min.Y <= this.Max.Y &&
box.Min.Z >= this.Min.Z && box.Min.Z <= this.Max.Z)
{
result = ContainmentType.Intersects;
}
if (box.Max.X >= this.Min.X && box.Max.X <= this.Max.X &&
box.Max.Y >= this.Min.Y && box.Max.Y <= this.Max.Y &&
box.Max.Z >= this.Min.Z && box.Max.Z <= this.Max.Z)
{
if (result == ContainmentType.Intersects)
result = ContainmentType.Contains;
else
result = ContainmentType.Intersects;
}
} }
public ContainmentType Contains(BoundingFrustum frustum) public ContainmentType Contains(BoundingFrustum frustum)
{ {
ContainmentType result; Vector3[] points = frustum.GetCorners();
this.Contains(ref frustum, out result);
return result; int pointsIn = 0;
} for (int i = 0; i < points.Length; i++)
public ContainmentType Contains (ref BoundingFrustum frustum,out ContainmentType result) {
{ Vector3 point = points[i];
throw new Exception("method has not yet been implemented");
if (point.X < this.Min.X ||
point.Z < this.Min.Z ||
point.Y < this.Min.Y ||
point.X > this.Max.X ||
point.Y > this.Max.Y ||
point.Z > this.Max.Z)
{
continue;
}
if (i != 0 && pointsIn == 0)
return ContainmentType.Intersects;
pointsIn++;
}
if (pointsIn == points.Length)
return ContainmentType.Contains;
return ContainmentType.Disjoint;
} }
public ContainmentType Contains(BoundingSphere sphere) public ContainmentType Contains(BoundingSphere sphere)
{ {
ContainmentType result; ContainmentType result;
this.Contains(ref sphere, out result); this.Contains(ref sphere, out result);
return result; return result;
} }
//source: monoxna
public void Contains(ref BoundingSphere sphere, out ContainmentType result) public void Contains(ref BoundingSphere sphere, out ContainmentType result)
{ {
throw new Exception("method has not yet been implemented"); //TODO: Find an other way, this one often is wrong!
if (sphere.Center.X - Min.X > sphere.Radius
&& sphere.Center.Y - Min.Y > sphere.Radius
&& sphere.Center.Z - Min.Z > sphere.Radius
&& Max.X - sphere.Center.X > sphere.Radius
&& Max.Y - sphere.Center.Y > sphere.Radius
&& Max.Z - sphere.Center.Z > sphere.Radius)
{
result = ContainmentType.Contains;
return;
}
double dmin = 0;
if (sphere.Center.X - Min.X <= sphere.Radius)
dmin += (sphere.Center.X - Min.X) * (sphere.Center.X - Min.X);
else if (Max.X - sphere.Center.X <= sphere.Radius)
dmin += (sphere.Center.X - Max.X) * (sphere.Center.X - Max.X);
if (sphere.Center.Y - Min.Y <= sphere.Radius)
dmin += (sphere.Center.Y - Min.Y) * (sphere.Center.Y - Min.Y);
else if (Max.Y - sphere.Center.Y <= sphere.Radius)
dmin += (sphere.Center.Y - Max.Y) * (sphere.Center.Y - Max.Y);
if (sphere.Center.Z - Min.Z <= sphere.Radius)
dmin += (sphere.Center.Z - Min.Z) * (sphere.Center.Z - Min.Z);
else if (Max.Z - sphere.Center.Z <= sphere.Radius)
dmin += (sphere.Center.Z - Max.Z) * (sphere.Center.Z - Max.Z);
if (dmin <= sphere.Radius * sphere.Radius)
result = ContainmentType.Intersects;
else
result = ContainmentType.Disjoint;
} }
public ContainmentType Contains(Vector3 point) public ContainmentType Contains(Vector3 point)
{ {
ContainmentType result; ContainmentType result;
this.Contains(ref point, out result); this.Contains(ref point, out result);
return result; return result;
} }
public void Contains(ref Vector3 point, out ContainmentType result) public void Contains(ref Vector3 point, out ContainmentType result)
{ {
throw new Exception("method has not yet been implemented"); result = ContainmentType.Disjoint;
if (point.X < this.Min.X ||
point.Z < this.Min.Z ||
point.Y < this.Min.Y ||
point.X > this.Max.X ||
point.Y > this.Max.Y ||
point.Z > this.Max.Z)
{
result = ContainmentType.Disjoint;
}
else if (point.X == this.Min.X ||
point.Z == this.Min.Z ||
point.Y == this.Min.Y ||
point.X == this.Max.X ||
point.Y == this.Max.Y ||
point.Z == this.Max.Z)
{
result = ContainmentType.Intersects;
}
else
{
result = ContainmentType.Contains;
}
} }
public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points) public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points)
{ {
throw new Exception("method has not yet been implemented"); if (points == null)
throw new ArgumentNullException("Points must not be null");
Vector3 min = new Vector3();
Vector3 max = new Vector3();
int p = 0;
foreach (Vector3 point in points)
{
if (p == 0)
{
min = point;
max = point;
}
else
{
min.X = Math.Min(point.X, min.X);
min.Y = Math.Min(point.Y, min.Y);
min.Z = Math.Min(point.Z, min.Z);
max.X = Math.Max(point.X, max.X);
max.Y = Math.Max(point.Y, max.Y);
max.Z = Math.Max(point.Z, max.Z);
}
p++;
}
return new BoundingBox(min, max);
} }
public static BoundingBox CreateFromSphere(BoundingSphere sphere) public static BoundingBox CreateFromSphere(BoundingSphere sphere)
{ {
throw new Exception("method has not yet been implemented"); BoundingBox result;
CreateFromSphere(ref sphere, out result);
return result;
} }
public static void CreateFromSphere(ref BoundingSphere sphere, out BoundingBox result) public static void CreateFromSphere(ref BoundingSphere sphere, out BoundingBox result)
{ {
throw new Exception("method has not yet been implemented"); Vector3 min = new Vector3();
Vector3 max = new Vector3();
min.X = sphere.Center.X - sphere.Radius;
min.Y = sphere.Center.Y - sphere.Radius;
min.Z = sphere.Center.Z - sphere.Radius;
max.X = sphere.Center.X + sphere.Radius;
max.Y = sphere.Center.Y + sphere.Radius;
max.Z = sphere.Center.Z + sphere.Radius;
result = new BoundingBox(min, max);
} }
public static BoundingBox CreateMerged(BoundingBox original, BoundingBox additional) public static BoundingBox CreateMerged(BoundingBox original, BoundingBox additional)
{ {
throw new Exception("method has not yet been implemented"); BoundingBox result;
CreateMerged(ref original, ref additional, out result);
return result;
} }
public static void CreateMerged(ref BoundingBox original, ref BoundingBox additional, out BoundingBox result) public static void CreateMerged(ref BoundingBox original, ref BoundingBox additional, out BoundingBox result)
{ {
throw new Exception("method has not yet been implemented"); Vector3 min = new Vector3();
Vector3 max = new Vector3();
min.X = Math.Min(original.Min.X, additional.Min.X);
min.Y = Math.Min(original.Min.Y, additional.Min.Y);
min.Z = Math.Min(original.Min.Z, additional.Min.Z);
max.X = Math.Max(original.Max.X, additional.Max.X);
max.Y = Math.Max(original.Max.Y, additional.Max.Y);
max.Z = Math.Max(original.Max.Z, additional.Max.Z);
result = new BoundingBox(min, max);
} }
public Vector3[] GetCorners() public Vector3[] GetCorners()
{ {
throw new Exception("method has not yet been implemented"); Vector3[] corners = new Vector3[BoundingBox.CornerCount];
corners[0].X = this.Min.X;
corners[0].Y = this.Max.Y;
corners[0].Z = this.Max.Z;
corners[1].X = this.Max.X;
corners[1].Y = this.Max.Y;
corners[1].Z = this.Max.Z;
corners[2].X = this.Max.X;
corners[2].Y = this.Min.Y;
corners[2].Z = this.Max.Z;
corners[3].X = this.Min.X;
corners[3].Y = this.Min.Y;
corners[3].Z = this.Max.Z;
corners[4].X = this.Min.X;
corners[4].Y = this.Max.Y;
corners[4].Z = this.Min.Z;
corners[5].X = this.Max.X;
corners[5].Y = this.Max.Y;
corners[5].Z = this.Min.Z;
corners[6].X = this.Max.X;
corners[6].Y = this.Min.Y;
corners[6].Z = this.Min.Z;
corners[7].X = this.Min.X;
corners[7].Y = this.Min.Y;
corners[7].Z = this.Min.Z;
return corners;
} }
public void GetCorners(Vector3[] corners) public void GetCorners(Vector3[] corners)
{ {
throw new Exception("method has not yet been implemented"); if (corners.Length != BoundingBox.CornerCount)
throw new ArgumentException("Corners has to have a Length of" + BoundingBox.CornerCount.ToString());
corners[0].X = this.Min.X;
corners[0].Y = this.Max.Y;
corners[0].Z = this.Max.Z;
corners[1].X = this.Max.X;
corners[1].Y = this.Max.Y;
corners[1].Z = this.Max.Z;
corners[2].X = this.Max.X;
corners[2].Y = this.Min.Y;
corners[2].Z = this.Max.Z;
corners[3].X = this.Min.X;
corners[3].Y = this.Min.Y;
corners[3].Z = this.Max.Z;
corners[4].X = this.Min.X;
corners[4].Y = this.Max.Y;
corners[4].Z = this.Min.Z;
corners[5].X = this.Max.X;
corners[5].Y = this.Max.Y;
corners[5].Z = this.Min.Z;
corners[6].X = this.Max.X;
corners[6].Y = this.Min.Y;
corners[6].Z = this.Min.Z;
corners[7].X = this.Min.X;
corners[7].Y = this.Min.Y;
corners[7].Z = this.Min.Z;
} }
public override int GetHashCode() public override int GetHashCode()
@ -152,48 +357,220 @@ namespace ANX.Framework
public bool Intersects(BoundingBox box) public bool Intersects(BoundingBox box)
{ {
throw new Exception("method has not yet been implemented"); bool result;
Intersects(ref box, out result);
return result;
} }
public void Intersects(ref BoundingBox box, out bool result) public void Intersects(ref BoundingBox box, out bool result)
{ {
throw new Exception("method has not yet been implemented"); result = false;
if (box.Min.X >= this.Min.X && box.Min.X <= this.Max.X &&
box.Min.Y >= this.Min.Y && box.Min.Y <= this.Max.Y &&
box.Min.Z >= this.Min.Z && box.Min.Z <= this.Max.Z)
{
result = true;
return;
}
if (box.Max.X >= this.Min.X && box.Max.X <= this.Max.X &&
box.Max.Y >= this.Min.Y && box.Max.Y <= this.Max.Y &&
box.Max.Z >= this.Min.Z && box.Max.Z <= this.Max.Z)
{
result = true;
return;
}
} }
public bool Intersects(BoundingFrustum frustum) public bool Intersects(BoundingFrustum frustum)
{ {
throw new Exception("method has not yet been implemented"); Vector3[] points = frustum.GetCorners();
for (int i = 0; i < points.Length; i++)
{
Vector3 point = points[i];
if (point.X < this.Min.X ||
point.Z < this.Min.Z ||
point.Y < this.Min.Y ||
point.X > this.Max.X ||
point.Y > this.Max.Y ||
point.Z > this.Max.Z)
{
continue;
}
return true;
}
return false;
} }
public bool Intersects(BoundingSphere sphere) public bool Intersects(BoundingSphere sphere)
{ {
throw new Exception("method has not yet been implemented"); bool result;
Intersects(ref sphere, out result);
return result;
} }
//source: monoxna
public void Intersects(ref BoundingSphere sphere, out bool result) public void Intersects(ref BoundingSphere sphere, out bool result)
{ {
throw new Exception("method has not yet been implemented"); //TODO: Find an other way, this one often is wrong!
if (sphere.Center.X - Min.X > sphere.Radius
&& sphere.Center.Y - Min.Y > sphere.Radius
&& sphere.Center.Z - Min.Z > sphere.Radius
&& Max.X - sphere.Center.X > sphere.Radius
&& Max.Y - sphere.Center.Y > sphere.Radius
&& Max.Z - sphere.Center.Z > sphere.Radius)
{
result = true;
return;
}
double dmin = 0;
if (sphere.Center.X - Min.X <= sphere.Radius)
dmin += (sphere.Center.X - Min.X) * (sphere.Center.X - Min.X);
else if (Max.X - sphere.Center.X <= sphere.Radius)
dmin += (sphere.Center.X - Max.X) * (sphere.Center.X - Max.X);
if (sphere.Center.Y - Min.Y <= sphere.Radius)
dmin += (sphere.Center.Y - Min.Y) * (sphere.Center.Y - Min.Y);
else if (Max.Y - sphere.Center.Y <= sphere.Radius)
dmin += (sphere.Center.Y - Max.Y) * (sphere.Center.Y - Max.Y);
if (sphere.Center.Z - Min.Z <= sphere.Radius)
dmin += (sphere.Center.Z - Min.Z) * (sphere.Center.Z - Min.Z);
else if (Max.Z - sphere.Center.Z <= sphere.Radius)
dmin += (sphere.Center.Z - Max.Z) * (sphere.Center.Z - Max.Z);
if (dmin <= sphere.Radius * sphere.Radius)
result = true;
else
result = false;
} }
public PlaneIntersectionType Intersects(Plane plane) public PlaneIntersectionType Intersects(Plane plane)
{ {
throw new Exception("method has not yet been implemented"); PlaneIntersectionType result;
Intersects(ref plane, out result);
return result;
} }
public void Intersects(ref Plane plane, out PlaneIntersectionType result) public void Intersects(ref Plane plane, out PlaneIntersectionType result)
{ {
throw new Exception("method has not yet been implemented"); Vector3 p = this.Min;
if (plane.Normal.X >= 0)
p.X = this.Max.X;
if (plane.Normal.Y >= 0)
p.Y = this.Max.Y;
if (plane.Normal.Z < 0)
p.Z = this.Max.Z;
float distance;
Vector3 planeNormal = -plane.Normal;
Vector3.Dot(ref planeNormal, ref p, out distance);
distance -= plane.D;
if (distance < 0)
result = PlaneIntersectionType.Front;
else if (distance > 0)
result = PlaneIntersectionType.Back;
else
result = PlaneIntersectionType.Intersecting;
} }
public Nullable<float> Intersects(Ray ray) public Nullable<float> Intersects(Ray ray)
{ {
throw new Exception("method has not yet been implemented"); Nullable<float> result;
Intersects(ref ray, out result);
return result;
} }
// source for implementation:
// http://courses.csusm.edu/cs697exz/ray_box.htm
public void Intersects(ref Ray ray, out Nullable<float> result) public void Intersects(ref Ray ray, out Nullable<float> result)
{ {
throw new Exception("method has not yet been implemented"); float tnear = float.NegativeInfinity;
float tfar = float.PositiveInfinity;
float t1 = (this.Min.X - ray.Position.X) - ray.Direction.X;
float t2 = (this.Max.X - ray.Position.X) - ray.Direction.X;
if (t1 > t2)
{
float t = t1;
t1 = t2;
t2 = t;
}
if (t1 > tnear)
tnear = t1;
if (t2 < tfar)
tfar = t2;
if (tnear > tfar || tfar < 0)
{
result = null;
return;
}
t1 = (this.Min.Y - ray.Position.Y) - ray.Direction.Y;
t2 = (this.Max.Y - ray.Position.Y) - ray.Direction.Y;
if (t1 > t2)
{
float t = t1;
t1 = t2;
t2 = t;
}
if (t1 > tnear)
tnear = t1;
if (t2 < tfar)
tfar = t2;
if (tnear > tfar || tfar < 0)
{
result = null;
return;
}
t1 = (this.Min.Z - ray.Position.Z) - ray.Direction.Z;
t2 = (this.Max.Z - ray.Position.Z) - ray.Direction.Z;
if (t1 > t2)
{
float t = t1;
t1 = t2;
t2 = t;
}
if (t1 > tnear)
tnear = t1;
if (t2 < tfar)
tfar = t2;
if (tnear > tfar || tfar < 0)
{
result = null;
return;
}
result = tfar;
} }
public override string ToString() public override string ToString()
{ {
throw new Exception("method has not yet been implemented"); return "Min:" + Min.ToString() + " Max:" + Max.ToString();
} }
#endregion #endregion
#region IEquatable implementation #region IEquatable implementation
public override bool Equals(Object obj) public override bool Equals(Object obj)
{ {
@ -205,7 +582,6 @@ namespace ANX.Framework
} }
#endregion #endregion
#region operator overloading #region operator overloading
public static bool operator ==(BoundingBox a, BoundingBox b) public static bool operator ==(BoundingBox a, BoundingBox b)
{ {

View File

@ -59,68 +59,46 @@ namespace ANX.Framework
#endregion #endregion
#region properties #region properties
public Plane Bottom private Vector3[] corners;
{
get
{
throw new Exception("property has not yet been implemented");
}
}
public Plane Far
{
get
{
throw new Exception("property has not yet been implemented");
}
}
public Plane Left
{
get
{
throw new Exception("property has not yet been implemented");
}
}
private Matrix matrix; private Matrix matrix;
public Matrix Matrix public Matrix Matrix
{ {
get get { return this.matrix; }
{ set
return matrix; {
} this.matrix = value;
set this.CreatePlanes();
{ this.CreateCorners();
throw new Exception("property has not yet been implemented"); }
}
} }
public Plane Near private Plane near;
{ public Plane Near { get { return this.near; } }
get
{ private Plane far;
throw new Exception("property has not yet been implemented"); public Plane Far { get { return this.far; } }
}
} private Plane top;
public Plane Right public Plane Top { get { return this.top; } }
{
get private Plane bottom;
{ public Plane Bottom { get { return this.bottom; } }
throw new Exception("property has not yet been implemented");
} private Plane right;
} public Plane Right { get { return this.right; } }
public Plane Top
{ private Plane left;
get public Plane Left { get { return this.left; } }
{
throw new Exception("property has not yet been implemented");
}
}
#endregion #endregion
#region constructors #region constructors
public BoundingFrustum(Matrix value) public BoundingFrustum(Matrix value)
{ {
corners = new Vector3[CornerCount];
this.matrix = value; this.matrix = value;
CreatePlanes();
CreateCorners();
} }
#endregion #endregion
@ -162,17 +140,18 @@ namespace ANX.Framework
public Vector3[] GetCorners() public Vector3[] GetCorners()
{ {
throw new Exception("method has not yet been implemented"); return this.corners;
} }
public void GetCorners(Vector3[] corners) public void GetCorners(Vector3[] corners)
{ {
throw new Exception("method has not yet been implemented"); corners = this.corners;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
throw new Exception("method has not yet been implemented"); //TODO: implement
return base.GetHashCode();
} }
public bool Intersects(BoundingBox box) public bool Intersects(BoundingBox box)
@ -225,6 +204,94 @@ namespace ANX.Framework
} }
#endregion #endregion
#region private methods
//algorithm from: http://crazyjoke.free.fr/doc/3D/plane%20extraction.pdf
private void CreatePlanes()
{
this.left.Normal.X = this.matrix.M14 + this.matrix.M11;
this.left.Normal.Y = this.matrix.M24 + this.matrix.M21;
this.left.Normal.Z = this.matrix.M34 + this.matrix.M31;
this.left.D = this.matrix.M44 + this.matrix.M41;
this.right.Normal.X = this.matrix.M14 - this.matrix.M11;
this.right.Normal.Y = this.matrix.M24 - this.matrix.M21;
this.right.Normal.Z = this.matrix.M34 - this.matrix.M31;
this.right.D = this.matrix.M44 - this.matrix.M41;
this.bottom.Normal.X = this.matrix.M14 + this.matrix.M12;
this.bottom.Normal.Y = this.matrix.M24 + this.matrix.M22;
this.bottom.Normal.Z = this.matrix.M34 + this.matrix.M32;
this.bottom.D = this.matrix.M44 + this.matrix.M42;
this.top.Normal.X = this.matrix.M14 - this.matrix.M12;
this.top.Normal.Y = this.matrix.M24 - this.matrix.M22;
this.top.Normal.Z = this.matrix.M34 - this.matrix.M32;
this.top.D = this.matrix.M44 - this.matrix.M42;
this.near.Normal.X = this.matrix.M13;
this.near.Normal.Y = this.matrix.M23;
this.near.Normal.Z = this.matrix.M33;
this.near.D = this.matrix.M43;
this.far.Normal.X = this.matrix.M14 - this.matrix.M13;
this.far.Normal.Y = this.matrix.M24 - this.matrix.M23;
this.far.Normal.Z = this.matrix.M34 - this.matrix.M33;
this.far.D = this.matrix.M44 - this.matrix.M43;
NormalizePlane(ref this.left);
NormalizePlane(ref this.right);
NormalizePlane(ref this.bottom);
NormalizePlane(ref this.top);
NormalizePlane(ref this.near);
NormalizePlane(ref this.far);
}
//source: monoxna
private void NormalizePlane(ref Plane p)
{
float factor = 1f / p.Normal.Length();
p.Normal.X *= factor;
p.Normal.Y *= factor;
p.Normal.Z *= factor;
p.D *= factor;
}
//source: monoxna
private static Vector3 IntersectionPoint(ref Plane a, ref Plane b, ref Plane c)
{
// Formula used
// d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 )
//P = -------------------------------------------------------------------------
// N1 . ( N2 * N3 )
//
// Note: N refers to the normal, d refers to the displacement. '.' means dot product. '*' means cross product
Vector3 v1, v2, v3;
float f = -Vector3.Dot(a.Normal, Vector3.Cross(b.Normal, c.Normal));
v1 = (a.D * (Vector3.Cross(b.Normal, c.Normal)));
v2 = (b.D * (Vector3.Cross(c.Normal, a.Normal)));
v3 = (c.D * (Vector3.Cross(a.Normal, b.Normal)));
Vector3 vec = new Vector3(v1.X + v2.X + v3.X, v1.Y + v2.Y + v3.Y, v1.Z + v2.Z + v3.Z);
return vec / f;
}
//source: monoxna
private void CreateCorners()
{
this.corners = new Vector3[8];
this.corners[0] = IntersectionPoint(ref this.near, ref this.left, ref this.top);
this.corners[1] = IntersectionPoint(ref this.near, ref this.right, ref this.top);
this.corners[2] = IntersectionPoint(ref this.near, ref this.right, ref this.bottom);
this.corners[3] = IntersectionPoint(ref this.near, ref this.left, ref this.bottom);
this.corners[4] = IntersectionPoint(ref this.far, ref this.left, ref this.top);
this.corners[5] = IntersectionPoint(ref this.far, ref this.right, ref this.top);
this.corners[6] = IntersectionPoint(ref this.far, ref this.right, ref this.bottom);
this.corners[7] = IntersectionPoint(ref this.far, ref this.left, ref this.bottom);
}
#endregion
#region IEquatable implementation #region IEquatable implementation
public override bool Equals(Object obj) public override bool Equals(Object obj)
{ {

View File

@ -62,7 +62,6 @@ namespace ANX.Framework
#endregion #endregion
#region constructors #region constructors
public BoundingSphere(Vector3 center, float radius) public BoundingSphere(Vector3 center, float radius)
{ {
@ -72,7 +71,6 @@ namespace ANX.Framework
} }
#endregion #endregion
#region public methods #region public methods
public ContainmentType Contains(BoundingBox box) public ContainmentType Contains(BoundingBox box)
{ {
@ -80,6 +78,7 @@ namespace ANX.Framework
this.Contains(ref box, out result); this.Contains(ref box, out result);
return result; return result;
} }
public void Contains(ref BoundingBox box, out ContainmentType result) public void Contains(ref BoundingBox box, out ContainmentType result)
{ {
byte value = 0; byte value = 0;
@ -94,22 +93,39 @@ namespace ANX.Framework
result = value == 0 ? ContainmentType.Disjoint : value == 1 ? ContainmentType.Intersects : ContainmentType.Contains; result = value == 0 ? ContainmentType.Disjoint : value == 1 ? ContainmentType.Intersects : ContainmentType.Contains;
} }
public ContainmentType Contains(BoundingFrustum frustum) public ContainmentType Contains(BoundingFrustum frustum)
{ {
ContainmentType result; Vector3[] points = frustum.GetCorners();
this.Contains(ref frustum, out result); float radiusSquared = this.Radius * this.Radius;
return result;
} byte pointsIn = 0;
public ContainmentType Contains(ref BoundingFrustum frustum, out ContainmentType result) for (int i = 0; i < BoundingFrustum.CornerCount; i++)
{ {
throw new Exception("method has not yet been implemented"); float distance = Vector3.DistanceSquared(points[i], this.Center);
if (distance > radiusSquared)
continue;
if (i != 0 && pointsIn == 0)
return ContainmentType.Intersects;
pointsIn++;
}
if (pointsIn == BoundingFrustum.CornerCount)
return ContainmentType.Contains;
return ContainmentType.Disjoint;
} }
public ContainmentType Contains(BoundingSphere sphere) public ContainmentType Contains(BoundingSphere sphere)
{ {
ContainmentType result; ContainmentType result;
this.Contains(ref sphere, out result); this.Contains(ref sphere, out result);
return result; return result;
} }
public void Contains(ref BoundingSphere sphere, out ContainmentType result) public void Contains(ref BoundingSphere sphere, out ContainmentType result)
{ {
float distance = Vector3.Distance(this.Center, sphere.Center); float distance = Vector3.Distance(this.Center, sphere.Center);
@ -126,113 +142,294 @@ namespace ANX.Framework
} }
result = ContainmentType.Intersects; result = ContainmentType.Intersects;
} }
public ContainmentType Contains(Vector3 point) public ContainmentType Contains(Vector3 point)
{ {
ContainmentType result; ContainmentType result;
this.Contains(ref point, out result); this.Contains(ref point, out result);
return result; return result;
} }
public void Contains(ref Vector3 point, out ContainmentType result) public void Contains(ref Vector3 point, out ContainmentType result)
{ {
float distance = Vector3.DistanceSquared(point, this.Center); float distance = Vector3.DistanceSquared(point, this.Center);
if (distance > this.Radius*this.Radius) if (distance > this.Radius * this.Radius)
result= ContainmentType.Disjoint; {
result = ContainmentType.Disjoint;
return;
}
else if (distance < this.Radius * this.Radius) else if (distance < this.Radius * this.Radius)
result= ContainmentType.Contains; {
result = ContainmentType.Contains;
return;
}
result= ContainmentType.Intersects; result= ContainmentType.Intersects;
} }
public static BoundingSphere CreateFromBoundingBox(BoundingBox box) public static BoundingSphere CreateFromBoundingBox(BoundingBox box)
{ {
throw new Exception("method has not yet been implemented"); BoundingSphere result;
CreateFromBoundingBox(ref box, out result);
return result;
} }
public static void CreateFromBoundingBox(ref BoundingBox box, out BoundingSphere result) public static void CreateFromBoundingBox(ref BoundingBox box, out BoundingSphere result)
{ {
throw new Exception("method has not yet been implemented"); result.Center = new Vector3(
(box.Min.X + box.Max.X) * 0.5f,
(box.Min.Y + box.Max.Y) * 0.5f,
(box.Min.Z + box.Max.Z) * 0.5f);
result.Radius = Vector3.Distance(box.Min, result.Center);
} }
public static BoundingSphere CreateFromFrustum(BoundingFrustum frustum) public static BoundingSphere CreateFromFrustum(BoundingFrustum frustum)
{ {
throw new Exception("method has not yet been implemented"); return CreateFromPoints(frustum.GetCorners());
} }
//source: monoxna
public static BoundingSphere CreateFromPoints(IEnumerable<Vector3> points) public static BoundingSphere CreateFromPoints(IEnumerable<Vector3> points)
{ {
throw new Exception("method has not yet been implemented"); if (points == null)
throw new ArgumentNullException("points");
float radius = 0;
Vector3 center = new Vector3();
// First, we'll find the center of gravity for the point 'cloud'.
int num_points = 0; // The number of points (there MUST be a better way to get this instead of counting the number of points one by one?)
foreach (Vector3 v in points)
{
center += v; // If we actually knew the number of points, we'd get better accuracy by adding v / num_points.
++num_points;
}
center /= (float)num_points;
// Calculate the radius of the needed sphere (it equals the distance between the center and the point further away).
foreach (Vector3 v in points)
{
float distance = ((Vector3)(v - center)).Length();
if (distance > radius)
radius = distance;
}
return new BoundingSphere(center, radius);
} }
public static BoundingSphere CreateMerged(BoundingSphere original, BoundingSphere additional) public static BoundingSphere CreateMerged(BoundingSphere original, BoundingSphere additional)
{ {
throw new Exception("method has not yet been implemented"); BoundingSphere result;
CreateMerged(ref original, ref additional, out result);
return result;
} }
public static void CreateMerged(ref BoundingSphere original, ref BoundingSphere additional, out BoundingSphere result) public static void CreateMerged(ref BoundingSphere original, ref BoundingSphere additional, out BoundingSphere result)
{ {
throw new Exception("method has not yet been implemented"); throw new NotImplementedException();
} }
public override int GetHashCode() public override int GetHashCode()
{ {
throw new Exception("method has not yet been implemented"); throw new NotImplementedException();
} }
public bool Intersects(BoundingBox box) public bool Intersects(BoundingBox box)
{ {
throw new Exception("method has not yet been implemented"); bool result;
Intersects(ref box, out result);
return result;
} }
public void Intersects(ref BoundingBox box, out bool result) public void Intersects(ref BoundingBox box, out bool result)
{ {
throw new Exception("method has not yet been implemented"); if (Vector3.DistanceSquared(box.Max, this.Center) < this.Radius * this.Radius)
{
result = true;
return;
}
if (Vector3.DistanceSquared(box.Min, this.Center) < this.Radius * this.Radius)
{
result = true;
return;
}
result = false;
} }
public bool Intersects(BoundingFrustum frustum) public bool Intersects(BoundingFrustum frustum)
{ {
throw new Exception("method has not yet been implemented"); Vector3[] points = frustum.GetCorners();
float radiusSquared = this.Radius * this.Radius;
for (int i = 0; i < BoundingFrustum.CornerCount; i++)
{
float distance = Vector3.DistanceSquared(points[i], this.Center);
if (distance > radiusSquared)
continue;
return true;
}
return false;
} }
public bool Intersects(BoundingSphere sphere) public bool Intersects(BoundingSphere sphere)
{ {
throw new Exception("method has not yet been implemented"); bool result;
Intersects(ref sphere, out result);
return result;
} }
public void Intersects(ref BoundingSphere sphere, out bool result) public void Intersects(ref BoundingSphere sphere, out bool result)
{ {
throw new Exception("method has not yet been implemented"); float distance = Vector3.Distance(this.Center, sphere.Center);
float bothRadius = this.Radius + sphere.Radius;
if (distance > bothRadius)
{
result = false;
return;
}
result = true;
} }
public PlaneIntersectionType Intersects(Plane plane) public PlaneIntersectionType Intersects(Plane plane)
{ {
throw new Exception("method has not yet been implemented"); PlaneIntersectionType result;
Intersects(ref plane, out result);
return result;
} }
// Source: monoxna
public void Intersects(ref Plane plane, out PlaneIntersectionType result) public void Intersects(ref Plane plane, out PlaneIntersectionType result)
{ {
throw new Exception("method has not yet been implemented"); float distance = Vector3.Dot(plane.Normal, this.Center) + plane.D;
if (distance > this.Radius)
{
result = PlaneIntersectionType.Front;
return;
}
if (distance < -this.Radius)
{
result = PlaneIntersectionType.Back;
return;
}
result = PlaneIntersectionType.Intersecting;
} }
public Nullable<float> Intersects(Ray ray) public Nullable<float> Intersects(Ray ray)
{ {
throw new Exception("method has not yet been implemented"); Nullable<float> result;
Intersects(ref ray, out result);
return result;
} }
// Method copied from and descriebed here:
// http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection
public void Intersects(ref Ray ray, out Nullable<float> result) public void Intersects(ref Ray ray, out Nullable<float> result)
{ {
throw new Exception("method has not yet been implemented"); //TODO: Find an other way, this one often is wrong!
float a;
Vector3.Dot(ref ray.Direction, ref ray.Direction, out a);
float b;
Vector3.Dot(ref ray.Direction, ref ray.Position, out b);
b += b;
float c;
Vector3.Dot(ref ray.Position, ref ray.Position, out c);
c -= Radius * Radius;
//Find discriminant
float disc = b * b - 4 * a * c;
// if discriminant is negative there are no real roots, so return
// false as ray misses sphere
if (disc < 0)
{
result = null;
return;
}
float distSqrt = (float)Math.Sqrt(disc);
float q;
if (b < 0)
q = (-b - distSqrt) / 2.0f;
else
q = (-b + distSqrt) / 2.0f;
// compute t0 and t1
float t0 = q / a;
float t1 = c / q;
// make sure t0 is smaller than t1
if (t0 > t1)
{
// if t0 is bigger than t1 swap them around
float temp = t0;
t0 = t1;
t1 = temp;
}
// if t1 is less than zero, the object is in the ray's negative direction
// and consequently the ray misses the sphere
if (t1 < 0)
{
result = null;
return;
}
// if t0 is less than zero, the intersection point is at t1
if (t0 < 0)
{
result = t1;
return;
}
// else the intersection point is at t0
else
{
//if (float.IsNaN(t0))
// result = null;
//else
// result = t0;
result = t0;
return;
}
} }
public BoundingSphere Transform(Matrix matrix) public BoundingSphere Transform(Matrix matrix)
{ {
throw new NotImplementedException(); BoundingSphere result;
Transform(ref matrix, out result);
return result;
} }
public void Transform(ref Matrix matrix, out BoundingSphere result) public void Transform(ref Matrix matrix, out BoundingSphere result)
{ {
throw new NotImplementedException(); result = this;
result.Radius += Math.Max(matrix.M11, Math.Max(matrix.M22, matrix.M33));
result.Center.X += matrix.M41;
result.Center.Y += matrix.M42;
result.Center.Z += matrix.M43;
} }
public override string ToString() public override string ToString()
{ {
throw new Exception("method has not yet been implemented"); return "Center:" + Center.ToString() + " Radius:" + Radius.ToString();
} }
#endregion #endregion
#region IEquatable implementation #region IEquatable implementation
public override bool Equals(Object obj) public override bool Equals(Object obj)
{ {
@ -244,7 +441,6 @@ namespace ANX.Framework
} }
#endregion #endregion
#region operator overloading #region operator overloading
public static bool operator ==(BoundingSphere a, BoundingSphere b) public static bool operator ==(BoundingSphere a, BoundingSphere b)
{ {