user2686299
user2686299

Reputation: 427

OpenGL. How to invert X axis?

Yo guys. I working on online game, and all unit's movement will be processing on server side. And for server debugging I have to integrate physics engine into OpenGL, or OpenGL into physics engine, actually I just want to visualize unit's and other objects on server side using OpenGL. But I faced with a problem. Inside game engine I have next axises orientationenter image description here

But in OpenGL world I see this orientation enter image description here

This code clearly explains it. I just drawed axises

gl.glBegin(gl.GL_QUADS);
//z
gl.glColor3f(0,0,1);
gl.glVertex3f(-width,0,length);
gl.glColor3f(0,0,1);
gl.glVertex3f(width,0,length);
gl.glColor3f(0,0,0);
gl.glVertex3f(width,0,-length);
gl.glColor3f(0,0,0);
gl.glVertex3f(-width,0,-length);

//x
gl.glColor3f(1,0,0);
gl.glVertex3f(length,0,-width);
gl.glColor3f(1,0,0);
gl.glVertex3f(length,0,width);
gl.glColor3f(0,0,0);
gl.glVertex3f(-length,0,width);
gl.glColor3f(0,0,0);
gl.glVertex3f(-length,0,-width);

//y
gl.glColor3f(0,1,0);
gl.glVertex3f(-width,length,0);
gl.glColor3f(0,1,0);
gl.glVertex3f(width,length,0);
gl.glColor3f(0,0,0);
gl.glVertex3f(width,-length,0);
gl.glColor3f(0,0,0);
gl.glVertex3f(-width,-length,0);
gl.glEnd();

So colorized parts of lines are in positive part of world, and dark part are in negative. Watch next image pls

enter image description here

Do you see it? Here is camera and point of interest position when I get that screenshot

Camara: (-18.778223, 26.576332, -77.65113)  
Point of interest: (-18.571165, 26.34204, -76.672806)

So how can I invert X axis?

Upvotes: 0

Views: 1907

Answers (1)

HolyBlackCat
HolyBlackCat

Reputation: 96236

I suppose your matrix-related code looks like this:

...
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Matrix calculations
...

Then, you can do this:

...
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glScalef(-1, 1, 1); // Each number represents scale for one axis
// Matrix calculations
...

Also you need to call glFrontFace(GL_CW); once after OpenGL initialization to compensate polygon winding direction inversion.


But I recommend you to not do that and invert Z axis in your engine instead.

It's easier when coordinate system in you engine is same as OpenGL one:

            +Y

          _______
         /  -Z   \
-X      /         \     +X
       /           \
      /     +Z      \
      """""""""""""""

            -Y

Upvotes: 4

Related Questions