#### Archived

This topic is now archived and is closed to further replies.

# Inverted z-axis ????

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

## Recommended Posts

Ok I have been doing some playing around and I'm very confused now! I thought that the positive Z direction was *into* the screen, positive x was to the left, and positive y was up. However, the following code

glVertex3f( 2.0f, -2.0f, 4.0f );
glVertex3f( -2.0f, -2.0f, 4.0f );
glVertex3f( -2.0f, 2.0f, 4.0f );
glVertex3f( 2.0f, 2.0f, 4.0f );
glEnd();


Draws this quad behind the viewer! Its as if the positive Z direction is out of the screen. Is that right? Putting a negative on the 4.0f for z coordinate results in the quad being drawn in front of the viewer... I never set a camera or anything this is the only drawing code. Doesn't this mess up cross products and worse? Now x cross y is -z... arg... [edited by - aargyle on May 4, 2003 1:37:37 PM]

##### Share on other sites
OpenGL use this convention:

x left -> right
y bottom -> top (inverse of classic 2D coordinate)
z far -> near

that is positive Z direction is out of the screen

To draw something in front of the viewer you should translate along negative z direction and look in the screen (neg z) and not behind !

And this respects the relation z = x ^ y (''right hand rule'')

However you can change the convention by scale by negative values (-1,-1,+1) -> x right->left, y top->bottom

##### Share on other sites
Ok that clears up a lot, I could have sworn I read that the axes were different, I guess I was smoking something.

Now, as another question, in all the camera tutorials I've found they take care to invert the z-axis in their matrix or quaternion calculations, why do they do this if it already respects x cross y = z?

(edit: oh I guess thats what you meant at the end.)
Dangit now my rotations are all backwards, lol.

[edited by - aargyle on May 4, 2003 2:13:40 PM]

##### Share on other sites
Hmm, I''m not sure if I have this backwards or not, but doesn''t OpenGL use the right handed system? I think that means -Z is into the screen...

##### Share on other sites
Wait a minute this screws up all my rotations. If a rotation of 0 degrees has you facing -z, then everything is messed up! The angles are measured from a negative axis! Arg....

How do you fix this with quaternions? As it is right now all my rotations are backwards (I pitch down when I should be pitching up, etc). For example, when I load up the program I am facing (0,0,-1), with no rotation in my quaternion. When I press forward, I am dutifully moved to (0,0,1). But, this has the effect of apparently moving me backwards, because all translational math assumes positive axes are 0 degrees and negative axes are 180 degrees! Evil GL lol.

[edited by - aargyle on May 4, 2003 2:48:38 PM]

##### Share on other sites
Ok it turns out this is worse than I thought.
Only the camera starts out at 180 degree yaw with no rotation, all the other objects in the world start out facing the correct direction. This is giving me crazy problems when I try to make the camera follow an object, because the camera is always 180 degrees away from where other objects are. Grrr!

##### Share on other sites
Sorry...!!!

I gave you wrong indications!

Z and Y OK (Z: far->near and Y:bottom->top)

X goes from right to left

That is ''left-hand'' rule... Z = - X ^ Y

quote:
Original post by Aargyle
Now, as another question, in all the camera tutorials I''ve found they take care to invert the z-axis in their matrix or quaternion calculations, why do they do this if it already respects x cross y = z?

I''ve posted some time ago a reply with my code on a camera matrix.

http://www.gamedev.net/community/forums/topic.asp?whichpage=1&pagesize=20&topic_id=153283

  matrix.LoadIdentity();vector3 side = look^up;   matrix.SetCol(0, -side	 );  matrix.SetCol(1,  up	 );  matrix.SetCol(2, -look	 );  matrix.SetRow(3, -(matrix*pos) );

As you can see I''ve computed side = look^up.
Suppose that the viewer is in pos=0 and it''s looking into the screen (Z<0) -> you should have an identity matrix.
In fact if we let look = -Z -> side = (-Z)^Y = - (Z^Y) = -x
but in the matrix I use inverted sign so I get the identity...

However I think that a different sign in angle should not be a problem!

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633702
• Total Posts
3013447
×