Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Quaternion Rotations in 3D Java OpenGL  (Read 12024 times)
0 Members and 1 Guest are viewing this topic.
Offline croft

Junior Member




Java, Java, Java


« Posted 2008-09-29 02:10:08 »

I created the tutorial "Quaternion Rotations in 3D Java OpenGL" to document a 3D math library that I wrote a few months ago. It includes an interactive demonstration applet and links to the javadoc and source code.
http://www.croftsoft.com/library/tutorials/quat/

David Wallace Croft / www.CroftSoft.com / (214) 636-3790 m / Advanced Java Game Programming
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2008-09-29 02:20:25 »

Ooh, nice, Quaternions are difficult to understand, this tutorial looks good.

See my work:
OTC Software
Offline gouessej
« Reply #2 - Posted 2008-09-30 07:27:52 »

I created the tutorial "Quaternion Rotations in 3D Java OpenGL" to document a 3D math library that I wrote a few months ago. It includes an interactive demonstration applet and links to the javadoc and source code.
http://www.croftsoft.com/library/tutorials/quat/
Thank you very much. It would be fine if you explained the way to use quaternions to avoid gimbal lock by using non eulerian transforms as many books and tutorials tell wrong things about it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #3 - Posted 2008-09-30 18:47:49 »

Quote
Thank you very much. It would be fine if you explained the way to use quaternions to avoid gimbal lock by using non eulerian transforms as many books and tutorials tell wrong things about it.

I always had trouble to understand what the exact problem with gimballock ?? and I still use euler angle for their simplicity.

I mean if you want to rotate an object around all its three axis you must also rotate its local axis  the same way as the object and that's all => no gimbal lock ?? dont know who invent the term of "gimbal lock" but it seems to be a confusion between world axis and local axis.


so when you have an object in 3d space you can set it in any 3D positions by using two Vector3D()
one for translation :
tx,ty,tz
one for rotation :
rx,ry,rz

than you set your object and its local axis by applying rx,rz,ry and translate it using tx,ty,tz


if you want to apply a rotation around x "world axis" and than around y "world axis" and etc.. you simply apply your rotation wrx, than wry. and etc... but if you want to rotate around its local axis x than its local axis y you must keep in mind that the rx rotation will have also rotate the object local axis and you should not use a world rotation to achieve rotation in object space (there is the confusion I told aboout local and world axis), it is only valid for the first rotation when local and world axis are still "equals".

if you want to rotate it around one of its local axis (so in object space) and you have no idea of the local rotation rx,ry,rz, you have to compute it using the above code and its local axis (you can create one on the fly choosing arbitrary axis x, axis y,axis z all perpendicular, but it is better to keep trace of object real local axis), than apply rotation you want and re-apply retrieved rotation of its local axis rx,rz,ry.

The problem is not really that a dimension of rotation is lost but rather that three rotation is too much to set an objet local axis, so you don really loose a dimension, you still have it, or rather "you dont need it".

only euler, no quaternions, and no "gimbal lock"


the above code may help :
cax,cay,caz are the three vector3D that represent the local axis of an object in world space, (they must translated to the origine and normalized).

the function then give the three rotation that you must apply in the following order RX,RZ,RY to get the same axis.

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  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
      
double axx=cax.getX();      
double axy=cax.getY();
double axz=cax.getZ();
double ayx=cay.getX();      
double ayy=cay.getY();
double ayz=cay.getZ();      
double azx=caz.getX();  
double azy=caz.getY();
double azz=caz.getZ();
double den=Math.sqrt((axx*axx)+(axy*axy)+(axz*axz));
double sz=-axy/den;

     
double rz=0.0;

//floating value precision bug handle
if(sz>1.0) sz=1.0;
if(sz<-1.0) sz=-1.0;

rz=Math.asin(sz);
 
den=Math.sqrt((axx*axx)+(axz*axz));

//floating value precision bug handle
if(den>1.0) den=1.0;
double rx=0.0;
double ry=0.0;
if(Math.abs(den)>0.0);
{
   double cx=ayy/den;        
   if(cx>1.0) cx=1.0;
   if(cx<-1.0) cx=-1.0;
   rx=Math.acos(cx);
   if(azy<0.0)
    rx=-rx;
             
   double cy=axx/den;        
   if(cy>1.0) cy=1.0;
   if(cy<-1.0) cy=-1.0;              
   ry=Math.acos(cy);
   if(axz<0.0)
    ry=-ry;
}
     
