Bounding box problem:

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
min:-6,-11,-6
(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-&gt;m_pVertices[pnt].m_location[0] &lt; Min[0])
	{Min[0] = Mod-&gt;m_pVertices[pnt].m_location[0]; }

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

if (Mod-&gt;m_pVertices[pnt].m_location[1] &lt; Min[1])
	{Min[1] = Mod-&gt;m_pVertices[pnt].m_location[1]; }

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

if (Mod-&gt;m_pVertices[pnt].m_location[2] &lt; Min[2])
	{Min[2] = Mod-&gt;m_pVertices[pnt].m_location[2]; }

}

any ideas?

-bobert

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.

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?
-bobert

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.

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[]

Nope, it just turns out that
Milkshape stored the vetices
in their pre-transformed state :stuck_out_tongue:

(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!!

Thanx anyhow
-bobert