My Y-axis is inverted .. why?

Started by
5 comments, last by tonysameh 14 years, 5 months ago
The +ve Y-axis should point upwards, right? I used the following code to draw the 3 axes. Each of them has a small part in the negative direction and a longer part in the positive direction. glBegin(GL_LINES); glColor3f(1,0,0); glVertex3d(-10,0,0); glVertex3d(100,0,0); glColor3f(0,1,0); glVertex3d(0,-10,0); glVertex3d(0,100,0); glColor3f(0,0,1); glVertex3d(0,0,-10); glVertex3d(0,0,100); glEnd(); The output was something like that: __|__________ ...| ...| ...| ...| ...| <Don't care about the dots. I only put them because spaces are removed in the threads> That means that the +ve Y axis looks downwards, while the X and Z axes are as expected. Did I make any wrong assumptions?
Advertisement
right hand rule: x-y-z, y-z-x, z-x-y always in CCW order on your right hand, and
the 3 axises are pointing out of the screen.

     y     |     |     |     |     o-------- x    /   /  /z

BTW use code tags for character drawings (or whatever they're called).
How did you set up your view volume? Y+ doesn't have to be in the vertical direction if you didn't set it as such. In fact it is fairly common for the upper left corner to be the point (0,0) with down being positive(If I remember correctly that is the default for Java) When you say x and z are as expected what is expected?
Like stonemetal said, you need to show how you set up your view volume. Did you set up an Ortho view or Perspective? Do you do any rotations, translations, scaling, before drawing the lines?
Here's my complete code
<code>

void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3d(-10,0,0);
glVertex3d(100,0,0);
glColor3f(0,1,0);
glVertex3d(0,-10,0);
glVertex3d(0,100,0);
glColor3f(0,0,1);
glVertex3d(0,0,-10);
glVertex3d(0,0,100);
glEnd();
glutSwapBuffers();
}


// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
}




void ChangeSize(int w, int h)
{

GLfloat nRange = 100.0f;

// Prevent a divide by zero
if(h == 0)
h = 1;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);


// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, nRange*h/w, -nRange*h/w, -nRange*2.0f, nRange*2.0f);
else
glOrtho (-nRange*w/h, nRange*w/h, nRange, -nRange, -nRange*2.0f, nRange*2.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL Atom");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();

return 0;
}
</code>
First, there are different conventions for which direction the +y axis points, so it can't really be said that it 'should' point one way or the other. Second, it looks like you have your orthographic projection set up so that +y will point down, so it shouldn't come as too much of a surprise that it doesn't point up (try flipping the signs of the 3rd and 4th arguments to glOrtho() and see what effect that has).

Also, [source][/source] are the tags you're looking for (you can also use 'pre' tags for small bits of code).
Original post by jyk
First, there are different conventions for which direction the +y axis points, so it can't really be said that it 'should' point one way or the other. Second, it looks like you have your orthographic projection set up so that +y will point down, so it shouldn't come as too much of a surprise that it doesn't point up (try flipping the signs of the 3rd and 4th arguments to glOrtho() and see what effect that has).

Also,
are the tags you're looking for (you can also use 'pre' tags for small bits of code).

Yes I got it.
I got everything, the glOrtho parameters, the source tag and the pre tag.
Thanks a lot

This topic is closed to new replies.

Advertisement