if(Math.abs(rx)>Math.PI*0.5 && Math.abs(ry)>Math.PI*0.5)
{
   rx=-Math.PI+rx;
   ry=-Math.PI+ry;
   rz=Math.PI-rz;
}


NB.: the code above may have severals optimisations, let me know

EDIT:
for 3d modeler studio users (as 3ds max)  => this is why when you rotate an object  most of the time the three rotations are updated

Offline gouessej
« Reply #4 - Posted 2008-10-01 05:36:13 »

I always had trouble to understand what the exact problem with gimballock ?? and I still use euler angle for their simplicity.
Watch the FAQ about quaternions on www.developpez.net, I answered to this question. It is not easily possible to avoid gimbal lock with euler angles, I proved it scientifically some years ago and Pascal Mignot (teacher and researcher at the university of Reims) confirmed I was right:
http://jeux.developpez.com/faq/matquat/

Then, your engine can suffer of gimbal lock...

Offline DzzD
« Reply #5 - Posted 2008-10-01 07:51:59 »

of course it is impossible as the "gimbal lock" term "is something logically wrong", it is like saying when I do Math.sin(90) the result is not 1.0 so it is a wrong result ? no it isn't if you think that the parameter should be given in radian.

the gimbal lock is the same as above, it is a confusion on space between object space operation and world space operation (confusion on unit in above example), read back the post I think it is well explained.

Quote
It is not easily possible to avoid gimbal lock with euler angles, I proved it scientifically some years ago and Pascal Mignot (teacher and researcher at the university of Reims) confirmed I was right:

