So heres some straight up code for you:
BoundingBox b = new BoundingBox(
Vector3.Up + Vector3.Right + Vector3.Forward,
Vector3.Down + Vector3.Backward + Vector3.Left);
BoundingBox bb = new BoundingBox(
Vector3.Up/2 + Vector3.Right/2 + Vector3.Forward/2,
Vector3.Down/2 + Vector3.Backward/2 + Vector3.Left/2);
Debug.GraphicsManager.DrawLine(b, Color.Purple);
Debug.GraphicsManager.DrawLine(bb, Color.Yellow);
if (bb.Contains(b) == ContainmentType.Disjoint)
Debug.DisplayVariable("Disjoint", "");
if (bb.Contains(b) == ContainmentType.Contains)
Debug.DisplayVariable("Contains", "");
if (bb.Contains(b) == ContainmentType.Intersects)
Debug.DisplayVariable("Intersects", "");
What this does is create two bounding boxes, that /obviously/ intersect. DrawLine is a function that accepts a bounding box and draws it. Math and visuals tells us that these intersect and contain.
But all I get is disjoint.
So I started a new blank fresh clean project and only added this to the update code:
BoundingBox b = new BoundingBox(
Vector3.Up + Vector3.Right + Vector3.Forward,
Vector3.Backward + Vector3.Left);
BoundingBox bb = new BoundingBox(
Vector3.Up / 2 + Vector3.Right / 2 + Vector3.Forward / 2,
Vector3.Backward / 2 + Vector3.Left / 2);
if (bb.Contains(b) == ContainmentType.Disjoint)
System.Console.WriteLine("Disjoint");
if (bb.Contains(b) == ContainmentType.Contains)
System.Console.WriteLine("Contains");
if (bb.Contains(b) == ContainmentType.Intersects)
System.Console.WriteLine("Intersects");
if (bb.Intersects(b))
System.Console.WriteLine("intersex");
and this has the same problem.
So I'm stumped. Does XNA just not have good bounding box collison code? Or am I doing something wrong? should I write my own collison code?
Thanks for reading, no this is not debug for me, I simply don't understand.
edit: I also have mouse picking set up and it can identify and pick all my "models" based on Ray.Intersects(model.boundingbox) no problem.
Answer
The problem is is the order of your constructors. This works correctly. I put all the negative static Vector3
values into the min, and the positives into the max.
BoundingBox b = new BoundingBox(
Vector3.Left + Vector3.Forward,
Vector3.Backward + Vector3.Up + Vector3.Right);
BoundingBox bb = new BoundingBox(
Vector3.Left / 2 + Vector3.Forward / 2,
Vector3.Backward / 2 + Vector3.Up / 2 + Vector3.Right / 2);
No comments:
Post a Comment