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.
This is using the Beta 2.
I guess I missed out a step (adding the new reference).
I’ve updated the original port to include my missed step.
Great stuff, thanks a lot! Been looking for this since XNA came out hehe 🙂
The code is working great… however I’m still having issues getting a Ray to intersect the bb to check if user clicked on an object (the quest for that has lead me here…)
That saga is here:
If nothing else, this code has simplified what was a major stumbling block when it came to getting a bb arond my own models.
Pingback: XNAtutorial.com » Weekly Update
sorry i dont understand. how can you build the dll by using that class?
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.
Pingback: Artificial-Studios.co.uk » Blog Archive » Picking and Bounding Boxes
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…
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…
never mind, I got my compile issue resolved.
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?
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?
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.
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?
Nice code, but for it to work with MeshContent parts that have been transformed within the model, v must be transformed by the matrix mc.AbsoluteTransform.
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 🙂
You must be logged in to post a comment.