2
\$\begingroup\$

Overview:

Simply put, I'm trying to make a zoom to cursor algorithm. This would normally be very simple, but the implementation of the camera is making it difficult.

As the camera zooms in and out, the pitch of the camera (angle relative to the ground) changes. At its farthest position from the ground, it looks nearly directly at the ground, and at its closest position, it looks at about a 40 degree angle toward the ground.

This greatly complicates the method for zooming into a mouse position on a non-uniform 3d terrain.


Specifics:

More details for those who are still interested in trying to help.

The camera is implemented in unreal engine using a spring-arm (basically a large stick) attached to an actor that serves as the center of the screen. Zooming in and out simply requires us to shorten the spring-arm and change the angle of the spring-arm. moving the camera around the world is done my moving the actor around the plane at z=0 (0 height).

The problem then becomes: Where should my actor be after zooming in such that the point that the cursor is over doesn't change?

There is already an algorithm in place to determine the current pitch of the camera and the new pitch of the camera, so you can assume that information is already known. We can also easily find the new height of the camera, and the new distance between the camera and the actor (length of the spring-arm). We can fairly easily determine the point the cursor is over in the game world, and we can determine that point when it is projected along the plane at z=0.

I had originally tried implementing this using a naive solution based on some 2D trigonometry, but this didn't account for the direction that the new actor position would be in relative to the cursor position after the translation occurs. After working on this for as long as I have, I'm having trouble coming up with a new solution that also finds this value.

I'm thinking now that I can use an alternative method that would involve drawing a plane with the same normal as the camera using the vector directions of the actor and cursor position as corners, then rotating about a line going through the cursor position and scaling the new triangle to make it identical to the previous one when viewed from the camera. This, though, seems like it would be unnecessarily complicated, and expensive to implement.

I was wondering if anyone had a simpler solution (or any solution for that matter) that they know of for this problem. Or at least if anyone has some kind of direction they could point me in for finding out how I might be able to solve this problem in a reasonable amount of time without it being too computationally expensive.

Let me know if you need any more details.

(Programming language is kind of irrelevant here, so feel free to use whatever you want for explanation or examples, or just use English or pseudo code. I don't really expect anyone to write me an algorithm to do this, I'd just like some ideas on how I ought to approach this problem to keep me from ripping off my head)

Thanks,

Zac Taylor

\$\endgroup\$

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.