Skip to main content
GameDev.net gamedev.net
🔒 Locked

A D3DXMatrixLookAtLH World Matrix

Started by jbizzler Jun 27, 2007 at 2:15 PM 9 replies 1.9k views
Original Post
jbizzler
jbizzler
Is there any way to use the pos, forward, up system of D3DXMatrixLookAtLH, but for world transformations? I want to be able to control my meshs' orientations with those three variables, but D3DXMatrixLookAtLH doesn't quite do the trick.
jollyjeffers
jollyjeffers
I doubt you could get it to work via the D3DX functions. Chances are you'd just end up writing a whole new matrix "type" that isn't any easier for having D3DX to help...

Have you looked into D3DXMatrixRotationYawPitchRoll()? It's pretty good at representing these sorts of situations.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
jbizzler
jbizzler
I used to, but I found it extremely limiting. All the rotations it does are based on the existing axes. With forward and up, I can make all rotation local, and based on axes should I choose.

I have all sorts of ideas in my head of how I could do this, but they get really computationally complex. I cna't help but think there's a right way to do this.
Gyna
Gyna
for rotations around a custom axis:

D3DXMATRIX* D3DXMatrixRotationAxis( D3DXMATRIX* pOut, CONST D3DVECTOR3* pV, FLOAT Angle )

is this what you were looking for?

[Edited by - Gyna on June 27, 2007 4:44:37 PM]
jbizzler
jbizzler
Well, I made a completely ridiculous function for doing this. If you tell me the code tabs for this forum, this will look much nicer.

Edit: I used ot have the code here but I now know IT DOESN'T WORK AT ALL!
Gyna, I'm not so much trying to rotate around an axis as I am trying to rotate to an axis.
mittens
mittens
What are you trying to accomplish, exactly? It's best to use things like D3DXMatrixLookAtLH for a sort of camera eye functionality rather than as a way to transform a certain model in world space.

But I'm confused as to why D3DXMatrixRotationYawPitchRoll won't get the job done for you.
jbizzler
jbizzler
Because yaw, pitch, and roll are relative to y, x, and z axes. It's great if your somewhere where there's always an up and a down, but what if your in space. Using a forward and up system is just mroe flexible. I guess it's not worth it if it's this complex. I have a function that works in some cases, but not in others.

Say you have a spaceship, flying along the y axis. Roll will obviously not make the spaceship roll, but rather, move the nose of the spaceship away from the y axis. But, in a forward up system, you simply rotate the up vector around the forward vector to roll the spaceship.

Just an example. I'm not necessarily make a space sim, just something as flexible as possible.
uavfun
uavfun
Option 1:
Use quaternions. They don't suffer the same issues as yaw/pitch/roll-based rotations. D3DX has all you need.

Option 2:

Store a 3x3 rotation matrix. The first row/column (I forget which way around it is in D3D) will be your X/side vector, the next your Y/up vector, then finally your Z/forwards. Then you can compound rotations to your heart's content simply by matrix multiplication (and possibly periodically reorthonormalizing the matrix so that all the directions stay parallel.)

The easiest way to construct that kind of matrix from a direction and (approximate) up vector is to take their cross product for the left/right vector, then take the cross product of that vector and the direction to get an up vector that's exactly perpendicular to the direction, then stick them all in a matrix (this is how LookAt-style camera functions generally work)
jbizzler
jbizzler
YES! Thank you. This is exactly what I needed! I knew quaterions were an option, but I really don't know how to use them. the 3x3 matrix sound simplest. I'm actuallt turnign in for the night. I'll test it tomorrow morning.
jbizzler
jbizzler
Okay, it works, except all the faces are reversed.

Edit: YES! It works. I just had my cross products reversed. Thank you so much! It's funny, we all use these matricies, but it took this long for someone to come along who can actually manipulate them without other functions.

[Edited by - jbizzler on June 27, 2007 11:45:53 PM]
bibiskuk
bibiskuk
Another simple way, if I'm right, is just to inverse the ViewMatrix, to have the equivalent WorldMatrix.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.