torrtuga
torrtuga

Reputation: 51

Placing the camera position inside cube in openGl

I am trying to create a 3D room. What I am doing is that I am creating a 3D cube and then trying to changing the camera position inside the cube so that it appears as a room. When I make my coordinate vertices as 3 instead of 1 it works but for 1 it doesn't work. Why did this happen?

My code for the cube is :

glBegin(GL_QUADS);        // Draw The Cube Using quads
glVertex3f(1.0f, 1.0f, -1.0f);    // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, -1.0f);    // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f);    // Bottom Left Of The Quad (Top)
glVertex3f(1.0f, 1.0f, 1.0f);    // Bottom Right Of The Quad (Top)
glVertex3f(1.0f, -1.0f, 1.0f);    // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f, -1.0f, 1.0f);    // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f, -1.0f, -1.0f);    // Bottom Left Of The Quad (Bottom)
glVertex3f(1.0f, -1.0f, -1.0f);    // Bottom Right Of The Quad (Bottom)
glVertex3f(1.0f, 1.0f, 1.0f);    // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f);    // Top Left Of The Quad (Front)
glVertex3f(-1.0f, -1.0f, 1.0f);    // Bottom Left Of The Quad (Front)
glVertex3f(1.0f, -1.0f, 1.0f);    // Bottom Right Of The Quad (Front)
glVertex3f(1.0f, -1.0f, -1.0f);    // Top Right Of The Quad (Back)
glVertex3f(-1.0f, -1.0f, -1.0f);    // Top Left Of The Quad (Back)
glVertex3f(-1.0f, 1.0f, -1.0f);    // Bottom Left Of The Quad (Back)
glVertex3f(1.0f, 1.0f, -1.0f);    // Bottom Right Of The Quad (Back)
glVertex3f(-1.0f, 1.0f, 1.0f);    // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f, -1.0f);    // Top Left Of The Quad (Left)
glVertex3f(-1.0f, -1.0f, -1.0f);    // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f, -1.0f, 1.0f);    // Bottom Right Of The Quad (Left)
glVertex3f(1.0f, 1.0f, -1.0f);    // Top Right Of The Quad (Right)
glVertex3f(1.0f, 1.0f, 1.0f);    // Top Left Of The Quad (Right)
glVertex3f(1.0f, -1.0f, 1.0f);    // Bottom Left Of The Quad (Right)
glVertex3f(1.0f, -1.0f, -1.0f);    // Bottom Right Of The Quad (Right)
glEnd();

And I am using gluLookAt(0.0,0.0,0.0,0.0,0.0,-1.0,0.0,1.0,0.0);

Upvotes: 0

Views: 487

Answers (1)

jozxyqk
jozxyqk

Reputation: 17294

I'm assuming you're using a perspective projection and you near plane is greater than one. This would lead to the following scenario where the geometry is behind the near plane and gets clipped:

enter image description here

Simply reduce the near plane to 0.1 for example. But make sure not to make it too small while the far plane is too big, or you'll lose depth precision and hit "z fighting" issues.

Upvotes: 1

Related Questions