View Full Version : 3D rotations n stuff
techbear
10-25-2007, 07:18 PM
I want to draw a roof rack on my car (in my 3D race game). Normally, I'd take the xyz offset of the roof, and rotate it with 3 matrixes, for the yaw, pitch, and roll of my car.
However, I don't HAVE the yaw, pitch, and roll. I'm using a "jelly box", eight points connected by springs. What can I do?
Should I "unwind" the box, to find it's yaw, pitch, and roll? Or should I do something sneaky with quaternions?
Thanks!
Bombinator
10-25-2007, 07:50 PM
Given my limited understanding of your situation you should keep in mind that I may be way off here. What I would do is find a plane that passes through say the two top, rear points of your "jelly box" and say a point at the center of the top four points and place the rack on that plane (or at a certain offset from it). Make any sense?
Maybe ascii art will help, looking down from the top:
O---O
|\ /|
| X |
|/ \|
X---X
I'd use the plane going through the three X points to place the rack. It seems as if there must be a simpler way though. Anyone else have any thoughts?
techbear
10-25-2007, 08:16 PM
No, no, I already understand that part. I'm doing just as you say, using three points of the top of the car to find a plane.
The question is, how do I derive a rotation matrix from that 3D plane? In going back over my notes, it seems that if I have an up, left, and front vector for my car (which I have), I can use those to make a matrix that correctly orients my roof rack. But how, exactly?
techbear
10-25-2007, 08:30 PM
FIXED!
The answer is to get a forward vector, and an up vector, and get a "look at" matrix. THEN, you have to take the inverse, and use that to orient your roof rack.
The Direct3D 8 code is:
D3DXMatrixLookAtLH( &matOrientation, &position, &frontVec, &upVec);
D3DXMatrixInverse( &matOrientation, NULL, &matOrientation );
Bombinator
10-25-2007, 09:02 PM
Ah, I completely misunderstood your question. Glad you figured it out.
FIXED!
The answer is to get a forward vector, and an up vector, and get a "look at" matrix. THEN, you have to take the inverse, and use that to orient your roof rack.
The Direct3D 8 code is:
D3DXMatrixLookAtLH( &matOrientation, &position, &frontVec, &upVec);
D3DXMatrixInverse( &matOrientation, NULL, &matOrientation );
Little late to the party, but yeah this is what you want.
An easy way to grok this concept is to remember that an at/up/eye rotation matrix is basically just a transform from one coordinate system to another, with the orthogonal vectors forming the basis for that coordinate system.
Applewood
10-27-2007, 04:23 AM
Avoiding all the math-speak and pedantry that always creeps into these explanations...
Think of a matrix as a remapping table consisting of 3 vectors. The top vector maps local X direction to world-space X direction. Next one does Y, bottom one does Z.
An identity matrix looks like this:
1,0,0
0,1,0
0,0,1
You can see that the topmost vector (x) says "all of X, none of Y and none of Z" which means the x direction in local space will point in the x direction in world space.
0,0,1
0,1,0
1,0,0
The above matrix maps the local X to be pointing down the worldspace Z axis. And local Z (third row, the object's forward direction) into worldspace X, meaning it's turned right 90 degrees.
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.