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 5 of 5

Thread: Camera System and View Stationary Objects

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Edinburgh, Scotland
    Posts
    6

    Camera System and View Stationary Objects

    Hi All,

    I have a small problem I am trying to work out in regard to OpenGL.

    I have a simple camera system which uses gluLookAt for its basic functionality. This allows me to move the mouse and the view will move around world.

    However, what I would like to do is create a cube object and have it in the bottom right of the view constantly. Even when the view is changed using the mouse.

    Does anyone have any hints/tips or pseudo code for this? Could someone give me an explanation of how to achieve this?

    Thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    628

    Re: Camera System and View Stationary Objects

    Put the cube in a way it is in the position you want using a identity modelview-matrix.

    After you draw your world, do a LoadIdentity.
    This will put the cube where it should be. There is the problem you have to place it very carefully (projection matrix still applies) but it should not be a problem.

    Got the idea?

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Edinburgh, Scotland
    Posts
    6

    Re: Camera System and View Stationary Objects

    Cool

    Ok I have my desired effect using:

    1) Update Camera
    2) Draw Scene
    3) Push and Load Identity
    4) Draw Cube
    5) Pop

    And I have worked out how to rotate the cube too

    After Loading Identity:
    1) Translate
    2) Rotate
    [3) Scale if required]

    Quick question: I thought I would have had to rotate and then translate? (So rotation was around origin and then translate away) Why did this make the cube spin around in a large circle?

    Thanks very much for you help.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    628

    Re: Camera System and View Stationary Objects

    ...
    [3) Scale if required]...
    The forum rules (blah blah and blah) pretend me to discurage you to do this

    ...
    Quick question: I thought I would have had to rotate and then translate? (So rotation was around origin and then translate away) Why did this make the cube spin around in a large circle?...
    Because, of curse, you translate on a new coordinate system which is defined as a rotation of the original one.

    So, if your coordinate system looked like '+' and you rotate it 45 degrees counter clockwise you get 'X'. Now, in '+', the +y axis is "straight up". After the rotation, the new +y axis is the upper left part of the 'X', so it will translate in that direction.

    Think about it a while and you'll figure out that the natural conseguence of this is a cube that rotates as you described.
    Instead, if you first place the cube where you need it and then rotate it you get the right effect. Think like the rotation is getting "amplified" by successive transforms.

    EDIT: big typo fixed.

    [This message has been edited by Obli (edited 07-23-2003).]

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Edinburgh, Scotland
    Posts
    6

    Re: Camera System and View Stationary Objects

    Hi again,

    OK I just about understood your explanation and then looked at the Red Book again. There is actually q really good explanation in that - well my brain seems to understand it

    The reference is (3rd edition): Page 106 Viewing and Modelling Transformations until page 110.

    Hope that helps some other people

Posting Permissions

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