Jump to content
  • Advertisement
Sign in to follow this  
Matt_Aufderheide

Spherical camera movement for planets

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Edited by Hawkblood

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!