Get the latest Education e-news
 

Go Back   Game Career Guide Forums > Programming
Forum Home Register Members List Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-17-2009, 07:07 PM   #1
brainydexter
Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss77
Location: N. America
Default 3d bounding boxes of a model not displaying properly

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
__________________
Twitter ~ Blog
brainydexter is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 08:22 PM.






UBM Tech