Results 1 to 3 of 3

Thread: Changing Camera Position

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    5

    Changing Camera Position

    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?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    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.

  3. #3
    Junior Member Newbie IonutCava's Avatar
    Join Date
    May 2012
    Location
    Bristol, U.K.
    Posts
    27
    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.

Similar Threads

  1. changing position of an object continuously
    By david419 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-21-2013, 06:53 AM
  2. Changing the camera look at
    By doron in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-31-2010, 10:49 AM
  3. Changing rotation center for orthographic camera
    By artmansoft in forum OpenGL: General
    Replies: 12
    Last Post: 03-12-2010, 10:40 PM
  4. Trouble changing the cam position, using gluLookAt
    By helluin in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-03-2010, 11:22 AM
  5. Camera Position / Camera Angle / Camera Target Position
    By bobGL in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-02-2007, 09:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean