PDA

View Full Version : Changing Camera Position



Torrtuga
04-27-2015, 10:30 PM
Hello, I am a beginner and 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.

My code for the cube :

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();

Now when I am trying to change the camera position using : to gluLookAt(0.5,0.5,0.5,0.0,0.0,0.0,0.0,1.0,0.0) it is just giving me an upper view of the cube.
How can I possibly view the inside of the cube?

reader1
04-28-2015, 04:39 AM
good , work hard. I have to admire your assiduous spirite. I have never intended to type so many...
just exam those vertices, too many repeat, why don't you simplify them by way of index?
vertex point array can do the trick.

IonutCava
04-28-2015, 07:01 AM
Well, first of all, you should stop using the fixed function pipeline as anything you'll learn from it will be pretty outdated from the start. gluLookAt being a fine example.
With that said, you really need to think about what you're trying to achieve here: gluLookAt(0.5,0.5,0.5,0.0,0.0.0 ... translation: move to the side, up and back a bit (+Z is towards you - Right-Handed System).
The cube, being in the center, kinda nullifies the need to move on the X and Y.
To get the "room" effect, you need to move quite a bit back, e.g. 0.95 and adjust the FoV accordingly (the first value of gluPerspective to ~60+ I guess).

Do this, and you will see ... probably nothing, if you are using standard stuff like culling, lighting, etc. So .. flip normals, cull mode and the rest as needed.