hehe no, I no, there is no trouble with gimbal lock in my engine (the main reason is that it doesn't really exist!), taking care of what I wrote above you can get ride of gimbal lock problem with euler.... in short: you just have to keep in mind that when you perform an operation rotation/translation you modify the object local axis, it is as simple...

Offline gouessej
« Reply #6 - Posted 2008-10-01 10:51:41 »

of course it is impossible as the "gimbal lock" term "is something logically wrong", it is like saying when I do Math.sin(90) the result is not 1.0 so it is a wrong result ? no it isn't if you think that the parameter should be given in radian.
I don't know what you mean.

hehe no, I no, there is no trouble with gimbal lock in my engine (the main reason is that it doesn't really exist!), taking care of what I wrote above you can get ride of gimbal lock problem with euler.... in short: you just have to keep in mind that when you perform an operation rotation/translation you modify the object local axis, it is as simple...

Gimbal lock exists even though you wish to give this phenomenon another name. I agree with you, you have to preserve the local reference to solve this problem, that is what I wrote in the FAQ but I don't see how your code solves the problem (it would be better with more comments). I debated with many people who suggested wrong solutions, for example using matrices instead of Euler angles, using quaternions but in the same way than Euler angles and I spent some time to prove that it fails, I hope I won't have to do it again.

If you're really sure you have no gimbal lock, show your piece of code to Pascal Mignot but I assume he might agree with me. Give a formal proof (a mathematic demonstration) that your method works as I did for mine some years ago.

Offline DzzD
« Reply #7 - Posted 2008-10-01 11:30:16 »

Quote
Gimbal lock exists even though you wish to give this phenomenon another name. I agree with you, you have to preserve the local reference to solve this problem, that is what I wrote in the FAQ. But I'm not sure that your code solves this problem, I haven't checked it mathematically.
ok if you want it exist, but it is not a problem or anything else that just a logical misundertood, that when you rotate one of three axis of an object (90°) it get parallel to one other axis in world space....

another thing is that you can perform arbitrary axis rotation using only euler :

Get an arbitrary axis in 3d space (the one you want to use to rotate around and represented by two 3d point)

V=P1-P2;

Compute its translation to the world origin : Tx,Ty,Tz

Compute the two world rotation rx & ry that you must apply to the world axis z so that it will then lie on your choosen rotation axis (like the code above, but only requiere to know rx,ry or rx,rz or ry,rz)

Once done,  you can rotate any 3d point around this vector using the following sequence of rotation and translation.

V.translate(-T)
V.rotX(-rx);
V.rotY(-ry);
V.rotZ(rz); // here you are working in a snipet of local object space (not the whole one) you can apply any rotation you want around Rz and translation Tz, other rotations & translation are invalid as the local object space is not complete
V.rotY(rx);
V.rotX(ry);
V.translate(T);

Quote
I don't see how your code solves the problem

I will make a draw/graphic, It is really simple and logic but hard to explain in simple-text.

add four vertex to your object with the following value :
o(0,0,0);
ax(1,0,0);
ay(0,1,0);
az(0,0,1);

wouaou a matrix !

once you will have performed any 3d operation on your object including rotation, translation and even zoom!! as many times as you want and in any order you wanted, you will still be able to get back the local object axis using the above code and the fourth new axis vertices, and so rotate around any of the three axis you want.



Offline gouessej
« Reply #8 - Posted 2008-10-01 14:05:18 »

V.rotX(-rx);
V.rotY(-ry);
V.rotZ(rz);
It can cause gimbal lock in some cases. You don't prove anything, it is not a demonstration.

Offline DzzD
« Reply #9 - Posted 2008-10-01 14:29:58 »

no.... it can't... you can set a vector looking in any direction with two rotations, apply those rotations in revers order and in the oposed sens you can make the inverse transform..... damn... this is so logic, dont understand your "reticence".

Quote
It can cause gimbal lock in some cases. You don't prove anything, it is not a demonstration.

I am talking of world space rotation so you only rotate around (1,0,0), (0,1,0), or (0,0,1) no possibilities that two axis get merged. ok I have no time right now I will post a proper explaination tonight

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #10 - Posted 2008-10-01 18:22:25 »

See picture below

Object Local Axis is defined by four Points :
O (origine)
AX (Axis X)
AY (Axis Y)
AZ (Axis Z)


Full method to rotate around ax object axis
(but that is the same for any arbitrary axis),
some pass are ofcource unecessary but for educational purpose that's better :

- compute T : translation of O to world origin) => O as world origin == 0,0,0
- compute R : rotation sequence RX,RZ,RY all applyed in WORLD SPACE

ok want to rotate around ax ? perform the following to the point you want to rotate :
let's call the point to rotate P

//First get back in object space
P.Translat(-T)
P.RY(-ry);
P.RZ(-rz);
P.RX(-rx);

//Rotate point with desired angle
P.RX(arbitrary angle around RX)

//Go back to world space
P.RX(rx);
P.RZ(rz);
P.RY(ry);
P.Translat(T)

this is the long method....

knowing the local object axis in world space you
can easily set any vertices on this axis so you will
only perform transformation on the object local axis and then
use this axis for example to set vertice at render time.

below a sample code that rotate a point around an arbitrary axis
(starting at world orign, requiere only to add two translation -T and +T
for any arbitrary axis that not start at world origin)

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  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
public class Point3D
{

public double x,y,z;

public Point3D rotate(double angle,double x,double y,double z)
{
     
   //normalize axis in case of
  double n=Math.sqrt(x*x+y*y+z*z);
   if(n==0.0) return this;
   double in=1.0/n;
   x*=in;
   y*=in;
   z*=in;
     
   double nzx=Math.sqrt(x*x+z*z);

   double rx=Math.asin(y);
   double ry=0;
   if(nzx!=0.0)
      {
      ry=-Math.acos(z/nzx);
      if(x<0)
      ry=-ry;
   }
   else
   {   if(y>0)
         rx=Math.PI*0.5;
      else
         rx=-Math.PI*0.5;
      ry=0;
   }

   //Add here the -T translation for arbitrary axis (not starting at 0,0,0)
  this.rotateY(-ry);
   this.rotateX(-rx);
   this.rotateZ(angle);
   this.rotateX(rx);
   this.rotateY(ry);
   //Add here the +T translation for arbitrary axis (not starting at 0,0,0)
  return this;
   
}

//rotate around world x axis
public Point3D rotateX(double angle)
{
   double tY=y,tZ=z;
   double cosa=Math.cos(angle);
   double sina=Math.sin(angle);
   y=tY*cosa + tZ*sina;
   z=-tY*sina + tZ*cosa;
   return this;
}
   
//rotate around world y axis
public Point3D rotateY(double angle)
{
   double tX=x,tZ=z;
   double cosa=Math.cos(angle);
   double sina=Math.sin(angle);
   x=tX*cosa - tZ*sina;
   z=tX*sina + tZ*cosa;
   return this;
}
   
//rotate around world z axis  
public Point3D rotateZ(double angle)
{
   double tY=y,tX=x;
   double cosa=Math.cos(angle);
   double sina=Math.sin(angle);
   x=tX*cosa + tY*sina;
   y=-tX*sina + tY*cosa;
   return this;
}
}



not optimised, not tested too Smiley but working code...

ex rotate PI/4 around the line l(t)=tx,ty,tz with x,y,z = 1, so we rotate 45° around an axis that start at 0,0,0 and finish at 1,1,1:
Point p=new Point3D();
p.x=200;
p.y=100;
p.y=50;
p.rotate(Math.PI*0.25,1.0,1.0,1.0);

p.x,p.y,p.z==rotated values

EDIT:

as the translation can be outsided so let's rotate around a line that goes from P1 to P2 :
p.x-=p1.x;
p.y-=p1.y;
p.z-=p1.z;
p.rotate(Math.PI*0.25,p2.x-p1.x,p2.y-p1.y,p2.z-p1.z);
p.x+=p1.x;
p.y+p1.y;
p.z+=p1.z;

oki.. better to add a "add" method...
1  
2  
3  
4  
5  
6  
public Point3D plus(Point3D p)
{
 this.x+=p.x;
 this.y+=p.y;
 this.z+=p.z;
}


and a sub one

1  
2  
3  
4  
5  
6  
public Point3D sub(Point3D p)
{
 this.x-=p.x;
 this.y-=p.y;
 this.z-=p.z;
}


finaly

p.sub(p1).rotate(Math.PI*0.25,p2.x-p1.x,p2.y-p1.y,p2.z-p1.z).add(p1);

Offline DzzD
« Reply #11 - Posted 2008-10-01 18:55:36 »

below an online sample of rotating around arbitrary angle :

http://demo.dzzd.net/Viewer3D/

the object will rotate in the sens of the mouse drag , so around an axis that lie on the camera screen and wich is perpendicular to the user mouse drag, axis is computed each frame, so rotation is around a dynamic axis if you are not dragging in a straight line.

it achieved by the following :
1) get the active camera
2) put object axis in camera space
3) rotate around the axis defined by user drag
4) compute and update the object rotation rx,ry,rz

