View Full Version : Some camera stuff (again)

Orzech

07-11-2003, 01:52 AM

Hi!

To be ohnest it's rather a math question than OpenGL one but

I hope that there is a solution somewhere in OpenGL. It's about

camera... I have 3 rotation angles - each about each axis. Let's

call them Rx, Ry, Rz. I've also got a position of the camera PosX,

PosY, PosZ. Now, let's say I'd like to set the cameras angles

in a way that camera would be facing a particular point (X, Y, Z).

I've made a math solution for this but there is too much

acos, atan and it's hardly any good one. So meaby you know

some better ways of calculating these ANGLES?

Thanks

dorbie

07-11-2003, 08:59 AM

gluLookAt

If that's not what you need then you need to google for Euler angles.

This should be simple, you don't have roll, so that's always zero (not enough info to specify this with a single vector), all you need is heading & pitch (probably rx and ry in typical OpenGL coordinates). You have a vector from (lookat_point - eye_pos

0. So it's simple trig.

acos ((x, 0, z) . (x, y, z)) gives you pitch or rotation about x, make sure you normalize the vectors before the dot product.

atan2f with x and z should give you the heading or rotation about y, although you may have to mess with the signs to get the quadrants right.

The only thing you need to worry about next is multiplication order of heading and pitch, but I assume you have some library for this.

If you have some z up scheme instead of y up the same thing applies but with different axes being used in the math above.

Jared@ETC

07-11-2003, 08:59 AM

You could just use gluLookAt.

The 4th,5th,and 6th parameters are the X,Y,Z of the camera target, respectively.

Orzech

07-12-2003, 02:21 AM

Originally posted by dorbie:

.

acos ((x, 0, z) . (x, y, z)) gives you pitch or rotation about x, make sure you normalize the vectors before the dot product.

atan2f with x and z should give you the heading or rotation about y, although you may have to mess with the signs to get the quadrants right.

The only thing you need to worry about next is multiplication order of heading and pitch, but I assume you have some library for this.

Yeah. I've made it this way but there are still some things I've forgot about (like normalizing vectors). OK. I'll try it.

Thanx

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.