1

I asked this in regular SO but I think people are not understanding the question so i will try here:

So, for anyone familiar with Google Maps, when you zoom, it does it around the cursor.

That is to say, the matrix transformation for such a zoom is as simple as:

TST^{-1}*x

Where T is the translation matrix representing the point of focus, S the scale matrix and x is any arbitrary point on the plane.

Now, I want to produce a similar effect with a spherical camera, think sketchfab.

When you zoom in and out, the camera needs to be translated so as to give a similar effect as the 2D zooming in Maps. To be more precise, given a fully composed MVP matrix, there exists a set of parallel planes that are parallel to the camera plane. Among those there exists a unique plane P that also contains the center of the current spherical camera.

Given that plane, there exists a point x, that is the unprojection of the current cursor position onto the camera plane.

If the center of the spherical camera is c then the direction from c to x is d = x - c.

And here's where my challenge comes. Zooming is implemented as just offsetting the camera radially from the center, given a change in zoom Delta, I need to find the translation vector u, colinear with d, that moves the center of the camera towards x, such that I get a similar visual effect as zooming in google maps.

Since I know this is a bit hard to parse I tried to make a diagram: enter image description here

TL;DR

I want to offset a spherical camera towards the cursor when I zoom, how do i pick my translation vector?

Makogan
  • 1,584
  • 8
  • 27
  • Isnt this a standard pole vector problem? Z is vector from center of circle. X is Z cross up (vector from center to north pole) , Y is Z cross X and the translate is R – joojaa Dec 11 '19 at 18:46
  • I am not sure I am understanding your question, this isn;t a kinematic issue – Makogan Dec 11 '19 at 18:50
  • You understand affine matrices? – joojaa Dec 11 '19 at 18:54
  • I want to say yes, it's a transformation that remains the same regardless of the position of the input. e.g trnaslation is affine, scaling isn;t – Makogan Dec 11 '19 at 18:56
  • Scaling is affine, so is skew, rotate, mirror and translate. Anyway all you need is to construct the tranformation matrix as described and stick yoir camera under that. (This works well eveywhere except on the singularities the pole) – joojaa Dec 11 '19 at 18:58
  • while joojaa is right I think you are more concerned with how to calculate the fraction of the total lenght of the vector `d` for each mouse wheel click (as the camera gradually zooms) if I am correct? Why don'y you just take a small fraction of it say `0.1*d` – gallickgunner Dec 11 '19 at 20:13
  • The camera needs to move towards the cursor as the user clicks the wheel, that's the main thing. – Makogan Dec 11 '19 at 20:22
  • Oh okay so you are asking the procedure on how to move the spherical camera in the same way as google map does (but it isn't a spherical camera) – gallickgunner Dec 11 '19 at 20:24
  • So, if I understand correctly, you are saying to move both the camera and the center along the vector cursor - camera Correct? – Makogan Dec 11 '19 at 20:24
  • That'd be my initial guess yes just nudge the camera basically the whole trackball system as it is a little in the direction of the translation then zoom – gallickgunner Dec 11 '19 at 20:25
  • @gallickgunner Yes I know google maps isn;t a spherical camera, I am nonetheless trying to create the same effect. – Makogan Dec 11 '19 at 20:25
  • 2
    The goal seems a bit strange since the entire point of an orbiting camera is to keep the target point at the center. I would recommend doing what Blender does, and having the target point change only when the user pans. Doing what google maps does in 3D doesn't make much sense because there are infinitely many positions along Z that match the mouse coordinates, and even zooming changes which of those points are visible (assuming perspective projection). – Dan Dec 21 '19 at 19:44

0 Answers0