5

I'm working on interactive scenes for a computer graphics course. I've set up a program which will generate color cubes, and let me rotate them with the keyboard. However they're getting cut open by the near clip plane of my camera:

Color cubes being clipped

I've tried to use gluPerspective, but the OpenGL documentation doesn't give any examples of its use. I found it being used in an example program online, and semi-replicated their code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 65, 1, 0.01, 100 );
glMatrixMode(GL_MODELVIEW);

Any thoughts?

UPDATE: As suggested in the comments below, I tried using glFrustum instead, with the following code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -0.5, 0.5, -0.5, 0.5, 0.1, 100 );
glMatrixMode(GL_MODELVIEW);

Again, there was no difference. Am I not pushing the resulting matrices correctly or something?

Nick
  • 6,900
  • 5
  • 45
  • 66
  • 1
    You're taking a compute graphics course that involves perspective projection and they didn't talk about the near clip plane? – Nicol Bolas Oct 18 '12 at 05:13
  • 1
    Perhaps you need to move your objects a little farther from the Camera. Right now it seems that they came out closer that 0.0 – Kromster Oct 18 '12 at 05:37
  • Do as Krom Stated or adjust your view Frustum – CStreel Oct 18 '12 at 06:08
  • I moved the cubes one whole unit away from the camera, and now as they rotate they get clipped by both the near and the far clip planes. I'll look into view frustum – Nick Oct 18 '12 at 13:48
  • 1
    You should post your render code if you can do that without being considered cheating for your class. If there was no difference between your call to gluPerspective and when you used glFrustum, then perhaps something else is amiss. If both planes are clipping your objects, then they must be quite large relative to your clipping space. Your far plane is 100 units away from the eye. How big are the cubes? – JCooper Oct 18 '12 at 14:05

1 Answers1

2

Perhaps you need to move your objects a little farther from the Camera. Right now it seems that they are closer than 0.0.

Considering your update "I moved the cubes one whole unit away from the camera, and now as they rotate they get clipped by both the near and the far clip planes" your cubes may be too large for your clipping depth (100 - 0.1). Move cubes away from the camera by 50 and set your clipping planes to 0.1 .. 1000 to make sure everything fits.

If the problem remains we might need to look at your matrices code.

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • My cubes are being constructed from the following array of points: `point4 vertices[8] = { point4( -0.5, -0.5, 0.5, 1.0 ), point4( -0.5, 0.5, 0.5, 1.0 ), point4( 0.5, 0.5, 0.5, 1.0 ), point4( 0.5, -0.5, 0.5, 1.0 ), point4( -0.5, -0.5, -0.5, 1.0 ), point4( -0.5, 0.5, -0.5, 1.0 ), point4( 0.5, 0.5, -0.5, 1.0 ), point4( 0.5, -0.5, -0.5, 1.0 ) };` they are positioned at (-0.75, 0, 0) and (0.75, 0, 0) respectively, (-0.75, 0, 1) and (0.75, 0, 1) after I moved them farther from the camera – Nick Oct 18 '12 at 14:21
  • 1
    You know that when a cube is positioned at -1 and rotated by 45 degrees its edges are 1.41 away from it's center and should get clipped? – Kromster Oct 18 '12 at 14:36
  • I understand that part of the picture is going to be off-camera, and should be clipped, but it's so visible, and you can see into the insides of the cubes. Not to mention the far clip plane is cutting things off as well. If I want to have a real scene, it's not going to look good. Nothing I change in the call to glFrustum or gluPerspective seem to be changing anything, so I don't think I'm using them correctly. How do you use them? – Nick Oct 18 '12 at 14:46