Funny phenomenon(maybe related to perpective?)

Hello, everyone,
I tried to load some 3ds files, and want to put few parts( tires & body of car ) altogether.
Some funny phenomenon happens: In certain position and angle to the parts, the parts seems to be neat:

But after lifting up the “camera” along Y axis a bit, the parts seems to be NOT neat anymore:

That’s somehow queer when the “camera” moves, some parts seems to be put-together and sometimes the parts just away from each other. I wonder what kind of wrong is it…

I use following few lines of code at the first of initialization:

glMatrixMode( GL_PROJECTION );
glEnable( GL_DEPTH_TEST | GL_RGB );
glEnable( GL_CULL_FACE );
glFrontFace( GL_CW );
glClearColor( 0, 0, 0, 1 );
gluPerspective( 30.0, 1.33, 1, 400 );

I wonder if anything wrong with use of gluPerspective or any other else. If anyone came to have some ideas about what might be wrong, it would be greatly appreciated.
Also, I would love to provide any further information if neccessary.

Thanks in advance.

BTW, I hope these two picture might have some help:

neat?

oops?

May somebody give a hand, please?
Any clue is fine…

I try to set the environment like this:

glMatrixMode( GL_PROJECTION );
glEnable( GL_DEPTH_TEST|GL_RGB );
glEnable( GL_CULL_FACE );
glFrontFace( GL_CW );
glClearColor( 0, 0, 0, 1 );
gluPerspective( 30.0, 1.333333, 1.0, 200.0 );
glMatrixMode( GL_MODELVIEW );
sceneRender= glGenLists( 1 );
glNewList( sceneRender, GL_COMPILE );
scene();
glEndList();

========
and the following code has no more manipulation to GL_PROJECTION.(all in GL_MODELVIEW) I hope these info might help.
Even if I ask something too silly to be answered, I hoped someone can give me some suggestion reading to prepare myself. ( An url will be great ) Thanks.

i can’t see the pictures, but at least i can say it all depends on the inner workings of your scene() function: take particular care of matching glPushMatrix() and glPopMatrix() calls, and everything should be fine.

also, what does
glEnable( GL_DEPTH_TEST | GL_RGB );
means to you ?
as far as i know, a call like this is not invalid, but will probably enable something you don’t want to be enabled… or maybe will rise an error and opengl will discard it silently.

Thanks for your reply.
I found the link aren’t available. Sorry for the disturbance, Let’s try these: screenshot from +z to -z
neat?
oops!

I think you’re right about I should mention something about scene(). Following is code of my main idea about how to put tire:
in car.renderer()

 
   glTranslatef(  MCpos.x,  MCpos.y,  MCpos.z ); // MCpos is where the carbody will be put.
   glRotatef( -90.0, 1.0, 0.0, 0.0 ); // Rotation for correcting the body model                                                   
   // rotate with headArrow                                                                                                       
   body.renderer();
   glRotatef( 90.0, 1.0, 0.0, 0.0 ); // rotate back for correction
   tireMounter();

and tireMounter() looks like:

 
  for ( int i=0; i< 4; i++ )
    {
      glPushMatrix();
      glTranslatef( tires[i].susJuncVector.x, tires[i].susJuncVector.y, tires[i].susJuncVector.z ); // susJuncVector is a pos related to center of carbody, where the tire would be mounted.
                                                                                             
      glRotatef( tires[i].steeringAngle, 0.0, 1.0, 0.0 ); // steering                                                  
      tires[i].renderer();
      glPopMatrix();
    }
 

And I tried to dump a ModelView matrix value of a tire.
In the “neat?” picture
tire[0]:0 0 -1 0 0 1 0 0 1 0 0 0 3.51667e-05 -0.20001 -2.40001 1
In the “oops” picture( rise along y axis for 0.1 )
tires[0]:0 0 -1 0 0 1 0 0 1 0 0 0 3.51667e-05 -0.300013 -2.40001 1

I hope these info may help, thanks for the reply, and I would really appreciat for any further suggestion.

the code seems conceptually right…
if it only fails with a single tire, then i would look elsewhere for the bug: check the function wich evaluates the tires positions.

if it is all right there, then there’s another source for this sort of bugs: the modelview matrix stack.
the opengl specs say that the minimum stack depth must be 32 matrices (if i recall it right), and if you do a push but the stack is completely filled, then the push will be discarded… but the subsequent pop won’t.

so, in the tire loop, you get the first tire placed correctly, because a push don’t changes the contents of the current mv matrix, and you will place the tire relatively to the car mv matrix, as you expect.
instead, the others tires won’t be at the right place, because the pop will change the mv matrix to a different one, not to the car’s mv matrix.

so, maybe you filled up the gl mv stack… i would:

1 - do assertion checks on gl error states.
2 - double-check glPush/glPop pairings
3 - coffee/music break
4 - double-check again :slight_smile:

Thank you again. This situation, in fact, happens on all four tires. Let’s see these two pictures and mv dumps of 4 tires:
pic1
current MV(MC):1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 -0.599965 -0.3 -9.00002 1
tire[0]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 -1.89997 -0.4 -8.30002 1
tire[1]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 0.400035 -0.4 -6.00002 1
tire[2]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 0.400035 -0.4 -12 1
tire[3]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 -1.59997 -0.4 -12 1
move along z axis
current pos(MC):1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 -0.599965 -0.3 -10.5 1
tire[0]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 -1.89997 -0.4 -9.80002 1
tire[1]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 0.400035 -0.4 -7.50002 1
tire[2]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 0.400035 -0.4 -13.5 1
tire[3]:1.11022e-16 0 -1 0 0 1 0 0 1 0 1.11022e-16 0 -1.59997 -0.4 -13.5 1

BTW, I use gluLookAt() to move the “cam” like this:

 gluLookAt( camPos[0], camPos[1], camPos[2], camPos[0]+ sin( camRot[1]/180*M_PI ), camPos[1], camPos[2]- cos( camRot[1]/180*M_PI\
 ), 0, 1, 0 ); 

well, I know it’s not a good idea to use sin and cos anyway, but just temp.ly.

And another funny thing is that if you paid more attention on tire itself, it looks like “tends to face the camera”. I checked my code, so far, I believe I haven’t rotate tires out of the tireMounter().

It’s my dream since I was a kid to write a racing game, even I know it’s quite hard now. I wish to do as far as I can reach. And thank you again, dmy. Although my problem is not solved yet. But somehow I feel more cheered-up.