Offline aldacron

Senior Member


Medals: 9
Exp: 16 years


Java games rock!


« Reply #12 - Posted 2008-10-02 04:12:51 »

I always had trouble to understand what the exact problem with gimballock ?? and I still use euler angle for their simplicity.

I mean if you want to rotate an object around all its three axis you must also rotate its local axis  the same way as the object and that's all => no gimbal lock ?? dont know who invent the term of "gimbal lock" but it seems to be a confusion between world axis and local axis.

The term "gimbal lock" comes from the physical world. It describes the condition in gimbal systems where you lose one degree of freedom (i.e., the ability to rotate around one particular axis). In software it can be an issue when using a rotation system based solely on Euler angles if you don't account for it. You may never see it, but it's certainly possible since it's an inherent characteristic (which quaternion rotations don't have) of gimbal systems (simulated and physical). A real-world example of a near-gimbal-lock situation occurred on the Apollo 10 mission in May, 1969.

Quote
After Stafford's camera failed, he and Cernan had little to do except look at the scenery until time to dump the descent stage. Stafford had the vehicle in the right attitude 10 minutes early. Cernan asked, "You ready?" Then he suddenly exclaimed, "Son of a bitch!" Snoopy seemed to be throwing a fit, lurching wildly about. He later said it was like flying an Immelmann turn in an aircraft, a combination of pitch and yaw. Stafford yelled that they were in gimbal lock - that the engine had swiveled over to a stop and stuck - and they almost were. He called out for Cernan to thrust forward. Stafford then hit the switch to get rid of the descent stage and realized they were 30 degrees off from their previous attitude. The lunar module continued its crazy gyrations across the lunar sky, and a warning light indicated that the inertial measuring unit really was about to reach its limits and go into gimbal lock. Stafford then took over in manual control, made a big pitch maneuver, and started working the attitude control switches. Snoopy finally calmed down.


