Get the latest Education e-news

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

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

Activity Longevity
0/20 17/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:

foreach (ModelMesh mesh in Model.Meshes)
Updating BoundingSphere dictionary:
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:
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) *
transforms[index] * Matrix.CreateTranslation(Position);   
Now, this works fine! Instead if I un-comment the Matrix.CreateTranslation(..)
and comment the manual translation done via
transforms[index] * Matrix.CreateTranslation(Position);
The spheres are not the same. They are bigger in radius when I use the 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.

Twitter ~ Blog
brainydexter is offline   Reply With Quote

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 - 2016, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 04:14 PM.

UBM Tech