Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (576) Games in Android Showcase (154) games submitted by our members Games in WIP (626) 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
 Gimble Lock I assume  (Read 1321 times) 0 Members and 1 Guest are viewing this topic.
Browndog

Senior Newbie

 « Posted 2006-06-01 03:59:29 »

I have a problem I'm tring to change the rotation of an odejava body by using a joystick. The problem is I think I'm getting Gimble Lock.

Here is my code:

 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  29  30  31  32  33  34  35 `private Matrix3f turn;private Matrix3f pitch;private Matrix3f roll;/* turn, pitch, roll are call in order rot = the rotation being passed from the jostick to body*/       void turn(float rot){         turn.setZero();         turn.rotY(rot);      }          void pitch(float rot){         pitch.setZero();         pitch.rotX(rot);            }          void roll(float rot){         roll.setZero();         roll.rotZ(rot);         rotate(); // turn, pitch, roll done now call rotate() to apply them      }             private void rotate(){               Matrix3f m = new Matrix3f();         m.setZero();         m.mul(turn, pitch);            m.mul(m, roll);         m.mul(m, shipBody.getRotation());         shipBody.setRotation(m);       }`

This code works if I only use 1 axis but as soon as I add in the 2 other axis it gets totaly confused and rotates all wrong. I've been doing a bit of reading into gimble lock but havnt found a solution yet. Does somone have a method that will fix this problem.
irrisor

Junior Devvie

 « Reply #1 - Posted 2006-06-02 06:43:02 »

Read up on 3d rotation, Quaternions and rotation matrices. You cannot simply set those values in the matrix. You have to create rotation matrices (e.g. from axis and angle) and multiply them. Additionally the order of multiplication matters - you would have to decide what you really want to do, as simply multiplying absolute angles won't achieve something intuitive, either. Or do you already use deltas?
Browndog

Senior Newbie

 « Reply #2 - Posted 2006-06-02 11:01:51 »

I have done a lot of reading into quaternion and matrix rotation but I cant work it out. I've tried 100 different things but they all come back to the fact that: I have a euler vector, created from the joystick and I dont know of a way that I can convert that into either quaternions or matrix rotatrion without creating gimble lock.

This is what I do to get a euler angle to a quaternion:

 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  29  30  31  32  33 `       private Quat4f createQuaternionFromEuler(float angleX, float angleY, float angleZ )      {      //simply call createQuaternionFromAxisAndAngle for each axis      //and multiply the results         Quat4f qx = createQuaternionFromAxisAndAngle(            1f,0f,0f, angleX );         Quat4f qy = createQuaternionFromAxisAndAngle(            0f,1f,0f, angleY );         Quat4f qz = createQuaternionFromAxisAndAngle(            0f,0f,1f, angleZ );            //qx = qx * qy         qx.mul( qy );            //qx = qx * qz         qx.mul( qz );               return qx;      }             public final Quat4f createQuaternionFromAxisAndAngle(       float x, float y, float z, float angle )      {         float sin_a = (float) Math.sin( angle * 0.5f );         float cos_a = (float) Math.cos( angle * 0.5f );               x = (float) (x * sin_a);         y = (float) (y * sin_a);         z = (float) (z * sin_a);         float w = (float) cos_a;                  return new Quat4f(x,y,z,w);      }`

I then multiply the 3 quaternion created from eluer angles  x, y and z and I just get gimble lock.
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 ClaasJG (40 views) 2015-04-30 20:33:25 Riven (24 views) 2015-04-30 13:25:12 ClaasJG (43 views) 2015-04-27 13:36:51 BurntPizza (51 views) 2015-04-23 03:42:11 theagentd (52 views) 2015-04-22 16:23:07 Riven (65 views) 2015-04-16 10:48:47 Duke0200 (76 views) 2015-04-16 01:59:01 Fairy Tailz (58 views) 2015-04-14 20:13:12 Riven (63 views) 2015-04-12 21:36:37 bus hotdog (88 views) 2015-04-10 02:39:32
 theagentd 24x BurntPizza 19x Spasi 16x kingroka123 11x wessles 11x alwex 11x Hanksha 9x Ecumene 8x chrislo27 7x Olo 7x kevglass 7x ra4king 7x Riven 6x princec 6x trollwarrior1 5x EgonOlsen 5x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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