Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Camera rotation (cont)  (Read 3427 times) 0 Members and 1 Guest are viewing this topic.
Porlus

Junior Devvie

 « Posted 2012-06-16 00:30:51 »

Hi, quick question. I hope the solution is as simple as I imagine. I've used the method at the bottom of this page: (http://www.songho.ca/opengl/gl_anglestoaxes.html) to perform rotations on each axis, which works exactly how I want. The problem I'm having with it is with roll rotations (z axis). X and Y work perfectly, but the roll seems to go in the same direction every time, as in left to right and it does so in the same direction regardless of other axis rotations.

 1  2  3  4  5  6  7  8  9  10  11  12  13 `    left.x = cy*cz;    left.y = sx*sy*cz + cx*sz;    left.z = -cx*sy*cz + sx*sz;    // determine up axis    up.x = -cy*sz;    up.y = -sx*sy*sz + cx*cz;    up.z = cx*sy*sz + sx*cz;    // determine forward axis    "forward.x = sy;    forward.y = -sx*cy;    forward.z = cx*cy;"`

Here's where I assume I'm making the error. I noticed the other two axis are determined by adding other axises. Is there something missing from this?

Thanks,
Paul
Porlus

Junior Devvie

 « Reply #1 - Posted 2012-06-19 14:33:11 »

I can elaborate if my explanation wasn't clear.
theagentd
 « Reply #2 - Posted 2012-06-19 18:45:54 »

I can elaborate if my explanation wasn't clear.

Myomyomyo.
Porlus

Junior Devvie

 « Reply #3 - Posted 2012-06-19 20:20:39 »

Ah, well at the moment I have 3 rotation angles around the x, y and z angles. The block of code above translates the rotation angles into a 3x3 rotation matrix. Everything works as expected, except when rolling on the Z axis (roll).

If I start the app when I'm at the default orientation, then perform a Z axis rotation, it works fine, however if I rotate 90 degrees around the Y axis first (yaw) and then perform the Z axis rotation it appears to perform the Z axis rotation as if the Y axis rotation hadn't taken place. So after rotating 90 degrees around the Y axis and then performing a Z axis rotation, the camera seems to forward roll.

So basically, any Z axis rotation ignores any other rotation (around X and Y) and just rotates as if it was rotated around the original orientation.
Sorry if that's a bit long-winded. Just trying to be descriptive.
sproingie

JGO Kernel

Medals: 202

 « Reply #4 - Posted 2012-06-20 01:57:50 »

Welcome to gimbal lock.
Porlus

Junior Devvie

 « Reply #5 - Posted 2012-06-20 02:43:18 »

Oh. So it's not a quick solution. I suppose rotation around the z axis isn't crucial to a 3D camera because with a mouse driven view there's no way to rotate about it. Would the solution be to not use Euler angles?
sproingie

JGO Kernel

Medals: 202

 « Reply #6 - Posted 2012-06-20 03:23:53 »

In a FPS, you'll rotate around Y (yaw), then X (pitch) and generally not bother with Z (roll) except maybe as a camera effect not under direct control of the player.  Sticking with just those two rotations shouldn't give you any problems with gimbal lock.
Porlus

Junior Devvie

 « Reply #7 - Posted 2012-06-20 03:27:39 »

Yeah I can't imagine many scenarios when I'd require a rotation around the Z axis. That said, would you recommend using another method such as quaternions?
sproingie

JGO Kernel

Medals: 202

 « Reply #8 - Posted 2012-06-20 03:42:19 »

I don't think quaternions buy you anything in this case.  They're more useful when you need to interpolate the motion from one angle to another, since euler angles are full of singularities like gimbal lock, and quats aren't.
Roquen

JGO Kernel

Medals: 517

 « Reply #9 - Posted 2012-06-20 05:14:12 »

Personally I think that quaternions are handy for all orientations.  The problem is that everyone insists on making them more complicated that is needed.  All orientations (in 3d) can be described by an axis and an angle and quaternions represent them in a stable, easy to manipulate and mostly trig free manner.  Axis/angle representation is really just an exponential mapping of quaternions BTW.
Porlus

Junior Devvie

 « Reply #10 - Posted 2012-06-20 05:36:56 »

Well yeah, I'm impartial to the method I use. If I can avoid gimbal lock by using quaternions then I'll find some resources on them. Before I have a google do you know of any good books or websites that cover them, preferably with a spin on camera orientation?
Roquen

JGO Kernel

Medals: 517

 « Reply #11 - Posted 2012-06-20 16:44:54 »

I don't know of any accessible description.  Really EVERYONE insist on making them more difficult than is needed.  I'd suggest looking at a lookAt matrix version first.  Basic sketch is you have a lookAt vector (direction the camera is facing) and a world up vector.  normalize(lookAt x UP) = right.  normalize(right x lookAt) = cameraUp.  Shove these into a matrix.  Breaks down when camera approaches straight up or down.  A quick websearch should yield various implementations.  (Something like graham-schmidt ... however their names are spelled..will slightly address some computation problems)
Pages: [1]
 ignore  |  Print

 ivj94 (583 views) 2018-03-24 14:47:39 ivj94 (48 views) 2018-03-24 14:46:31 ivj94 (374 views) 2018-03-24 14:43:53 Solater (61 views) 2018-03-17 05:04:08 nelsongames (108 views) 2018-03-05 17:56:34 Gornova (150 views) 2018-03-02 22:15:33 buddyBro (693 views) 2018-02-28 16:59:18 buddyBro (91 views) 2018-02-28 16:45:17 xxMrPHDxx (493 views) 2017-12-31 17:17:51 xxMrPHDxx (733 views) 2017-12-31 17:15:51
 SHC 10x NuclearPixels 10x Zemlaynin 10x KaiHH 10x ByerN 7x Spasi 6x Damocles 6x Guerra2442 6x VaTTeRGeR 5x ags1 4x orangepascal 4x philfrei 4x princec 3x ndnwarrior15 3x mesterh 3x Phased 2x
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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