Problems with camera movement and rotation.

Started by
13 comments, last by Wodzu 14 years, 1 month ago
Quote:
In first case when I am thinking in terms of grand fixed orgin the command are issued in the reversed order, so:

1. Cube is drawn
2. Cube is rotated around OY counterclockwise by 90 degrees.
3. Cube is rotated around OX counterclockwise by 90 degrees.
4. Cube is translated -5 units in Z direction from the orgin.

Am I thinking correct?


Sounds right to me. Your second case should work equally well, and I'm not sure I really understand what is wrong.

Forgive me if I'm missing something, but how can you tell what is happening by rotating a cube by 90 degrees? If I take a cube and rotate it by 90 degrees doesn't that look exactly the same? I think you need to render some kind of object that is visually unique from all sides so you can tell what is happening. Either that you can just draw some axis on your cube:

glLoadIdentity;gluLookAt(0,0,5, 0, 0, 0, 0, 1, 0);glRotatef(90, 1, 0, 0);glRotatef(90, 0, 1, 0);glutWireCube(1);glBegin(GL_LINES);glColor3f(1,0,0);glVertex3f(0,0,0); glVertex3f(2,0,0);glColor3f(0,1,0);glVertex3f(0,0,0); glVertex3f(0,2,0); glColor3f(0,0,1);glVertex3f(0,0,0); glVertex3f(0,0,2); glEnd();


If that's still not working you can post some images and I can maybe understand better.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Advertisement
I had more or less the same problem. Here was my solution (in C++):

glLoadIdentity();glRotatef( -camPitch, 1, 0, 0 );glRotatef( -camYaw, 0, 1, 0 );glTranslatef( -camX, -camY, -camZ );


The cam values are handled in a Lua script in my implementation, which has dodgy angle calculations so I'm not sure if camPitch and camYaw follow standard form, but a little tinkering with - signs should fix it.

Edit:
You'd then render all your stuff in world coords (so your cube at 0, 0, 5) after that.
Firs of all, thank you karwosts for your time and helping me out.

Yes you have absolutely right, one the example which I have given I could not say how to cube was rotated. I just modified my working example, maybe not neceserly and I confused you.

I am drawing the axis as you suggested, so we have right now:

RED: X - axis
GREEN: Y - axis
BLUE: Z - axis

In case 1 I am rotating cube firstly 90-degrees around OY and after that the Z-axis is on the place of X-axis and the X-axis is on the place of Z-axis. So the X-axis has been rotated as weel. Then I am rotating around X-axis, hovewer X-axis is now on the position of Z-axis but the cube is rotating like the X-axis would be on the oryginal position!

In 2 case I am also performing the same rotation around OY, and the axises has been rotated in the same way(X-axis is on the Z-axis position). But then when I am rotating around X-axis the rotation occurs in a different way! Now the cube rotating around X-axis like it would been on the Z-axis!

I can not understand that.

Here are images with my commentary, hope this will be now easier to udenrstand.

Here is the starting position for both cases:

Starting position

Rotation 90 counterclockwise around OY gives this result for both cases:


OY 90 degrees rotation

As we see now the X-axis is on the place of Z-axis. Also the Z-axis should be on the left side of the cube, I don't understand why it is on the right side.

Now I am performing rotation around X-axis which is hidden (it is on the place of Z-axis).

Case 1 OX 90 deegre rotation

But instead of local coordinate system rotation (X-has been rotated) now the image is rotated about the world coordinate system around BLUE axis.
So the question is, why the cube has been rotated around BLUE axis?

Now lets compare it with case two rotation:

Case 2 OX 90 deegre rotation

Now the cube has been rotated aroud the RED-axis instead of the BLUE axis (like in case 1).

Why there is adifference? I can not understand the inconsistency in this rotations. Either both examples shoudl rotate around local coordinate system or around a world coordinate system but they behave differently and ONLY the order of rotations has been changed.

Here is the link to the working examples:

http://www.speedyshare.com/files/21431956/Rotation.zip

thomasfn1: Yes this solves the problem (I've found that solution on the NeHe tutorials page) but I would like to understand this rotation thing.

Thank you for your time.







Just started...
I think I must have confused you talking about applying operations in reverse order.

Quote:
In case 1 I am rotating cube firstly 90-degrees around OY and after that the Z-axis is on the place of X-axis and the X-axis is on the place of Z-axis. So the X-axis has been rotated as weel. Then I am rotating around X-axis, hovewer X-axis is now on the position of Z-axis but the cube is rotating like the X-axis would be on the oryginal position!

Quote:
CASE 1:
glLoadIdentity;
gluLookAt(0,0,5, 0, 0, 0, 0, 1, 0);
glRotatef(90, 1, 0, 0);
glRotatef(90, 0, 1, 0);
glutWireCube(1);


Everytime you call a "gl{MatrixOp}f" command, this happens on the coordinate axis that has already been transformed by all of the previous operations.

So when you call gluLookAt (essentially glTranslate), you first translate the cube on its local coordinate system. Then when you call glRotate on X, you rotate the cube on its local X axis. Finally calling glRotate on the Y axis rotates it on the local Y axis (which is now parallel to the global Z axis as you already rotated the object around X).


Quote:
Rotation 90 counterclockwise around OY gives this result for both cases.
...
Also the Z-axis should be on the left side of the cube, I don't understand why it is on the right side.

No this is correct. The +Z is towards the camera by definition. So if you rotate Y 90 degrees CCW then it will be pointed to the right, while X is pointed out.


I think I would suggest that you just spend some more time playing with it, possibly searching the internet for articles and more explanations.

I don't mind helping, it helps me too to verbalize these concepts and think about them, even after I think I understand it can still be confusing sometimes. I'm just afraid I've reached the limit of how I can explain it.

Best of luck!
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I think I've finally understand this. Somehow during the time I confused the thing whish is drawn on the screen with actual code execution and this gave me all the trobule.

Thank you for devoting your time in helping me on this. :)
Just started...

This topic is closed to new replies.

Advertisement