Object bounding box question
by Stephen Zepp · in Torque Game Engine · 11/23/2004 (5:14 pm) · 1 replies
I'm trying to figure out how to properly project a building (.dts) procedurally so that regardless of how the artist set the origin (or more importantly, x-z plane) in the model, the "bottom" of the model is always at/near the terrain beneath it.
For reference, I have several models that appear to be centered on their origin. When you first place them in a scene, half of the object goes underground. You can easily use your eye and the mouse to adjust the Z axis coordinate of the object's center so that it sits on the terrain, but I want to be able to do it procedurally.
Is there a good technique for this that someone already knows?
If not, is there a decent way to calculate the max "extent" from the origin of an object in a particular axis direction, so you can auto-calculate a transform to move the object properly (given it being centered on the origin)?
Based on my (limited for sure) understanding of the code, the objects have a bounding box, and those can be modified procedurally, but I'm lost when it comes to how to figure out what to set it to.
Any thoughts?
For reference, I have several models that appear to be centered on their origin. When you first place them in a scene, half of the object goes underground. You can easily use your eye and the mouse to adjust the Z axis coordinate of the object's center so that it sits on the terrain, but I want to be able to do it procedurally.
Is there a good technique for this that someone already knows?
If not, is there a decent way to calculate the max "extent" from the origin of an object in a particular axis direction, so you can auto-calculate a transform to move the object properly (given it being centered on the origin)?
Based on my (limited for sure) understanding of the code, the objects have a bounding box, and those can be modified procedurally, but I'm lost when it comes to how to figure out what to set it to.
Any thoughts?
Torque 3D Owner Drew Parker
This returns world coords. I think 2 is the right word, you might want to dump the whole thing out to the console to make sure. Basically, the world box is just a box around the object box. So regardless where the model center is, the world box will cap the bottom of the model. However, if the object rotates, the world box will get bigger, so you have to watch out. Try turning on the collision bounds to check it out, I think you can do that like so:
This is probably more simple then what you are looking for, but if your requirements are really simple, it might do the trick...
Here is an example on how I typically use it. I'm sure there are better ways, if anyone has some please chime in :)