# camera phi & theta

This topic is 5412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hhi! i got a little qn on managing a camera. i parsed truespace's perspective camera, and need to convert it to standard layman usage(TS really inverts the axes all over until i blur). suppose i got arbitrary lookat,up,right,position camera vectors(parsed from TS). But i dunno the phi and theta, which i need to calculate for a 1st person camera. Is there a way to calculate them? thx! RC

##### Share on other sites
you need a matrix-to-euler conversion routine, that converts a matrix into a euler.

google : matrix to euler conversion

...Bookmark the Martin Baker site.

##### Share on other sites
as a side note, you can build a orientation matrix by loading the columns (or rows if the matrix is row aligned) of the matrix with the strafe, up, dir vectors you have.

##### Share on other sites
I'm not sure which way around your phi and theta are so I'll refer to them as elevation and heading angles. The elevation angle, ie: that between the normalised lookat vector and the xz plane, is given by:

sin( elevation angle ) = lookat.yaxis

and the direction angle, that between the lookat vector and the zy plane, is given by:

sin( direction angle ) = lookat.xaxis

where yaxis and xaxis are the world cartesian axes and '.' refers to the vector dot product. Note that this will give you signed angles. Hope that this is what you were after

Edit: Just occured to me the lookat vector refers to a point in space and not the camera view vector doesn't it. In that case replace lookat vector above with the normalised view vector which is given by subtracting the lookat vector from the camera pos vector and normalising the result. Sorry for the confusion

##### Share on other sites
hmm... ok thks!
however, looks like got another weird problem, looks like i din realli get the correct lookat,up,right vectors correctly.

i managed to parse their so called "camera local axes", which kinda seemed to me are the vectors but i think i am lacking something to fit them correctly. The following are the results of the parsing.

camera position 16.6 16.32 13.7
camera local x axis -0.707107 0.707107 0
camera local y axis -0.3987 -0.3987 0.825879
camera local z axis -0.583985 -0.583985 -0.563847

Their actual world axes follows that of mathworld, x-axis goes towards the viewer, y-axis points to the right, z-axis points up.

i am using GL, and i was thinking that the lookat vector is the so called/parsed camera local z-axis, but fitting any of the other 2 vectors for the up and right doesnt give the natural feel of a 1st person camera though...sigh

thx!
RC

• 18
• 29
• 11
• 21
• 16