# Camera Rotation using angles

I currently try to rotate a camera (using gluLookAt()) around a point , i successfully do it for rotating around one global axis.

But when i want to use more than one axis , I'm stuck . I've searched around and it's seem i need to use something like axis-angle or quaternion (that i don't understand at all for now)

for rotating my camera i have 3 angles (using accelerometer and geomagnetic values).

How can i determine the point of view , using three angle and the radius ? knowing the the camera itself is at the point of origin (0,0,0).

I prefer using gluLookAt() than moving the whole scene if possible(event if i know that almost the same thing).

• Please re-word the part "How can I determine the point of view, using three angles and the radius". What is the radius in this case? Commented Nov 19, 2010 at 17:10
• the radius is the distance between the eye and the point of view , doesn't matter if this is the point of view who move around, but matter if it's the opposite Commented Nov 20, 2010 at 10:11

I would suggest keeping track of the pivot (that is, what the player is looking at in gluLookAt) explicitly. If the player looks left, rotate the pivot to the left around his head. If he looks up, move it up. Every frame use gluLookAt with the adjusted pivot. This is a bit wasteful compared to other techniques, but it has the benefit of being easy to visualize. You can even show a primitive at the pivot position to verify it's where you think it is.

In the long run, it's probably worth investing in learning quaternions. Using multiple angles along fixed axes (called Euler Angles) will end up causing you more trouble than you can imagine, as the rotations will be interdependent. I'm sure you've seen it happen in examples, you look up, then turn around. When turning around you turn around along the current up-axis instead of the vertical, and you end up looking down. There's also the matter of gimbal lock, but in practice that's not nearly as annoying as the above.

Here is a decent tutorial on quaternions.

• i will get in quaternion soon as the solution i found is limited for certain type of rotation . But quaternions seems hard to get :( Commented Nov 22, 2010 at 8:29

I got it !

i simply used conversion from Spherical Coordinate (rho,phi,theta) to Cartesian coordinate.

for those who need it , here my function in java:

void angleToCartesian(double rho, double phi, double theta) {

coords.x = rho * Math.sin(phi) * Math.cos(theta);
coords.y = rho * Math.cos(phi);
coords.z = rho * Math.sin(phi) * Math.sin(theta);

}


the rho is the radius , phi is the zenith angle (so be careful if like me your angle start at azimuth (90° from zenith)) and theta is the longitude angle (starting from +z). the angles are -of course- in radians.

it's explained here for those who want : http://mathworld.wolfram.com/SphericalCoordinates.html (pay attention to the fact that their xyz axis are not the same)

• If you choose to go on and explore the axis/angle concept and how it can be implemented into rotating a matrix, you can reduce your relatively expensive trig function calls from the 5 in your solution to just 2. Most likely a less than optimal camera won't bottleneck a game but later, if you start manipulating many objects per frame, keep that in mind. Commented Nov 28, 2010 at 12:56

if you have three angles, then the first thing you need to do is figure out what they represent:

your problem sounds like a conversion from euler angle to matrix, and if that's true, then you need to find out what order your angles are meant to be applied in.

see this wikipedia link for details of building the matrix once you have found out what order the axes are in.

If they're not euler angles, then what are they? Are they axial north bearings?if so, then you've got to generate a lookat from a calibrated north-world transform, and that's not going to give you a single solution, but a set of solutions that lie in the plane of the north axis. Normally you'd take this plane solution and use it to provide an update to a kalman filter, or marry it with accelerometer readings to give the correct downward direction thus prodiving the extra constant required for a single solution or mere pair of solutions.