I am trying to create a strategy game that takes place on a globe (i.e. a textured sphere). I would like to be able to zoom to mouse like on google maps. My camera always points towards the center of the globe, and its position is defined in spherical coordinates. I have implemented zoom to mouse using an orthographic projection (technically scaling) which is easier since screen distance corresponds to world distance. I would like to be able to use a perspective projection, but the math seems to be a bit beyond me.

So far I am able to determine what point on screen my mouse is on my globe by ray-casting, however I am not sure how far my camera should be moving in order to keep that point fixed on screen while still having the camera point towards the center of the globe. I know that the basics of zoom to mouse involve translating to the position of the mouse, zooming, and then translating back, however being on a sphere with perspective introduces lots of distortion when translating.

Has anyone had any luck implementing zoom to mouse on a globe using a perspective projection? Or is this an exercise in futility...


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.