PDA

View Full Version : BoundBox



alucard
02-10-2004, 06:08 AM
Hi.

Iīm having problens to update the BoundBox of my models.

When I translate the model, ou rotate the BoundBox donīt are update. I have all the transformation of the model in 3 matrices translate, rotate and scale. And multiply then by MODEL_VIEW before rendering.

But how i will do this with my BB ??
I need to have a copy of the original BB, to make transformations, and I donīt want to do this all frames, only when the model are updated!

How could I do this fast ???

Thanks..

delbass
02-15-2004, 03:54 PM
Well, if you are using axis aligned bounding box, coded as min/max point, transform all box corners by the model transformation and find the new min and max. (if you code the BB by center/extents, it works exactly the same, you just have some extra works)
Here a piece of code i wrote as an exemple :

AABB AABB::TransformBy(const Matrix4& mat)
{
Vec3 min, max;
Vec3 v[8];
int i;

for (i = 0; i < 8; i++) {
v[i] = mat * GetCorner(i, v[i]);
}
min = max = v[0];
for (i = 1; i < 8; i++) {
if (v[i].x < min.x) min.x = v[i].x;
else if (v[i].x > max.x) max.x = v[i].x;
if (v[i].y < min.y) min.y = v[i].y;
else if (v[i].y > max.y) max.y = v[i].y;
if (v[i].z < min.z) min.z = v[i].z;
else if (v[i].x > max.x) max.z = v[i].z;
}
return AABB(min,max);
}

[edit]

oh i forgot, if you want the bounding box to be aligned with world axis, the matrix should be the local->world matrix, and the original bounding box should be in local space (computed directly from vertices) (By the way why use 3 matrices ?)


[This message has been edited by delbass (edited 02-15-2004).]

[This message has been edited by delbass (edited 02-15-2004).]