PDA

View Full Version : Camera System and View Stationary Objects



dhm
07-21-2003, 01:11 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Obli
07-21-2003, 10:32 PM
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?

dhm
07-22-2003, 10:57 AM
Cool http://www.opengl.org/discussion_boards/ubb/smile.gif

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

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.

Obli
07-23-2003, 11:33 AM
...
[3) Scale if required]...
The forum rules (blah blah and blah) pretend me to discurage you to do this http://www.opengl.org/discussion_boards/ubb/wink.gif



...
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).]

dhm
07-25-2003, 08:15 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

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

Hope that helps some other people http://www.opengl.org/discussion_boards/ubb/smile.gif