PDA

View Full Version : gluLookAt problems seeing two objects



maxxjr
02-16-2014, 07:49 PM
I am drawing two objects: a cone and a torus beneath the base of the cone. If I orient the camera with gluLookAt, so that it points to the base of the cone, I do not see the torus.

If I look at the shapes from the side, using gluLookAt like this:
gluLookAt (5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

I see that the point of the cone is oriented along the positive z axis, and I see the torus offset to the right.

If I move the camera to the negative z-axis, looking back toward the origin, I only see the cone.

gluLookAt (0.0, 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

I am very much beginning here, and am likely making some fundamental mistake. I am trying to extend examples I have found online for positioning the camera, but seem to be missing something here. My code is attached.

Any suggestions on what I am doing wrong?

Thanks!

charisma_tubagus
02-16-2014, 09:23 PM
Try to change the code to be like this:



glPushMatrix();
glColor3f(0.0,0.0,1.0);
glTranslatef(0.0, 2.0, 0.0);
glutSolidTorus(0.15, 0.25,10,10);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,0.0,1.0);
glColor3f(1.0, 0.5, 0.0);
glutSolidCone(0.5,2.0,20,20);
glPopMatrix();

maxxjr
02-19-2014, 11:44 AM
This did not change the display. Thanks.

tonyo_au
02-19-2014, 04:34 PM
glTranslatef(0.0,0.0,1.0)
places the object behind the other in the xz-plane along the + z-axis

Be default "up" is in + y-axis

use

glTranslatef(0.0,-1.0,0.0)
to put the object below

maxxjr
02-23-2014, 01:57 PM
The other issue that I have, possibly related, is that "zooming out" does not seem to impact size.

The cone + torus look the same size whether the camera is at 1,1,1 or 10,10,10.

Any suggestions?

Thanks,


I am drawing two objects: a cone and a torus beneath the base of the cone. If I orient the camera with gluLookAt, so that it points to the base of the cone, I do not see the torus.

If I look at the shapes from the side, using gluLookAt like this:
gluLookAt (5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

I see that the point of the cone is oriented along the positive z axis, and I see the torus offset to the right.

If I move the camera to the negative z-axis, looking back toward the origin, I only see the cone.

gluLookAt (0.0, 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

I am very much beginning here, and am likely making some fundamental mistake. I am trying to extend examples I have found online for positioning the camera, but seem to be missing something here. My code is attached.

Any suggestions on what I am doing wrong?

Thanks!

tonyo_au
02-23-2014, 03:25 PM
Have you setup your perspective view?

maxxjr
02-23-2014, 06:07 PM
Perspective view took care of the second issue...the objects now scale as I "zoom" in and out with the camera (by changing the eye coordinates in gluLookAt).

I still have the issue where if I move the camera position so that the torus should be in front of the cone, I only see the cone. I added GLUT_DEPTH to glutInitDisplayMode, and GL_DEPTH_BUFFER_BIT to glClear, but behavior is still the same.


Have you setup your perspective view?

maxxjr
02-23-2014, 06:10 PM
Found the answer here:

http://stackoverflow.com/questions/5330673/background-object-is-drawn-in-front-of-foreground-object-in-opengl