Jump to content
  • Advertisement
Sign in to follow this  

3d bounding boxes of a model not displaying properly

This topic is 3320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to display the bounding box spheres for all the meshes in the model. I have them displaying, but for some reason(which obviously I don't know), they seem to be just out of place. Well, I'll put in my code first and then ramble. Loading the <int, BoundingSphere> dictionary: Code:
Model.CopyAbsoluteBoneTransformsTo(transforms); 

foreach (ModelMesh mesh in Model.Meshes)
{
   BoundingSphereDictionary.Add(mesh.ParentBone.Index,mesh.BoundingSphere);
}

Updating BoundingSphere dictionary: Code:
Dictionary<int, BoundingSphere> tempBSDictionary = new Dictionary<int, BoundingSphere>();

            foreach (int index in BoundingSphereDictionary.Keys)
            {
                BoundingSphere bs = BoundingSphereDictionary[index];

                Matrix transformation = transforms[index] * Matrix.CreateTranslation(Posn);
                bs.Center = Vector3.Transform(Vector3.Zero,transformation);
                
                tempBSDictionary.Add(index, bs);
            }
            BoundingSphereDictionary = tempBSDictionary;

What I am doing here is, transforming each sphere by the position in the world and further transforming by the internal transforms[parentbone.Index] And, the Draw Call: Code:
foreach (int index in BoundingSphereDictionary.Keys)
            {
                foreach (ModelMesh mesh in boundingSphereModel.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.View = view;
                        effect.Projection = projection;

 effect.World = 
Matrix.CreateScale(BoundingSphereDictionary[index].Radius) *
          //Matrix.CreateTranslation(BoundingSphereDictionary[index].Center);
transforms[index] * Matrix.CreateTranslation(Position);   
                            
                    }
                    mesh.Draw();
                }
            }

Now, this works fine! Instead if I un-comment the Matrix.CreateTranslation(..) and comment the manual translation done via Code:
transforms[index] * Matrix.CreateTranslation(Position);

The spheres are not the same. They are bigger in radius when I use the boundingSphere.center to translate the spheres than when I use the transforms[index] * ... I am essentially doing the same thing in update as well, but still I dont understand why is there, this discrepancy in the output ? Can somebody please help me out with this. Also, if you want me to upload the code, I can do that. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!