Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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).

share|improve this question
    
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? –  Samaursa Nov 19 '10 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 –  eephyne Nov 20 '10 at 10:11
add comment

3 Answers 3

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.

share|improve this answer
    
i will get in quaternion soon as the solution i found is limited for certain type of rotation . But quaternions seems hard to get :( –  eephyne Nov 22 '10 at 8:29
add comment
up vote 0 down vote accepted

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)

share|improve this answer
    
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. –  Steve H Nov 28 '10 at 12:56
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.