### Author Topic: Rotating 3D and keeping everything happy.  (Read 2177 times)

#### Qube

• Mr. Polyvector
• Posts: 157
##### Rotating 3D and keeping everything happy.
« on: 2011-Nov-04 »
At the moment if you rotate a 3D object like so :

Code: (glbasic) [Select]
`// EXAMPLE 1x_movement x,y,zx_rotation rotx, 1, 0, 0x_rotation roty, 0, 1, 0x_rotation rotz, 0, 0, 1x_drawobj cube, 0`
We suffer from gimbal lock (is that the correct term)? - For example you can't set the object to point upwards and rotate on the Y axis and keep rotating on the X axis perfectly while manipuating y or z rotations, BUT if we do something like :

Code: (glbasic) [Select]
`// EXAMPLE 2x_movement x, y, zx_rotation rotx, 1, 0, 0x_pushmatrix   x_rotation roty, 0, 1, 0   x_rotation rotz, 0, 0, 0   x_drawobj cube, 0x_pushmatrix`
We can achieve the desired rotation of our object. We can then use x_getmatrix after the x_drawobj to get the coordinates of said object.

My question is this : How do I get the real angles rotx, roty, rotz from example 2 so I can draw other objects using the method in example 1?  I can't base the other objects inside the original push / pop matrix as they also get changed when the original object changes rotation, I need to be able to grab the x, y, z & the rotation angles for reuse.

I'm not sure if there are other bits from the output of x_getmatrix that I can use? I've looked but the don't seem to make much sense on how to use them apart from mat[12] / 13 & 14 which are the objects x,y,z.

Bit of a messy question but I think it makes sense?

#### Qube

• Mr. Polyvector
• Posts: 157
##### Re: Rotating 3D and keeping everything happy.
« Reply #1 on: 2011-Nov-06 »
um, ignore the above post, it's a load of messed up junk, lol

The only way to get rid of gimbal lock is to re-write all the rotation routines to use quaternions. I've no idea what they are and how they work (yet)  but they will solve the problem with GLBasics eular angles and good old gimbal lock.

Right, where did I leave my reading glasses, six pack of beer and thinking cap?

#### Hatonastick

• Dr. Type
• Posts: 474
##### Re: Rotating 3D and keeping everything happy.
« Reply #2 on: 2011-Nov-06 »
Hmm that's odd.  I just did a search for "Quaternion" and got no results, and yet I'm positive someone (maybe Hemlos) was working on such a thing.

Edit:  Egads...  5 minutes reading Wikipedia entries on Gimbal Lock, Euler Angles and Quaternion's and my head is spinning from all this math-ey stuff!
« Last Edit: 2011-Nov-06 by Hatonastick »
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

#### Hatonastick

• Dr. Type
• Posts: 474
##### Re: Rotating 3D and keeping everything happy.
« Reply #3 on: 2011-Nov-06 »
....  I just did a search for "Quaternion" and got no results, .....

Have you checked this board http://www.glbasic.com/forum/index.php?board=29.0  ?
It's even sticky!

Ocean
Gah!  Ok... As the females in my family put it: "I did a male look."
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).