# Left-Handed LookAt

This topic is 3973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In XNA, there is no LookATLH function. By default, XNA is right handed. I've been trying to code my own left handed function but I haven't been getting the proper results. Lets just say the camera is at the origin (0,0,0) and its looking down the positive x-axis (1,0,0) That means the camera has not been rotated. All angles are 0. Basically, i want the +Z-axis to be the left and the +Y-axis to be up. I've been getting either to be flipped in in positive or negative, so +Y is down and Z+ is right, which is incorrect. Does anyone know how to setup a LookATLH Matrix manually? Is there a way i can do this using quaternions? Thanks.

##### Share on other sites
Wasn't this somewhere in the DirectX SDK docs?

Anyway, this replacement seemed to work fine for me:

LookAtLH( const vector3& position,          const vector3& target,	  const vector3& upVector ){  // geprüft  vector3 zaxis = target - position;  zaxis.normalize();  vector3 xaxis = upVector.cross( zaxis );  xaxis.normalize();   vector3 yaxis = zaxis.cross( xaxis );  m[0][0] = xaxis.x;  m[0][1] = yaxis.x;  m[0][2] = zaxis.x;  m[0][3] = 0;        m[1][0] = xaxis.y;  m[1][1] = yaxis.y;  m[1][2] = zaxis.y;  m[1][3] = 0;        m[2][0] = xaxis.z;  m[2][1] = yaxis.z;  m[2][2] = zaxis.z;  m[2][3] = 0;        m[3][0] = -xaxis.dot( position );  m[3][1] = -yaxis.dot( position );  m[3][2] = -zaxis.dot( position );  m[3][3] = 1.0f;}

##### Share on other sites
Instead of making the look direction (1,0,0), make it (0,0,1).

Thus, positive Z is forward, positive Y is up, and positive X is to the right. To my knowledge, this is standard. It's even where the term "Z buffer" comes from. Meaning the depth buffer represents how far forward from you in the Z direction a pixel is.

I haven't found I've had to change my thinking or do any hacks like this since switching from direct3d to xna. If anything, it always annoyed me greatly that direct3d uses left handed matrices, and it's nice to be using right handed ones.

##### Share on other sites
gharen2: Oddly enough, when I use Matrix.CreateLookAt(), if I set the look to (0,0,1), positive X still goes to the left. Essentially what I'm getting is horizontally a flipped image.

##### Share on other sites
haha, actually, I was mistaken, positive X is to the left.

##### Share on other sites
Is there a way to flip it? I know you can flip the signs of any column of a matrix to have the objects flip, but how can you accomplish this with the camera position as well?

##### Share on other sites
The calculation of a look-at matrix is not specific to a left-handed or right-handed coordinate system.

##### Share on other sites
Well, i figured it out. I also had to calculate the perspective matrix in LH as well. In any case i found the formula here:

http://msdn2.microsoft.com/en-us/library/bb281727.aspx

Endurion also posted the correct formula for the view matrix above.

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013761
×