Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 1277 times)
0 Members and 1 Guest are viewing this topic.
Offline 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.
Offline 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?
Offline 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (32 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (58 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!