View Full Version : Bounding box problem:

03-01-2002, 01:18 PM
I have a great AABB system up and and working in my opengl engine. Im loading animated milkshape s as both levels and characters. (sweeeeeeet....)
However, when i go to scan the vertices (400 or so) for the max's and min's i get

max: 6, 7, 25
(rounded up)

when milshape tells me:
max: 15, 35, 13
min:-15,-40, -9

gah!!?? why??
this is my code:

Max[0] = Max[1] = Max[2] = 0.0f;
Min[0] = Min[1] = Min[2] = 0.0f;

for (int pnt = 0; pnt < Mod->m_numVertices; pnt++)
if (Mod->m_pVertices[pnt].m_location[0] > Max[0])
{Max[0] = Mod->m_pVertices[pnt].m_location[0]; }

if (Mod->m_pVertices[pnt].m_location[0] < Min[0])
{Min[0] = Mod->m_pVertices[pnt].m_location[0]; }

if (Mod->m_pVertices[pnt].m_location[1] > Max[1])
{Max[1] = Mod->m_pVertices[pnt].m_location[1]; }

if (Mod->m_pVertices[pnt].m_location[1] < Min[1])
{Min[1] = Mod->m_pVertices[pnt].m_location[1]; }

if (Mod->m_pVertices[pnt].m_location[2] > Max[2])
{Max[2] = Mod->m_pVertices[pnt].m_location[2]; }

if (Mod->m_pVertices[pnt].m_location[2] < Min[2])
{Min[2] = Mod->m_pVertices[pnt].m_location[2]; }


any ideas?


03-01-2002, 05:21 PM
I don't see a problem in the code that would cause your problem, but in general your method is a bit wrong, or rather, has the potential of producing incorrect results. You should initialize the min and max with the first vertex rather than (0,0,0), as there is always the possibility of (0,0,0) being outside the AABB.

03-02-2002, 12:19 PM
i tried this:

Max[0] = Mod->m_pVertices[0].m_location[0];
Max[1] = Mod->m_pVertices[0].m_location[1];
Max[2] = Mod->m_pVertices[0].m_location[2];

Min[0] = Mod->m_pVertices[0].m_location[0];
Min[1] = Mod->m_pVertices[0].m_location[1];
Min[2] = Mod->m_pVertices[0].m_location[2];

with the same results....

any ideas?

03-02-2002, 02:40 PM
The problem that fixes is not the problem you are having, as in this case (0,0,0) is in the AABB. I was merely pointing out that if the you had a AABB which did not contain (0,0,0), then your method would fail. Again, the problem you are describing is not the same problem I was pointing out.

03-03-2002, 08:33 AM
Min[0] = Mod->m_pVertices[0].m_location[0];

Try casting Mod->m_pVertices[0].m_location[0]; as whatever type Min[0] is when you're setting m_location[i] to Min/Max[i]. If they are different data types you may have bad bits or you may be overwriteing the next location in memory.

if Min[0] is an int, try

Min[0] = int(Mod->m_pVertices[0].m_location[0]);

if Min[0] is a float, try

Min[0] = float(Mod->m_pVertices[0].m_location[0]);

or better yet, make sure Min[0] is the same data type as Mod->m_pVertices[].m_location[]

03-03-2002, 01:12 PM
Nope, it just turns out that
Milkshape stored the vetices
in their pre-transformed state :P

(garbled up the torso object, hands
had been mirrored...)

I hacked it to apply the bones when
checking the bounding box volume, and
it works just fine!! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Thanx anyhow