Corner Points of Bounding Box ?
by Dante Falcone · in Torque Game Engine · 01/10/2009 (10:14 am) · 11 replies
I'm currently developing an obstacle avoidance system that requires the Points of each corner of a SceneObject's bounding box. I'm running into trouble because of the way the boxes are stored with Point and Extent. I cannot figure out how to get each corner point of the bounding box in world space. Any help would be awesome.
About the author
I am a Producer in the Video Game industry and specialize in MMO development, Character Art->Game pipelines, and general support programming.
#2
01/11/2009 (10:07 am)
Get the corners in object space,then mul with mRenderObjToWorldto get transform into world space.
#3
@Picasso, thanks for the advice with mRenderObjToWorld. I will look into this. The only thing I'm still worried about is how I will get the new points I created transformed to world space with this because the are not part of the mesh. I may just be worrying too much.
Thanks again guys.
01/11/2009 (12:22 pm)
@Daniel, I'm not sure I understand your question. Torque provides you with 3 calls to getting a bounding box, an object space box, a world space box, and a render box. The boxes are made from 2 points, called 'point' and 'extent'. I've tried to deduce the corners by doing the math, but you still can't get correct world space results that account for object rotation. You are also provided with a method to get the center point, but I havn't used it on account of the World Space Transform problem.@Picasso, thanks for the advice with mRenderObjToWorld. I will look into this. The only thing I'm still worried about is how I will get the new points I created transformed to world space with this because the are not part of the mesh. I may just be worrying too much.
Thanks again guys.
#4
01/11/2009 (1:59 pm)
I hope you share the code when you finish. It would be very useful to many people.
#5
So, the mRenderObjToWorld is the transform matrix. So, if I remember my matrix math, I think I need to multiply the object space points by this matrix to get their world space points.
So, step 1, figure out the corner points in local space. Step 2, multiply these points by the mRenderObjToWorld matrix.
Will try this now and post in a bit.
01/11/2009 (5:05 pm)
@Tyler, definitely will do.So, the mRenderObjToWorld is the transform matrix. So, if I remember my matrix math, I think I need to multiply the object space points by this matrix to get their world space points.
So, step 1, figure out the corner points in local space. Step 2, multiply these points by the mRenderObjToWorld matrix.
Will try this now and post in a bit.
#6
The transformed positions are not at the corners of the object's bounding box, but are instead scaled down as if the object were small.
01/11/2009 (11:20 pm)
I feel like I'm close but still have not gotten this to work right. Here's what I'm doing:MatrixF worldTransform = sceneObj->getRenderTransform(); //mRenderObjToWorld transform Box3F targetBox = sceneObj->getObjBox(); //Bounding Box in Object Space //FIGURE OUT CORNER POINTS IN OBJECT SPACE Point3F p0(box.min.x, box.min.y, 0); Point3F p1(box.max.x, box.min.y, 0); Point3F p2(box.max.x, box.max.y, 0); Point3F p3(box.min.x, box.max.y, 0); //CREATE MATRICES FROM POINTS MatrixF m0(EulerF(0,0,0), p0); MatrixF m1(EulerF(0,0,0), p1); MatrixF m2(EulerF(0,0,0), p2); MatrixF m3(EulerF(0,0,0), p3); //TRANSFORM POINTS TO WORLD SPACE m0.mul(worldTransform); m1.mul(worldTransform); m2.mul(worldTransform); m3.mul(worldTransform); //STORE THE TRANSFORMED POSITIONS m0.getColumn(3, &p0); m1.getColumn(3, &p1); m2.getColumn(3, &p2); m3.getColumn(3, &p3);
The transformed positions are not at the corners of the object's bounding box, but are instead scaled down as if the object were small.
#7
The min is '0' - yes it is a projection on XY, but not the maximum.
I think you should use the native box.max.z and box.min.z,or it is dangerous to lose accurasy on scale factor (if scaled later) of the transform operation.
Also check your way on use the sceneObj pointer.When upcasted it is safe,but downcasts can be wrong. I use the SimObj smart pointer on my way for such ideas.
01/12/2009 (8:27 am)
In object space i am not sure the 3th coord is '0' for the max extreme point.The min is '0' - yes it is a projection on XY, but not the maximum.
I think you should use the native box.max.z and box.min.z,or it is dangerous to lose accurasy on scale factor (if scaled later) of the transform operation.
Also check your way on use the sceneObj pointer.When upcasted it is safe,but downcasts can be wrong. I use the SimObj smart pointer on my way for such ideas.
#8
I just substituted sceneObj in for the scene object I'm using here. So no worries on casting, this is being done in the Scene Object class anyway.
I put 0 on the Z because I only care about the X and Y. So, I'm saying all points have the correct X and Y and a height of 0. How does this affect scale of XY when these are only local space points?
01/12/2009 (8:38 am)
@PicassoI just substituted sceneObj in for the scene object I'm using here. So no worries on casting, this is being done in the Scene Object class anyway.
I put 0 on the Z because I only care about the X and Y. So, I'm saying all points have the correct X and Y and a height of 0. How does this affect scale of XY when these are only local space points?
#9
When transformed to world space,you have the projected "small" XY maximum of the box.
When regenerated the box from min-max,there will be a small scaled box.
scale_factor = old (min.max).len() / new (min.max).len()
I think the right decision on this problem is to transform the center of the box from object to world.
Then you can easily regenerate the min-max coords from center away.
The player mObjBox is centered the same way in player class.
01/12/2009 (10:04 am)
You care about XY,but the box is created via XYZ.When you project (min,max) line in XYobject,you got the new line in XYobject that is scaled.The right angle keeps the largest line (Pythagoras rule).That's why it is scaled.You only need a mul factor to make the box "large".When transformed to world space,you have the projected "small" XY maximum of the box.
When regenerated the box from min-max,there will be a small scaled box.
scale_factor = old (min.max).len() / new (min.max).len()
I think the right decision on this problem is to transform the center of the box from object to world.
Then you can easily regenerate the min-max coords from center away.
The player mObjBox is centered the same way in player class.
#10
Thanks for the help, but I'm not sure I really understand your last comment. Are you saying I need to scale the box up separately from just multiplying the transform matrix?
I also don't understand what you mean with the XYZ XYobject thing. If all points are changed so that Z is 0, then I'm just changing the 3d box to a height of 0, so that there are 4 points, each with an overlapping point. To then scale these points should scale XY and place the Z at the world center point height.
01/12/2009 (2:15 pm)
@PicassoThanks for the help, but I'm not sure I really understand your last comment. Are you saying I need to scale the box up separately from just multiplying the transform matrix?
I also don't understand what you mean with the XYZ XYobject thing. If all points are changed so that Z is 0, then I'm just changing the 3d box to a height of 0, so that there are 4 points, each with an overlapping point. To then scale these points should scale XY and place the Z at the world center point height.
#11
i haven't followed along closely,
but in general that is the case in TGE: the scale is stored in separate variables, not in the transform matrix. see SceneObject::mObjScale.
01/12/2009 (2:25 pm)
> Are you saying I need to scale the box up separately from just multiplying the transform matrix? i haven't followed along closely,
but in general that is the case in TGE: the scale is stored in separate variables, not in the transform matrix. see SceneObject::mObjScale.
Torque Owner Daniel Buckmaster
T3D Steering Committee