1
votes

Basically I want to put a bounding box/cube around my 3D Model in XNA (in this case it is a simple painting so the model itself is just a textured rectangle).

I tried the following code to create the cube:

    public BoundingBox BoundingBoxCreation()
    {
        min = Position + Vector3.Up * Height - Size / 2
        max = Position + Vector3.Up * Height - Size / 2;

        boundingBox = new BoundingBox(min, max);
        return boundingBox; 
    }

Then I create two of the same models, with the same height, size and scale: Scale: new Vector3(500.0f) (large scale because I created them in Blender) Height: 2f Size: new Vector3(6.75f * 500, -1.09f * 500, 0.35f * 500) (Multiplied everything by the scale). Then I tried to check for the collision between the two like so:

if (CollisionTest.boundingBox.Intersects(tapestryLeftOne.boundingBox))
   {
      Window.Title = "Collision";
   } 

However the Window Title will only change to show the collision when the two are absolutely 100% perfectly aligned, but what I was going for is trying to make it so even if they touch at any point not just when they match up. Any ideas on how I could achieve this?

If there is a better way to construct a Bounding box/cube and detect collision between another bounding cube,sphere, etc then I would very much appreciate if you could show me.

1

1 Answers

0
votes

Based on the code you have, the min and max would be the same. This would explain why they only Intersect when they are perfectly aligned. Are you later modifying the bounds?

What you are doing looks correct, but you could also try Contains and check 4 corners (Vector3) if the boxes are the same size

Some more info on bounding boxes for models http://www.toymaker.info/Games/XNA/html/xna_bounding_box.html