OpenGl rotation/translation problems?

Moderator
Posts: 373
Joined: 2006.08
Post: #1
I've been having some problems with OpenGl not displaying textured objects the way I want it to Sad
Everything I'm doing is composed of texture-mapped quads that have straight sides, but for some reason when they're rendered the side are not perfectly straight. From what I can tell, these imperfections are always one pixel in difference from what they're supposed to be.
Here's a link to the app: http://www.wyrmmage.com/client.zip and its contents in zipped form. (if you download the app, you can press 'e' in the menu and right-click to resize the elements; press 'e' again to stop resizing). Click on multiplayer, then the top text to be taken to the cube/plane test...use w and s to zoom out/mouse to rotate (rotation is backward, sorry).
I've also taken some screenshots in case you don't download the app.
The below one is my main menu:
[Image: menu_small.png]
and another one with the object a bit larger (notice the top of the object is larger than the bottom for some reason)
[Image: menu_big.png]
then here's one of the cube and the plane; the plan should be parallell to the cube, but instead it's titled.
[Image: cube_plane.png]


here's the code for for drawing the menu:
Code:
glTranslated(theCamera.x, theCamera.y, theCamera.z);
glRotatef(theCamera.rotX, 1.0, 0.0, 0.0);
glRotatef(theCamera.rotY, 0.0, 1.0, 0.0);
glRotatef(theCamera.rotZ, 0.0, 0.0, 1.0);

(this->*funcDraw)(theNewTime);

glRotatef(theCamera.rotX, -1.0, 0.0, 0.0);
glRotatef(theCamera.rotY, 0.0, -1.0, 0.0);
glRotatef(theCamera.rotZ, 0.0, 0.0, -1.0);
glTranslated(-1*theCamera.x, -1*theCamera.y, -1*theCamera.z);

(this->*funcDraw)(theNewTime) draws a rectangle with points:
-0.925 0.275 0
0.645 0.275 0
0.645 0.565 0
-0.925 0.565 0
and texture coords
0 0
1 0
1 1
0 1
the camera x,y and rotX, rotY, rotZ are all 0, and camera z is set to 6 so that I can see my objects I'm drawing.

Then for the cube/plane I have the same code as above, but (this->*funcDraw)(theNewTime) draws the cube and then the plane, with points
-8 -8 8
8 -8 8
8 -8 -8
-8 -8 -8
and texture coords
0 0
1 0
1 1
0 1

also, here's my code to set up openGl:
Code:
glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);        // Turn Blending On
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                // Black Background
glClearDepth(1.0f);                                    // Depth Buffer Setup
glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
glDepthFunc(GL_LEQUAL);                                // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    // Really Nice Perspective Calculations
and when the window is resized:
Code:
width,height);                        // Reset The Current Viewport
    
windowX = (double)width;
windowY = (double)height;

glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
glLoadIdentity();                                    // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
glLoadIdentity();                                    // Reset The Modelview Matrix


Sorry for such a long post...I figured too much information was better than too little XD
Thanks in advance Grin
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Member
Posts: 72
Joined: 2006.10
Post: #2
Code:
glTranslated(theCamera.x, theCamera.y, theCamera.z);
glRotatef(theCamera.rotX, 1.0, 0.0, 0.0);
glRotatef(theCamera.rotY, 0.0, 1.0, 0.0);
glRotatef(theCamera.rotZ, 0.0, 0.0, 1.0);

(this->*funcDraw)(theNewTime);

glRotatef(theCamera.rotX, -1.0, 0.0, 0.0);
glRotatef(theCamera.rotY, 0.0, -1.0, 0.0);
glRotatef(theCamera.rotZ, 0.0, 0.0, -1.0);
glTranslated(-1*theCamera.x, -1*theCamera.y, -1*theCamera.z);

Assuming that you want to do the following:
- Apply tranform
- Render
- Nullify transform

Then you should apply all transforms in reverse order when canceling the transform. Your block of code should read:
Code:
glTranslated(theCamera.x, theCamera.y, theCamera.z);
glRotatef(theCamera.rotX, 1.0, 0.0, 0.0);
glRotatef(theCamera.rotY, 0.0, 1.0, 0.0);
glRotatef(theCamera.rotZ, 0.0, 0.0, 1.0);

(this->*funcDraw)(theNewTime);

glRotatef(theCamera.rotZ, 0.0, 0.0, -1.0);
glRotatef(theCamera.rotY, 0.0, -1.0, 0.0);
glRotatef(theCamera.rotX, -1.0, 0.0, 0.0);
glTranslated(-1*theCamera.x, -1*theCamera.y, -1*theCamera.z);

or even better:
Code:
glPushMatrix();
glTranslated(theCamera.x, theCamera.y, theCamera.z);
glRotatef(theCamera.rotX, 1.0, 0.0, 0.0);
glRotatef(theCamera.rotY, 0.0, 1.0, 0.0);
glRotatef(theCamera.rotZ, 0.0, 0.0, 1.0);

(this->*funcDraw)(theNewTime);

glPopMatrix();

I am willing to bet that this is what is causing your issues
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #3
Thank you so much! ^_^
That was my problem Smile

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Texture Problems jhbau1000 1 5,331 Jul 12, 2010 05:57 AM
Last Post: Kezhaya
  OpenGL ES 2.0 Problems - Senior Project Thread Zammy 3 4,559 Mar 16, 2010 12:32 PM
Last Post: arekkusu
  OpenGL Center of rotation? 3DTOPO 7 10,737 Sep 26, 2008 01:30 PM
Last Post: haegarr
  Retrieving new object coordinates after translation/rotation chris69m 4 6,198 Apr 13, 2008 06:47 PM
Last Post: chris69m
  Problems getting on the fast path in OpenGL Sea Manky 15 9,633 Jun 10, 2007 01:43 PM
Last Post: OneSadCookie