Clipping issue with a display list

Hi all. I’ve been having some weird issues with my code, and I can’t figure out what exactly is happening. My goal is to call a previously created display list and have it appear in a location that is advantageous to the viewer.

What I’m currently trying:

  glLoadIdentity();
  glScalef( 1.0f, 1.0f, -1.0f );

  // Make the object upright
  glRotatef(180,1,0,0);  
  glRotatef(90,0,1,0);

  // Move the object so the "camera" can see it
  glTranslatef(XDistance, YDistance, ZDistance );

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glCallList( ListId );  
  glFinish();

Basically, I have some code that will vary XDistance, YDistance and ZDistance based on user input, which will then move the “view” of the object drawn. If I vary YDistance, the object will move up or down in the plane of view, and if I vary ZDistance, the object will move right or left in the plane of view.

However, if I vary XDistance, the object does not appear to move forward or backward (the only remaining axis), but instead seems to move the visible display box forward and back (more clarification: Say I start with x = 0. The apple tree I’m rendering appears in its entirety. If I move x = 1, the apples in the rear of the tree [along with the rest of the rear of the tree, the apples are just the easiest to identify] are not rendered. If I move x = -1, the rear apples are rendered while the close ones aren’t. ).

I’ve tried adding calls to glFrustum and glProspective, with no success (glFrustum has no visible effect and glProspective prevents all rendering).

So I guess I have a couple of questions. One, why is my stuff getting “clipped” when I vary translation in my XDirection. And two, why does translating in XDirection have such a different effect than translating in either YDirection or ZDirection.

Thanks much for your time and help,

Ryan

Every projection matrix needs a near plane and far plane to enable correct depth testing. This means that everything before the near plane and everything behind the far plane is being clipped. You can think of these near and far planes as planes parallel to the image plane of the camera and at a certain depth perpendicular to the view direction. This explains why nothing disappears/reappears when moving along the image plane. If something suddenly disappears it means that it is either in front of the near plane or behind the far plane. You can set the near and far plane distance in the glFrustum and gluPerspective calls.

Cheers,
N.

Ya I tried setting the near and far planes, using both glFrustum and glPerpective(individually and both at the same time), with no success. I also find it odd that the object doesn’t seem to be getting bigger or smaller (the size of the apple stays the same no matter if the object is clipped or not), but rather that the frames themselves seem to be moving based on the translate call. I.e. all I do is call glTranslate( X, 0, 0 ) and the frames seem to move, whereas if I call glTranslate( 0, Y, Z ), the object itself moves side to side and up-down.

Thanks,

Ryan

I don’t understand, you only need to use glFrustum OR gluPerspective (not both). They both set near and far plane in a single function call.

How do you know if it’s not getting bigger/smaller if it’s clipped and therefor invisible? Please define ‘frames’.

N.

I don’t understand, you only need to use glFrustum OR gluPerspective (not both). They both set near and far plane in a single function call.
[/QUOTE]
I first tried glPerspective. Then I tried glFrustum. Then, neither having worked, I tried both. No success in either of the three situations.

I have a tree that’s several units deep. Identical apples are scattered around the tree. So there are some apples that are close to the viewer (we know this because they appear larger) and some that are farther away (smaller). Not all apples disappear at the same time. If I move one direction, each increment will slowly move the far frame forward, and thus not render the back part of the tree. So the close apple stays in view for a couple of movements, but does not change size as we move (we’d expect the apple to get relatively larger if we moved the tree closer to us, and smaller if we moved it away. It doesn’t change size at all). If I move the other direction, each increment will move the near frame forward, thus rendering the far parts of the tree but not the close ones. This only happens when translating the one direction. If I change the YDistance value, the tree moves side to side as expected.

I’m sorry if this is a bit confusing, I’m more than a fair share confused myself. I’m not positive that frames moving are even the cause of my problem, as it only seems to affect that one direction. I do know that if I change XDirection in my code to be 0, I can see the whole tree. If I change it to be 1, I can only see the front half of the tree. And if I change to to -1, I can only see the back half. Changing YDirection and ZDirection do not have similar effects.

Thanks for your help,

Ryan

Ah, ok, first of all, make sure you’re working on the correct matrix by setting the glMatrixMode.

Secondly, opengl matrix operations perform a postmultiplication of the current active matrix which means that the last matrix operation is applied first to the object. So instead of:


glLoadIdentity();
glScalef( 1.0f, 1.0f, -1.0f );
// Make the object upright
glRotatef(180,1,0,0);  
glRotatef(90,0,1,0);
// Move the object so the "camera" can see it
glTranslatef(XDistance, YDistance, ZDistance );

you probably want to use:


glLoadIdentity();
// Move the object so the "camera" can see it
glTranslatef(XDistance, YDistance, ZDistance );
// Make the object upright
glRotatef(180,1,0,0);  
glRotatef(90,0,1,0);
glScalef( 1.0f, 1.0f, -1.0f );

N.

So if I use glMatrixMode(GL_MODELVIEW), there’s no difference( as we would expect given that that’s the default).
If I switch to something like glMatrixMode( GL_PROJECTION), there’s no difference either, even if I use glFrustum or gluPerspective.

But switching those will only mean that my axises line up with the default OpenGL axises, right? I don’t really care if moving in the x direction causes my object to move up and down versus left and right. What I do find odd is that moving the Y and Z directions seem to move the object along two of the axises, while moving in the X direction doesn’t seem to move along the remaining axis, but instead changes the rendered field of view.

Thanks,

Ryan

Ryan, I’m just curious, and don’t take this the wrong way, but how did you find your way into the OpenGL Advanced Forum? Did someone give you a direct link or did you see the choice between advanced and beginners and thought this to be an advanced question?
I ask because this is probably the most basic question I’ve ever seen posted on the advanced forum in my 7 years frequenting it.
Your answer might help the administrators to improve the forum.