17 thoughts on “BoundingBox Howto from Mesh

  1. was this example using 1st or 2nd Beta?

    I’m having trouble compiling the example… mostly because I can’t use the Content.Pipeline namespace. Compiler says that the “pipeline” namespace does not exist.

    I’m pretty sure I upgraded to the Beta 2 release of XNA.

  2. Pingback: XNAtutorial.com » Weekly Update

  3. When you choose New Project, select Class Library as project type. Do as above except also add Microsoft.XNA.Framework as well as the content pipeline reference. Build, and the dll file will be in the release folder for the project.

  4. Pingback: Artificial-Studios.co.uk » Blog Archive » Picking and Bounding Boxes

  5. Very cool! However, the bounding box coords are relative to each model, not the world. I (a true novice) haven’t figured out how to adjust the boxes so I can compare them with Intersects(). I tried creating a new bounding box that was adjusted by the model’s position, but that didn’t work…

  6. Ignore my last newbie post… The problem was that I had scaled some of my models using SetScaling(). When I scale all models to 100%, Intersects() works great. Now to figure out how to deal with the scaling…

  7. I’m still having problems. Does the bounding box change after each render? I would think it must if the object is moving, since at render time its the only time it knows the model location, right? It’s always telling me my two models are coliding when they aren’t. I have one in a static position on the screen and another I can move side to side with the control stick. Pretty much everywhere it tells me its a collision. I’m not getting any errors, it compiled clean and I made the changes to the Content Processor. I’ve tried using the tag boundingblock on load and after render, and the intersect always returns true. Any suggestions?

  8. I think I see whats going on.

    The bounding box is relative to position 0,0,0 and is also relative to the inital size of the model when its loaded.

    I’m using a scale matrix to resize the model before it’s rendered

    the bounding box doesn’t seem to adjust the box to the new location (at render time) and scale.

    Is there a way to cottect this?

  9. For what its worth I got it resolved. I learned two things:
    1. after creating the bounding box at load time, save off the min and max values. That’s all you need, you can get rid of the bounding box (or not)

    then at render time, add the position values to the min and max values, and use the new min and max values to create a temporary new bound box to use for collision detection during this frame.

    repeat the process each frame

    2. I was using a framework from the XNA Game Programming book and the framework resized the model on load, but after the bound box was calculated, so they weren’t matching. I had to remove that code from the load routine and use a normal scaling matrix.

    3. I almost forgot, if you are scaling the model with a scaling matrix, make sure you multily the scale value against the min and max values so your bounding box is correctly scaled.

  10. I’m still confused. I have a model of a building and I’m trying to keep my character from going through the walls. I think I need a boundingbox for every mesh in the building to properly check for collision. Maybe I can take this code and store that information in something to check.

    Anyone have any insight?

  11. Hi everybody,

    first of all i would like to thank you ANDY so much.

    I worked perfectly to my solution.

    If are you or anybody interested into creating an XNA engine for 3D games … i am already preparing my world with collision for boundingspheres and now for boundingboxes in XNA version 3.0 .

    Feel free to contact or add me by MSN:

    Bye bye ! Now I can go to sleep … i was wondering not passing another night awaken with more headaches 🙂

Leave a Reply