I've read that there are several instances in the Apollo records and flight logs where pilots had to make special maneuvers to avoid gimbal lock. So yes, it's a real problem, though the consequences aren't severe in 3D graphics programming Smiley
Offline DzzD
« Reply #13 - Posted 2008-10-02 12:59:06 »

thank that's very interristing, I will now try to read that to understand what it exacly mean Smiley, as I still dont understand what the problem and when it can occur

EDIT: I got it Smiley, this can happen when yaw, pich, roll are dependent each other as in the gimbal system , so I believe that's not applyable when you are in a software and can magically rotate around anywhere without your axis behing really linked to something and then imediatly reorder all your axis wich is not possible in real life.

Click to Play

Quote
the left, you can see how each gimbal allows rotation around a specific axis. On the right, you can see a set of gimbals in gimbal lock. The inner-most gimbal can't change in pitch unless someone puts the gimbals into another position.

Offline gouessej
« Reply #14 - Posted 2008-10-02 18:20:55 »

You may never see it, but it's certainly possible since it's an inherent characteristic (which quaternion rotations don't have) of gimbal systems (simulated and physical).
It is not completely true. Gimbal lock is an inherent characteristic of eulerian transforms whatever you use (Euler angles, matrices, quaternions). The gimbal lock can be avoided by using non eulerian transforms that are easier to express with quaternions. That means that if you use quaternions with eulerian transforms (for example if you convert quaternions to matrices or Euler angles or if you combine them the same way as you already do with Euler angles), you can still have gimbal lock, I made a demonstration of it some years ago, my conclusions have been checked and approved, some FAQ reuse them now.

Offline DzzD
« Reply #15 - Posted 2008-10-02 22:12:57 »

no, because can set an object in any position with euler angle ... in real life there is some situation you wont be able to rotate in some direction, because in real life you cannot reorder your axis "immediatly".

but in computer programming you can recompute you three rotation so that the object seems to have rotated in the direction you wanted to (any direction even the one that is impossible in gimbal shem above), wich is impossible in real life because it requiere that the object pass some other orientation before reaching this new position and that "immediatly".

Quote
Euler angles are a means of representing the spatial orientation of any frame of the space as a composition of rotations from a reference frame.

and this is true, you can set an object in any position with the combinaison of three rotation, and in computer you can pass from one to another  immediatly, wich is impossible in real life, that's all !

the applet provided above that let you rotate the object in any direction use a combinaison of three rotation exacly as the gimbal system with three axis above, but all three rotations are re-computed each time, this cause jump from one pos to another some time but the object rotate smoothly and is rotated using ONLY three rotation (euler angles). you have a working sample, what do you want more, next week, I will add the three gimbal, to show the same gimbal system as above arround the rotated object in the applet. each of them representing rx,ry,rz and so you will be able to see those while smoothly rotating the object even when it is in the gimbal lock position.


EDIT:
note that then you can also compute any euler transformation between one posistion to another by doing : new rx- last rx,new ry-last ry,new rz - last rz. and I guess that when rotating an object and passing a gimbal lock pos some rotation should make a "big jump", but who care... we are not in a real ship!!


Offline gouessej
« Reply #16 - Posted 2008-10-03 05:43:36 »

no
Is it a demonstration? I worked 6 months on this problem and you seem not to understand what gimbal lock is as you said at the beginning of this topic. The problem comes from eulerian transforms. If you combine your rotation with this, there is a risk to obtain gimbal lock.

Offline DzzD
« Reply #17 - Posted 2008-10-04 09:49:29 »

Quote
Is it a demonstration?
no but the following is enought for me : "no, because can set an object in any position with euler angle ..." proof me that 1+1=2 ??

Quote
I worked 6 months on this problem and you seem not to understand what gimbal lock is as you said at the beginning of this topic.

maybe just explain me why it can be a problem in 3d software ??, that's rather that  that I dont understand...

Quote
The problem comes from eulerian transforms. If you combine your rotation with this, there is a risk to obtain gimbal lock.

and what is afraying in that Huh you will still be able to rotate in any direction....

this seems so simple that I dont understand we have to debat hours on this, so there could be two reasons : I dont understand what you said or you dont understand what I said, so please explain me in a short way a case where a gimbal lock can lock anything in software, or can cause a problem ??

let's take a trivial case using rx,ry,rz. we take rx=90 & ry=90 so that we should be locked, what I said is just that we are not because we can still go in any other position.

it maybe as follow (but it depend on you choosen axis and sens for rotation to work with eg : x at right, x down, etc..., anyone can choose its own axis to works with) :

rx=90,ry=90,rz=0   ==   rx=90,ry=0,rz=90 == etc...

an object can be set in the same pos using differents combinaison for rotation, (this is why I said earlier that three rotation is too much.)

do you follow?? but even without that, if you agree with the fact that you can set an object in any 3d rotation position with euler angle (wich is true, no ?) you cannot disagree with the fact that you can go from one rotation pos to another at anytime, this is only logic.... and trivial.... and the way to go from one to another is just being able to rotate around an arbitrary axis, and you have one of the differents ways you can use to do that implemented in the code above.






Offline gouessej
« Reply #18 - Posted 2008-10-04 11:20:05 »

and what is afraying in that Huh you will still be able to rotate in any direction....
No, that's the point Sad you lose at least a degree of freedom. This is not a trivial problem, I needed some months to understand it, it was very difficult and plenty of people told me things that were in contradiction  Angry. If you want, I can send you an extract of my report (in French  Grin), maybe it could help you. I have a source code in C++ that implements the good formula (under GPL license).

Offline aldacron

Senior Member


Medals: 9
Exp: 16 years


Java games rock!


« Reply #19 - Posted 2008-10-04 12:11:37 »

this seems so simple that I dont understand we have to debat hours on this, so there could be two reasons : I dont understand what you said or you dont understand what I said, so please explain me in a short way a case where a gimbal lock can lock anything in software, or can cause a problem ??

let's take a trivial case using rx,ry,rz. we take rx=90 & ry=90 so that we should be locked, what I said is just that we are not because we can still go in any other position.

it maybe as follow (but it depend on you choosen axis and sens for rotation to work with eg : x at right, x down, etc..., anyone can choose its own axis to works with) :

rx=90,ry=90,rz=0   ==   rx=90,ry=0,rz=90 == etc...

an object can be set in the same pos using differents combinaison for rotation, (this is why I said earlier that three rotation is too much.)

do you follow?? but even without that, if you agree with the fact that you can set an object in any 3d rotation position with euler angle (wich is true, no ?) you cannot disagree with the fact that you can go from one rotation pos to another at anytime, this is only logic.... and trivial.... and the way to go from one to another is just being able to rotate around an arbitrary axis, and you have one of the differents ways you can use to do that implemented in the code above.

Yes, you can adjust the angles at any time, clear and reset matrices and whatever you want. That doesn't prevent gimbal lock from rearing its head, but can open up doors to avoiding it. But this isn't an imaginary problem that goussej is making up. It's a real issue that is common in 3D graphics. You'll find it being discussed in a number of graphics books.

The point you seem to be missing is that those Euler angles need to be applied to the object you are rotating. Whether you let the graphics API handle it or you do it yourself, they are going to be applied one at a time. When rotations are performed sequentially, it's possible for one axis to become aligned with another. The order in which rotations are applied can affect whether or not gimbal lock occurs, so there are ways you can avoid it. This page has a couple of suggestions. The main reason that you don't see gimbal lock with quaternions is that the rotations are essentially applied simultaneously.
Offline DzzD
« Reply #20 - Posted 2008-10-04 12:40:43 »

Quote
The point you seem to be missing is that those Euler angles need to be applied to the object you are rotating

yep I believe I probably missed something...


ok, I try to better explain myself:

your object rotation is set using the following sequence of rotation rx,ry,rz (euler ok ?)
you can go in a pos A with euler angle but you can also go in a pos B ok ?
so to go from A to B it is rx+=rxb-rxa, ry+=ryb-rya, rz+=rzb-rza ok ?
and what you have to do is to compute  rya,ryb,rzb and that can be achieved

you can go from one pos to another applying rx+=drx,ry+=dry,rz+=drz, no ?

once again I really dont understand why you point that one (link)
Quote
the last axis is processed one of the axis could be aligned to another,
this is not possible as explained above Axis are rigid, you cant rotate one without rotate the two other, or you are confusing world and local space.

when you rotate in any direction you began to influence other rotation, as if you rotate around x and around y then the amount you rotate around y depend about the rotation you made around x basically
rotate arround x==0 => your axis are aligned and rotating around y is not affected 100%
but when you start to increase rx it become false and rotation around y is no more 100% it decrease and reach 0 at 90°. the gimbal lock is just the end of a degenration of your rotation axis, but this doesn't lock anything and this particulary does'nt avoid any rotation even if you set your object rotation using three consecutive world space rotation.

EDIT:
ps: I was just asking what problems it can cause (this is this point that I missed the most)?


but finally you point that one too, with one I fully aggree.

Quote
To avoid Gimbal lock completely checks need to be placed in code whenever there is a chance of it occurring, or alternatively a different way of rotating can be used

but once again, this seems for me to results from a confusion ( or probably mine confusion ) about performing a world or a local object space rotation. because once you have made one rotation even small all your axis become not aligned to world one and so performing any more rotation doesn't make what you expect it should do, but this become to be true when you start any rotation, I mean if you call pitch the rotation around x and you have performed a roll rotation before, your picth rotation is affected and is already false and become completly false (0%) at 90% because you try to perform a rotation in world axis and one of your ocal axis has become coolinear to a world axis wich is different then the one it was colinear with at init time.

so when your perform the sequence rx,ry,rz you must keep in mind that it is not directly local rx,ry,rz and that if you want to rotate around any of the three axis x,y,z you have to read it back not increase rx or ry or rz. but that's only a confusion if you try to do such (IMHO)


NB: I believe it exist , ofcourse, as I have hear this term a lot of time,but what I am just trying to understand is when ? it cause problem and how ? in 3D software as I understand the problem in a gimbal system as above but not why it should/can be same in 3D software that allow us to put an object in any other rotation pos immediatly and so to rotate to any pos at anytime.


Offline DzzD
« Reply #21 - Posted 2008-10-04 13:42:16 »

 my question is more what do you mean ? what anybody means when he said "It can suffer of gimbal lock" or something like "you may have a gimbal lock" etc ? what's happend then ? I have developped a 3d software that use only euler positioning (I thinks this is that) and if I am going to suffer from anything I want to know, do I will have scare on my skin or anything else, what does that mean in 3D software and what problems it can cause ? my research is more to know if I have to care about that ?

EDIT:
seems there is a good explanation on difference of local and world there : http://en.wikipedia.org/wiki/Euler_angles#Other_composition_of_movements_equivalent

and this section is interresting too :
http://en.wikipedia.org/wiki/Euler_angles#Matrix_notation


also an other problem then the gimbal system lock is described there but once again not applicable to 3d software :
Quote
For example, assume a level sensing platform on an aircraft flying due north has its three gimbal axes mutually at right angles, i.e., Roll, Pitch and Yaw angles each zero. If the aircraft pitches up 90 degrees, the plane's and platform's Roll axes become parallel to the Yaw axis, and changes about Yaw can no longer be compensated for. This problem may be overcome by use of a fourth gimbal, driven so as to maintain a large angle between Roll and Yaw gimbal axes.
http://en.wikipedia.org/wiki/Gimbal_lock

and about quaternion and euler this one can help :
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

Offline gouessej
« Reply #22 - Posted 2008-10-04 17:19:19 »

Angry Using quaternions like Euler angles and converting them into Euler angles at the end doesn't solve the problem.

Watch this (it is a bit approximative about the matrices):
http://www.univie.ac.at/cga/faq/angles.html

Offline DzzD
« Reply #23 - Posted 2008-10-05 21:56:37 »

Quote
Using quaternions like Euler angles and converting them into Euler angles at the end doesn't solve the problem.
I trust you that it doesn't, but this would be easier to know what problem we are talking about ? I never had anyproblem with quaternion or euler ....

Offline gouessej
« Reply #24 - Posted 2008-10-06 13:47:28 »

I trust you that it doesn't, but this would be easier to know what problem we are talking about ? I never had anyproblem with quaternion or euler ....
I spoke about the gimbal lock, I thought it was obvious.

Offline irreversible_kev

Junior Member





« Reply #25 - Posted 2008-10-06 14:59:00 »

I spoke about the gimbal lock, I thought it was obvious.

Lets say the user of the software doesn't know about Gimbal Locks, what inconvenience or practical problem will the presence of a Gimbal Lock create for the user?

In other words, why does the user of DzzD's programs (rather than DzzD) care about whether or not his code might have Gimbal Locks?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #26 - Posted 2008-10-06 19:39:26 »

Let's say you have this skeleton. You make a node tree of the limbs. Now when some nodes have specific angles, it becomes impossible to rotate the sub nodes along a certain axis.

At least, that was why I read up on Gimbal Lock to keep my little robot men walking across the screen pointing at stuff and grabbing things.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #27 - Posted 2008-10-07 11:51:32 »

Quote
In other words, why does the user of DzzD's programs (rather than DzzD) care about whether or not his code might have Gimbal Locks?
yup, that's exacly the question, aswell as why it is said something like "3d studio max suffer from gimbal lock"..., I use this software and other 3d tools and never had trouble on rotations.

Quote
Let's say you have this skeleton. You make a node tree of the limbs. Now when some nodes have specific angles, it becomes impossible to rotate the sub nodes along a certain axis.
ok, so I assume it is a lock on rotation that made impossibility to rotate in one direction when certain condition are meet ?

the first idea I had about software gimbal lock was like Riven explanation : impossibility to rotate on certain condition. but I get some doubt after making further research on it, there is not really an official and clear explanation of what is a 3d software gimbal lock.

Making some further research on gimbal lock due to this thread it seems that it is become a term used in a lot of differents situations, and it is now clear for me that it is logical in the reallity as the gimbal system or the plane example.

so we can say that in 3d software it is used to define a situation of being unable to rotate in one direction wich seems to be the most used to define gimbal lock in 3d software.

so what I have tried to explain before is that : "being unable to rotate in one direction" is not related to the use of euler angle, euler angle doesn't cause any lock while you know in wich space you are working
and what you are doing and while you keep in mind that performing the following world rotation rx,ry,rz is different to perform the following local rotation rx,ry,rz.

and "being unable to rotate in one direction" is just a very logical consequence of trying to rotate around an axis wich is not the one you think it is.

eg: a plane that is going straight down (nose going very down)
rotate in world space around y (with y up) it rotate in local space around z (with y forward) but rotating in local space around y make the plane turn right or left.
and if the plane is going forward all is magicaly working fine in local aswell as in world space.

NB: sorry If you find me too long on that subject, but I found it is a lot more interresting that it appear at first and I really want to understand the whole problem....


Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #28 - Posted 2008-10-07 19:38:33 »

Maybe the following example will help:

First of all: (0,1,0) is up

Again, we have that skeleton, and we want to control the hand, which is attached to the lower arm, the upper arm, the shoulder/torso.

Without rotation each arm stretches to each side (-X .. +X), with the back of the hands facing up. Now rotate the shoulder/upperarm joint 45deg, so that there is an angle of 90deg between the arms. Now rotate the upper/lower arm joints 90 deg - the 2 upper arms and 2 lower arms form a rectangle now, pointing forward. Rotate the upper arms 60deg down. The skeleton is now standing as if he holds his belt.

Now try rotating the hands on the axis of the lower arm. (the Y axis in local space, as the hands go 'up' from the lower arm).

And indeed, this has nothing to do with euler angles, as you get the exact same problem with matrix concatenation.



For clarity, this is what your scenegraph would look like:

1  
2  
3  
4  
5  
6  
7  
torso
 - translate along +X axis (neck to R shoulder joint), make rotations rotate, attach upper R arm
    - translate along +Y axis (shoulder to upper/lower arm joint), make rotations rotate, attach lower R arm
       - translate along +Y axis (upper/lower arm to hand joint), make rotations rotate, attach R hand
 - translate along -X axis (neck to L shoulder joint), make rotations rotate, attach upper L arm
    - translate along +Y axis (shoulder to upper/lower arm joint), make rotations rotate, attach lower L arm
       - translate along +Y axis (upper/lower arm to hand joint), make rotations rotate, attach L hand

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #29 - Posted 2008-10-07 21:49:34 »

I try to understand.... but get stuck on : "Now rotate the upper/lower arm joints 90 deg", what next ?

EDIT: step 3 ok ?

EDIT 2: I have modelized a gimbal system, so box is linked/child to the yellow axis, yellow axis is linked/child to blue gimbals , blue child of green gimbals and green child of red gimbal, all object are shown with rotation==0

so what can I do that will produce the lock bug (the 3ds file is available, just rename gimbals.3ds.txt to gimbal.3ds) ?

Pages: [1] 2
  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.

CopyableCougar4 (23 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!