Spherical camera movement for planets

Started by
2 comments, last by Matt_Aufderheide 7 years, 8 months ago

Does anyone know a way to do a spherical first person movement with only setting pan, tilt, and roll angles? This is for walking on a spherical planet.

The engine I'm using basically just creates your view matrix from these 3 angles...

That is, I don't want to end up with a lookat matrix, but actually 3 angles I can set. Let me know if this question is too vague..I have done a lot of looking and not sure what the best method is.

Advertisement

Calculate camera orientation by using the up-vector pointing from planet center to player (gravity direction).

This up vector is the only thing you can trust in,

e.g. an additional tangent towards south pole (or any other fixed point on the planet surface) will flip as soon as you move over that point.

But the up vector alone is enough - looking left / right becomes rotating about up vector, Looking up down becomes rotating about cross(upVector, characterFrontDir).Unit()

So after that you have a matrix or quaternion storing camera orientation in worldspace, and you need to get 3 Euler angles from that.

Getting Euler angles directly from player input would be just pain - don't try to do so - waste of time.

Make sure your engine really does not support any other camera option than Euler angles (pan, tilt, roll, - pitch, yaw, roll, - rotate x,y,z... mathematically that's all just Euler angles).

To convert from matrix / quaternion to Euler you also have to know (but mostly have to guess) the order of the 3 rotations defined by those 3 angles.

This can become a frustrating source of trial and error.

If your engine can take any kind of projection matrix (And it really should - otherwise, what engine do you talk about?), use this instead.

If you're only moving a camera along a planet's surface where up is ALWAYS away from the planet, then you can do it like this:

keep track of the position (D3DXVector3(x,y,z))

keep track of your camera's current matrix with no position data (CurMat)

say you want to rotate the camera : D3DXMatrixRotationYawPitchRoll(&rot,y,p,r)

now set up your camera's position matrix (CPM) CPM=CurMat*rot

and put in your position to CPM

Hope this answers your question.

EDIT: the multiplication order is important. it may be CPM=rot*CurMat.

be sure to store the CPM into your CurMat before adding position data.

Thanks guys! I got it to work using a function that was built in i didint realize existed... but the info you have given me is great!

This topic is closed to new replies.

Advertisement