PDA

View Full Version : Lines jumping around



Super-K
02-09-2002, 01:16 PM
I have drawn a very simple view. I just have axis lines running from +-200.0 on each of the x, y, and z axis.

glBegin(GL_LINES);
glVertex3f(200.0f, 0.0f, 0.0f);
glVertex3f(-200.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 200.0f, 0.0f);
glVertex3f(0.0f, -200.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 200.0f);
glVertex3f(0.0f, 0.0f, -200.0f);
glEnd();


When I rotate the world (modelmatrix) using glRotate I noticed that sometimes the axis lines tend to jump around a little bit (most noticable at the origin). Sometimes they don't appear to even go though the origin (?!).

What causes this? It seems to get worse if the line is going straight up and down on my screen. Is this a floating point precision problem, or a clipping problem, something else?

I actually took the Gtk sample application "viewlw", added the axis lines, and it does the same thing... I know this is not normal though, I have apps that don't exhibit this behavior (although they don't use the Gtk GL widget).

Thanks for any info!

chowe6685
02-09-2002, 04:30 PM
When you rotate the modelview matrix do you
glRotatef(increment, ...)
or
glLoadIdentity()
glRotatef(Total Accumulated angle,...)
if you use the former, try switching to the latter, if you constantly modify a matrix you can get accuracy errors

Super-K
02-09-2002, 04:58 PM
Yes, I redo both the projection and model matrix every time using what amounts to this render function:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, width/height, 0.25f, 200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f);
glRotatef(angle1, 1.0f, 0.0f, 0.0f);
glRotatef(angle2, 0.0f, 1.0f, 0.0f);
..render axis lines..
swap buffers...

Enabling or disabling GL_DEPTH_TEST doesn't seem to help.

If I move the camera close to the origin (-1.0 on the Z axis) the lines really start jumping around all over the place. If I move farther away they don't jump as much. This makes me think it's a precision error but I can't figure out where the problem is. I'm using GLfloats for everything.

It seems like I've seen this before (years ago) but I can't remember where or what caused it.

Super-K
02-09-2002, 05:07 PM
Here's a picture looking at the origin. Remember, the axis lines go +-200.0 on each axis, but look, they don't cross in the center... What?!? http://www.opengl.org/discussion_boards/ubb/smile.gif

http://www.planetquake.com/oz/3d/brokenaxis.png

Super-K
02-09-2002, 05:33 PM
OK, I found a solution.

I have to draw all the lines so they terminate at the origin instead of just +- the extents.

// Positive X
glVertex(200,0,0);
glVertex(0,0,0);
// Negative X
glVertex(-200,0,0);
glVertex(0,0,0);
...
etc.

That seems to fix it. No more jumping lines. I finally remembered what I did all those years ago.

Super-K
02-09-2002, 05:40 PM
But I still want to know why it does that... I haven't figured that out yet. If someone who knows would be so kind as to share...

Do I have to live with this, or did I not set something up correctly?