Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (574) Games in Android Showcase (154) games submitted by our members Games in WIP (620) 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 2117 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

« JGO Bitwise Duke »

Medals: 426
Projects: 2
Exp: 8 years

 « 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
 « 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
 « 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

You cannot reply to this message, because it is very, very old.

 Riven (27 views) 2015-04-16 10:48:47 Duke0200 (42 views) 2015-04-16 01:59:01 Fairy Tailz (30 views) 2015-04-14 20:13:12 Riven (33 views) 2015-04-12 21:36:37 bus hotdog (49 views) 2015-04-10 02:39:32 CopyableCougar4 (51 views) 2015-04-10 00:51:04 BurntPizza (51 views) 2015-04-06 22:06:58 ags1 (53 views) 2015-04-02 10:58:48 Riven (52 views) 2015-04-01 18:27:05 ags1 (69 views) 2015-03-31 10:55:12
 theagentd 24x BurntPizza 20x wessles 15x 65K 11x kingroka123 11x Rayvolution 11x alwex 10x KevinWorkman 9x kevglass 8x phu004 8x chrislo27 8x Hanksha 7x SHC 7x ra4king 7x Olo 7x Roquen 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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