I am trying to make a game where the player can walk along the surface of a spherical planet, and am not sure how to handle orientation. Pitch is relatively easy, as it is simply how much "above" or "below" the plane tangent to the surface of the sphere you are looking. However, yaw is more tricky. Right now, I have yaw configured as essentially the "bearing", where yaw=0 means you are pointing east and yaw=90 means you are point north.

This creates to problems:

1) On the poles, the moment gets messed up becouse the angle between the "Up" and "north" vector is very small.

2) If you move over the pole, your view will suddenly flip so that you are still facing the pole. This is a problem similar to #1.

3) If you walk in a straight line, you will walk along the rhumb line, rather then the great circle line, unless you purposely change your yaw. In the "real" world, you can walk "straight" and still walk on the great circle line (correct me if I am wrong).

Is there some trick or other reference system I could use to solve these problems?

For reference, this is my current code:

Up = glm::normalize(pos - body->pos); //Points from center of sphere to camera

float r_pitch = glm::radians(pitch);
float r_yaw = glm::radians(yaw);

East = glm::normalize(glm::cross(glm::vec3(0, 1, 0), Up)); //Points "east", lies on plane tangent to surface of sphere
North = glm::normalize(glm::cross(Up, East)); //Points "north", lies on plane tangent to surface of sphere

Forward = glm::rotate(East, -r_pitch, North);
Forward = glm::rotate(Forward, -r_yaw, Up); //The direction the camera is pointing in the "universal" reference frame.

FFlat = glm::normalize(ProjectOnPlane(Forward, Up)); //Used for movement, lies on plane tangent to surface of sphere
FSide = glm::normalize(glm::rotate(FFlat, TAU / 4, Up));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.