Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (757) Games in Android Showcase (229) games submitted by our members Games in WIP (844) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Camera that rotate and move on local axes (Convert local to global.)  (Read 1216 times) 0 Members and 1 Guest are viewing this topic.
AikoCraft

Junior Newbie

 « Posted 2013-02-19 16:05:55 »

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() {                   // This code was used before, it was used for a freefly camera wich can't rotate its local z axis     //      pos.x += speed * Math.sin(Math.toRadians(yRot)) * Math.cos(Math.toRadians(xRot));    //      pos.y += speed * Math.sin(Math.toRadians(xRot)) * Math.cos(Math.toRadians(zRot));    //      pos.z += speed * Math.cos(Math.toRadians(yRot)) * Math.cos(Math.toRadians(xRot));           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;            }       // I still not did the turnLocalZ But it's the same principle.    `

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 !
Pages: [1]
 ignore  |  Print

 EgonOlsen (78 views) 2018-06-10 19:43:48 EgonOlsen (58 views) 2018-06-10 19:43:44 EgonOlsen (78 views) 2018-06-10 19:43:20 DesertCoockie (260 views) 2018-05-13 18:23:11 nelsongames (158 views) 2018-04-24 18:15:36 nelsongames (157 views) 2018-04-24 18:14:32 ivj94 (898 views) 2018-03-24 14:47:39 ivj94 (162 views) 2018-03-24 14:46:31 ivj94 (811 views) 2018-03-24 14:43:53 Solater (175 views) 2018-03-17 05:04:08
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org