• ### Announcements

#### Archived

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

# Problem with z-axis

## Recommended Posts

Hi, Trying to learn OpenGL Programming... but i am having problems. My neg z-axis is "pointing towards me" when it should be "going into the screen". This is contrary to all documentation i could find. Is it normal, or is there something screwed up?

##### Share on other sites
That''s not a problem, it depends how you set your coordinate system. In my engine, y points towards the screen.

##### Share on other sites
How do you set it? I new to opengl, so i''m just following along what the book does... and it doesnt seem to set one.

##### Share on other sites
If your negative z axis is towards you, is the positive x axis to the left or to the right? I suspect to the left unless you are doing some funny kind of glScale(-1,1,1) or glScale(1,1,-1)

##### Share on other sites
Quote from my code:
text_coord_pointer[ i ].v=1.0f-(float)file_text_coord_pointer[ i ].v/(float)file_header.skinHeight;

 God damn forum software, it converts [ i ] in < i >

[edited by - Raduprv on May 19, 2004 3:48:09 AM]

##### Share on other sites
Thats the funny thing... my positive X and Y axis are fine (positive x points to the left, and positive Y points upwards).. they are exactly like in my books and all that... its just my z axis that differs.

Here is an example, take this section of code:

glBegin(GL_LINES);
glColor4f(0.0f,1.0f,0.0f,1.0f);
glVertex3f(0.5f,0.5f,0.5f);
glColor4f(1.0f,0.0f,1.0f,1.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glEnd();

Now, if the Z-axis is pointing towards me like like it should, the line would go from forward top right to back bottom left. But, when i compile, my line goes from back top right to forward bottom left. I dont have any code that alters the coord system.. this is your basic opengl app.. bareboned.

[edited by - Chrysaor on May 19, 2004 4:21:23 AM]

##### Share on other sites
Oops, damn, I am so tired, I posted a reply on the wrong thread (that was supposed to go on a thread where someone had a problem with an MD2 skin). Sorry.
Like FReY said, toy with glScale (try 1 or -1 for the values, other valeus for some fun) until you find the orientation you want.

##### Share on other sites
Did you position the camera properly? Did you rotate it?

##### Share on other sites
OpenGL uses a right handed (sometimes referred to as positively oriented) coordinate system. This means that if u, v and w are the coordinate system axes, u cross v = w. Or in other words, the positive x-axis points to the *right*, the positive y-axis up and the positive z-axis *out* of the screen.

If your positive x-axis points to the right, something is wrong. Beware that many 3d mesh file formats use a left handed coordinate system and so does D3D, so if you get weird results it might be because you''re reading in a file with a left handed coordinate system or using code from a tutorial that''s been ported from D3D.

##### Share on other sites
quote:
Original post by Chrysaor
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);

Now, if the Z-axis is pointing towards me like like it should, the line would go from forward top right to back bottom left.

meep. wrong. positive z is towards you and negative away from you.

quote:
But, when i compile, my line goes from back top right to forward bottom left.

just like its supposed to be. if you dont like that you can set the projection matrix yourself to have positive z going into the screen (which i usually do, because i find right/up/forward intuitive while right/up/backwards is just.. backwards)

##### Share on other sites
To Trienco:

I dont see how the positive z axis could be towards me. I drew a quad before the line (see above code of the vertex of the line) at the depth of 0.5f. Now, if the positive z-axis is towards me, the line shouldnt be visible, right? well.. the line appears in front of the quad. So the positive z-axis is pointing away from me.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627654
• Total Posts
2978450

• 10
• 12
• 22
• 13
• 33