Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  Camera rotation (cont)  (Read 2029 times)
0 Members and 1 Guest are viewing this topic.
Offline Porlus

Junior Devvie





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

Hi, quick question. Smiley 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
Offline Porlus

Junior Devvie





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

I can elaborate if my explanation wasn't clear. Smiley
Offline theagentd

« JGO Bitwise Duke »


Medals: 365
Projects: 2
Exp: 8 years



« Reply #2 - Posted 2012-06-19 18:45:54 »

I can elaborate if my explanation wasn't clear. Smiley
Please do... I have no idea what you're asking about...  persecutioncomplex

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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. Smiley Just trying to be descriptive.
Offline sproingie

JGO Kernel


Medals: 202



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

Welcome to gimbal lock.
Offline Porlus

Junior Devvie





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

Oh. Sad 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?
Offline 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. 
Offline 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?
Offline 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.
Offline 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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?
Offline 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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