Making a box from a transform
by Morrock · in Technical Issues · 06/18/2008 (7:36 pm) · 1 replies
Hi. I'm trying to make a Box's normals in code that is realigned based on a given "up vector." The thing is, I don't really know the math that would be needed to do this. Since, it's hard for me to explain this, example: a box is setup in code like:
I'd like to be able to use that to make normals for the sides of a box, but somehow transform them so the "up" for the box, is equal to the up vector, and the sides would have to turn to match. Example:
I'm good at 2d/3d math, and know all the terms so don't feel you need to explain things much. I just can't figure out how I would do this, and searching turns up no related results. Thanks!
Point3F BoxNormals[] = {
Point3F(-1, 0, 0),
Point3F( 1, 0, 0),
Point3F( 0,-1, 0),
Point3F( 0, 1, 0),
Point3F( 0, 0,-1),
Point3F( 0, 0, 1)
};I'd like to be able to use that to make normals for the sides of a box, but somehow transform them so the "up" for the box, is equal to the up vector, and the sides would have to turn to match. Example:
Point3F upVector = //however the upVector comes into this equation
Point3F BoxNormals[] = {
Point3F(x,y,z),
Point3F(x,y,z),
Point3F(x,y,z),
Point3F(x,y,z),
upVector, //These 2 are easy, since it's the top/bottom of the box
-upVector,
//etc...
};I'm good at 2d/3d math, and know all the terms so don't feel you need to explain things much. I just can't figure out how I would do this, and searching turns up no related results. Thanks!
About the author
Torque Owner Ivan Mandzhukov
Liman3D
The normal is only direction:
N(A,B,C)
Ax+By+Cz+?=0
The cube is a space, that can not be determined fast by planes.
A1x+B1y+C1z+?<=0 - TOP
A2x+B2y+C2z+?>=0 - BOTTOM
Yes that works, you limit the space from TOP and BOTTOM,but this is a very bad style of programming.
It will be better use of extreme points.
Look at how isContained is done.