Hi all !

This is my problem, I need to convert local axis translating/rotating to global axis. (I won't use matrix, so please don't ask me to use them. I will use them only if there is no other way to solve my problem.)

(X axis = right/left) (Y axis = up/down) (Z axis = front/back)

On this picture we can see that the Camera rotated on its Local Z axis, it's normal that now the Y and X global/local axis aren't parallel and the Z global/local axis are.

So right now, we can assume that if the camera goes up its y position will increase but also its x position.

To do this mathematically in the game I did this :

**-Create an up Vector.** (Which store for each global axes the percentage that make them the axis nearest from the y Local)

this code show how the up vector is computed. (Don't search errors here, I'm (almost) sure that it doesn't come from here)

1 2 3 4 5 6
| public void getUp() { up.x = -Math.sin(Math.toRadians(zRot)) * Math.cos(Math.toRadians(yRot)); up.y = Math.cos(Math.toRadians(xRot)) * Math.cos(Math.toRadians(zRot)); up.z = -Math.sin(Math.toRadians(xRot)) * Math.cos(Math.toRadians(yRot)); } |

-Compute camera movement using up vector: In this code you can see that I just took the previous code and integrate to it the up vector.

(I'm almost sure that there is a problem here)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public void moveForward() { pos.x += speed * ( ( (up.x * Math.sin(Math.toRadians(xRot))) + (up.y * Math.sin(Math.toRadians(yRot))) + (up.z * Math.sin(Math.toRadians(zRot))) ) * ( (up.y * Math.cos(Math.toRadians(xRot))) + (up.z * Math.cos(Math.toRadians(yRot))) + (up.x * Math.cos(Math.toRadians(zRot))) ) ); pos.y += speed * ( ( (up.y * Math.sin(Math.toRadians(xRot))) + (up.z * Math.sin(Math.toRadians(yRot))) + (up.x * Math.sin(Math.toRadians(zRot))) ) * ( (up.z * Math.cos(Math.toRadians(xRot))) + (up.x * Math.cos(Math.toRadians(yRot))) + (up.y * Math.cos(Math.toRadians(zRot))) ) ); pos.z += speed * ( ( (up.x * Math.cos(Math.toRadians(xRot))) + (up.y * Math.cos(Math.toRadians(yRot))) + (up.z * Math.cos(Math.toRadians(zRot))) ) * ( (up.y * Math.cos(Math.toRadians(xRot))) + (up.z * Math.cos(Math.toRadians(yRot))) + (up.x * Math.cos(Math.toRadians(zRot))) ) ); } |

-Compute camera rotations using up vector: The code speak better than me : (if you don't totally understand what i'm doing ask me ^^ !)

1 2 3 4 5 6 7 8 9 10 11 12 13
| public void turnLocalX(float dist) { xGlobalRot += dist * up.y; yGlobalRot += dist * up.z; zGlobalRot += dist * up.x; } public void turnLocalY(float dist) { xGlobalRot += dist * up.x; yGlobalRot += dist * up.y; zGlobalRot += dist * up.z; } |

But even after all of this, it doesn't work

!

Do someone have an idea of where it comes from ?

Thank you for reading !

Sorry if I poorly explained what I mean, my english is not perfect ask me if there is something weird !

Also I am young and the only advanced math we saw at school is cos() and sin()..

Fortunately all my other math knowledge is from the Internet. So if you answer me with 'advanced' math, please explain a bit what you're posting !