Camera Rotation and Gimbal Lock

Software: Away3D 4.x

Beek, Member
Posted: 08 March 2015 04:04 AM   Total Posts: 67

HI,

I’m attempting to manipulate some controls based on the camera roll (z).

The camera is controlled by device motion and a Quaternion.  Anything I do to access this Quaternion, copying it, cloning it etc seems to change how it’s applied to the camera, so I decided to read the data from the camera itself.

At first just getting camera.rotationZ seemed OK,  however it soon transpired when the camera is rotated around the Y axis the X and Z flip. So I did some crazy hacks to get around that:

var camera.rotationZ;
      var 
camera.rotationX;
      var 
camera.rotationY;

    
90 
     
- (180)
     : 
z;
    
< - 90
     
- (180)
     : 
z;
    
    
90 
     
180
     
x;
    
< - 90
     
180
     
x

 
Which is kind of working.

Now I’m stuck with what I’m assuming is a Gimble Lock, where if Y is near 90 or -90, X and Z go nuts and trigger my functions.

I assume it would be better to use the camera matrix, however converting that to Eulers seems to have the same affect.

I saw another post where someone created a matrix and applied each rotation in order with Y as the upVector, and this didn’t seem to help with this issue either.

Basically I want to catch if the camera has rolled 45 degrees either way, or is pointing straight down.

Any better way of achieving this?

   

JaykopX, Newbie
Posted: 08 March 2015 07:15 PM   Total Posts: 13   [ # 1 ]

Basically I want to catch if the camera has rolled 45 degrees either way, or is pointing straight down.

If you mean with pointing straight down==“looking on the floor”
you can achieve this by checking the forwardVector of the camera:

var tolerance:Number 0.1;
//checking how close we are to the looking-down-vector (0, -1, 0)
   
if(Math.abs(view.camera.forwardVector.x) <= tolerance{
    
if(Math.abs(view.camera.forwardVector.z) <= tolerance
     
if(Math.abs(-view.camera.forwardVector.y-1) <= tolerance{
      trace
("Looking down");
     
}
    }
   } 

where tolerance is between 1.0 and 0.0 and triggers the “look down” notification sooner(1.0==always) or later(0.0==only if exacly looking down).

For the rolling you could keep track of the leftVector. It should be a bit trickier, i maybe look into it.

   

Beek, Member
Posted: 08 March 2015 08:17 PM   Total Posts: 67   [ # 2 ]

Worked perfectly thank you.

I’m checking the values of the leftVector to see if I can notice a pattern.

Thanks


EDIT

pano.camera.leftVector.y has the rotation value.  This is so simple! I spent nearly all weekend fighting with that gimbal lock and flipping values.. thanks again.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X