Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Quaternion rotations and gimble lock  (Read 938 times)
0 Members and 1 Guest are viewing this topic.
Offline arthor

Junior Newbie





« Posted 2006-03-11 13:12:33 »

Hi, I've been trying to implement a camera class for a couple of weeks now ive finally got something thats mostly working using quaternions for rotation and vectors for movement, but I think im suffering from gimble lock. The more i turn to the side the less height i can acheive turning upwards. Im fairly certain the vector section is correct and is mostly independant from the rotation.

Heres my code for the rotation

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  
public void updateCamera()
{
   Quat4f rotation = new Quat4f();
     
   AxisAngle4f axisAngleX = new AxisAngle4f(cameraX.x, cameraX.y, cameraX.z, (float)Math.toRadians(angleX));
   AxisAngle4f axisAngleY = new AxisAngle4f(cameraY.x, cameraY.y, cameraY.z, (float)Math.toRadians(angleY));
     
   Quat4f quatXRotation = new Quat4f();
   Quat4f quatYRotation = new Quat4f();
     
   quatXRotation.set(axisAngleX);
   quatYRotation.set(axisAngleY);
     
   rotation.mul(quatYRotation, quatXRotation);
   rotation.normalize();
   
   Matrix4f newViewMatrix = new Matrix4f();
   newViewMatrix.set(rotation);
   newViewMatrix.transpose();
     
   float[] rotationMatrixArray = new float[]
   {
   newViewMatrix.m00, newViewMatrix.m01, newViewMatrix.m02, 0,
   newViewMatrix.m10, newViewMatrix.m11, newViewMatrix.m12, 0,
   newViewMatrix.m20, newViewMatrix.m21, newViewMatrix.m22, 0,
    0, 0, 0, 1
   };

      gl.glLoadIdentity();
      glu.gluPerspective(60.0, 800/600, 2.0, 500.0f);
     
      gl.glTranslatef(cameraPosition.x, cameraPosition.y, cameraPosition.z);
      gl.glMultMatrixf(rotationMatrixArray);
   }


Am i doing something completely wrong? Or do i need to approach this from a different angle.
Offline Gannin

Senior Newbie





« Reply #1 - Posted 2006-03-12 00:30:01 »

You would probably be better served by asking this question in one of the OpenGL forums here.
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2006-03-12 02:11:34 »

AIUI the whoel point of Quaternions is that they *don't* suffer from gimble lock.

As this is a heavy 3D math question I would *defintiely* ask it in one of the 3D forums (JOGL or Java3D)

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zero

Junior Member





« Reply #3 - Posted 2006-03-12 02:54:59 »

hey arthor,

what are the values for the vectors cameraX and cameraY? Simply, the axes <1,0,0>, <0,1,0>?
and do you change angleX/angleY on key strokes?

further, what is ment by 'The more i turn to the side the less height i can acheive turning upwards'?
Rotating around the y-axis, right?
Offline Mike Jacobs

Junior Member





« Reply #4 - Posted 2006-03-12 05:17:25 »

... the whoel point of Quaternions is that they *don't* suffer from gimble lock.

Jeff is right if the Quaternion is used to represent an orientation.  On the surface, it appears that the quaternions may be used to represent axis rotations.  I included an overview of Java 3D quanternions in this article that might prove useful (http://jdj.sys-con.com/read/99792.htm).  The quaternions are covered in the section entitled 'Slicker than Euler' on page 3.

Mike

Special Effects for Java 3D games: http://www.indietechnologies.com
Offline arthor

Junior Newbie





« Reply #5 - Posted 2006-03-12 13:14:35 »

Thanks for the interest, as sugessted ive posted again in one of the 3d forums, JOGL to be specific, hopefully that is a better place for the question. Ive also answered some of the questions asked in the new post

http://www.java-gaming.org/forums/index.php?topic=12801.0
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.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (57 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!