Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Camera

  1. #1
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Bangalore,India
    Posts
    49

    Camera

    Hello Friends,
    Can I place two camera in any opengl application? What I want for a Appliction two camera place one which directed toward front another one back side,in menu two options one for front camera on and second for back camera on.

    with regards
    Rajiv Kumar

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    25

    Re: Camera

    You can only have one camera, but you can specify it's location using gluLookAt. Figure out your camera positions and toggle between them if necessary

    Regards,
    Ritchie

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    587

    Re: Camera

    There's no such thing as a "camera", just the modelview and projection matrices that you specify. You can have multiple views dependent on a menu selection (i.e. multiple "cameras") by having different modelview (and possibly projection) matrices. It should be quite easy to do. You can also have multiple viewports (obviously) if you want, like in 3DS Max.

    Hope that helps.

  4. #4
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Bangalore,India
    Posts
    49

    Re: Camera

    Well ffish,
    As you told 3DS MAX have multiple view.I want to implement same,can you tell how different gluLookAt funtion for different view.
    with thanks

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    25

    Re: Camera

    Hello,

    ffish, I agree with you that there is no camera, but pretending there is one, you can get a feeling on how to use gluLookAt. The red book also uses the camera analogy to explain viewing transformations.

    As to your problem Rajiv, I guess you can set up multiple viewports and render the scene in each viewport with different angles.

    Regards,
    Ritchie

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    587

    Re: Camera

    rajiv: If you wanted to do something like 3DS Max, you'd use glViewport(x, y, width, height) to specify the "windows" to draw into. Something like:
    Code :
    // Setup orthogonal projection matrix.
    glViewport(0, 0, width/2, height/2);
    glMatrixMode(GL_MODELVIEW);
    // Setup modelview matrix (e.g. using gluLookAt() if you want).
    DrawLowerLeftWindowStuff();
    glMatrixMode(GL_PROJECTION);
    // Setup orthogonal projection matrix again (unnecessary, I think?)
    glViewport(0, height/2, width/2, height);
    glMatrixMode(GL_MODELVIEW);
    ...
    DrawUpperLeftWindowStuff();
    ...
    DrawUpperRightWindowStuff();
    ...
    // Setup perspective projection matrix.
    glViewport(width/2, 0, width, height/2);
    ...
    DrawLowerRightWindowStuff();
    Ritchie: Agreed. gluLookAt() is a good analogy for a camera, if you want to think about it like that. I just prefer to think about the whole thing mathematically using the individual glRotates/glTranslates in my head. It's irrelevant really, both ways are a means to an end as long as you understand how they work and how your matrix is set up.

    Hope that helps.

  7. #7
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Bangalore,India
    Posts
    49

    Re: Camera

    Hi ffish,
    It is correct but in different viewport gluLookAt has different parameter what is the gluLookAt function for different viewport.

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    25

    Re: Camera

    Hello,

    rajiv: The different parameters are your positions of the 'camera' in each viewport.
    If you have two viewports. In the first viewport you look at your objects as if you're standing in front of it, and in the second you have the same objects, now looking at it from the right. Then your display function should be something like this:

    Code :
    // Setup orthogonal projection matrix.
    glViewport(0, 0, width/2, height);
    glMatrixMode(GL_MODELVIEW);
    // Setup modelview matrix (e.g. using gluLookAt() if you want).
    gluLookAt (0, 0, 5,    // eye coordinates
               0, 0, 0,    // center coordinates
               0, 1, 0);   // up vector
    DrawLeftWindowStuff();
    glMatrixMode(GL_PROJECTION);// Setup orthogonal projection matrix again (unnecessary, I think?)
    glViewport(width/2, 0, width/2, height);
    glMatrixMode(GL_MODELVIEW);
    gluLookAt (5, 0, 0,    // eye coordinates
               0, 0, 0,    // center coordinates
               0, 1, 0);   // up vector
    DrawRightWindowStuff();
    ffish: (just to make sure that I understand it all): Am I correct that instead of the gluLookAt functions in the code above can be substituted like this:

    gluLookAt (0, 0, 5, // eye coordinates
    0, 0, 0, // center coordinates
    0, 1, 0); // up vector

    is the same as:

    glLoadIdentity();
    glTranslatef (0, 0, -5);

    and

    gluLookAt (5, 0, 0, // eye coordinates
    0, 0, 0, // center coordinates
    0, 1, 0); // up vector

    is the same as (I hope I am doing this in the correct order):

    glLoadIdentity();
    glRotatef(90, 0, 1, 0);
    glTranslatef(0, 0, -5);

    Regards,
    Ritchie

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    587

    Re: Camera

    Ritchie: yeah, that's right (except you got the rotate/translate around the wrong way ). I kind of prefer doing it manually because it may save function calls, especially for the simple examples. e.g. your first example is a glLoadIdentity and a glTranslate, or one glLoadMatrix whereas gluLookAt will have a fixed number of calls to glTranslate and glRotate no matter what the complexity. Of course, this is unlikely to be the source of a bottleneck in an app anyway, but it is good to save calls whenever possible. On the other hand, gluLookAt may be easier for someone to conceptually deal with, so it has its benefits too.

    Hope that helps.

  10. #10
    Intern Newbie
    Join Date
    Aug 2001
    Location
    Bangalore,India
    Posts
    49

    Re: Camera

    Ritchie and ffish,
    Many Many Thanks of help!!!
    Rajiv Kumar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •