Register
Handmade Hero»Forums»Code»Zoom Differential Equation
9 posts
Zoom Differential Equation
1 week, 2 days ago Edited by Bronxolon on Jan. 9, 2020, 11:18 a.m.
Hi all. I have a couple of questions about this clip
https://youtu.be/CTTCf79MgDY?t=7073

So, in order to smoothly zoom irrespective of how far and or close Casey is to the focused object. He, basically writes the camera velocity as a function of current distance from the object * constant.

I understand that the camera velocity should be proportional to the distance from the object; in other words, as the camera gets further away it needs to move more and more to zoom by the same amount. One of my questions is why do we know the relationship is one of linear proportionality as opposed to some other proportionality relationship. Is this due to how perspective projection works? i.e. suppose z is the forward direction, if you slice a plane through any z, the area of the plane increases linearly.

Second, Casey mentioned that instead of taking the distance from the object as (camerapos - objpos) and multiplying by a constant we would want to actually solve the differential equation since our velocity is only instantaneously correct. EG: moving the mouse by 2 pixels, corresponds to a different zoom, than moving it by 1 pixel 2 times. Is this because our velocity should be changing over the 2 movements of the camera, and we need to actually be integrating the differential velocity equation over those 2 movements to get a position that accounts for the changing velocity as we go, as opposed to using the same velocity for both?

Sorry, if the question is confusing, but it has been over a decade since I've done any calculus haha.
Simon Anciaux
705 posts
Zoom Differential Equation
1 week ago
I'm not good at math so take the following with a grain of salt.

For you first question I believe you're correct.

For the second part you're partially correct: since we are moving the camera and using the camera position at the same time to compute how much to move, to get the right result we would need to be able to recompute the speed for any movement of the camera. Meaning we need to compute the speed in a continuous manner, not at discrete interval (which I believe is what a differential equation would give us). Hope this makes sens.
9 posts
Zoom Differential Equation
6 days, 23 hours ago
so this is sort of like a compound interest problem, where if you want to have 100% interest over a year, you would think that if you start with $1 you should end up with $2, but if you instead split up the 100% interest into x% interest over 100/x intervals you get closer and closer to the number e. In other words, if we want to calculate the new position as a function of the mouses y position, we need to sum up infinitesimal velocities as opposed to saying: well this is the velocity based on our distance at the start of the interval, so let's just multiply that by the interval to get an area (the position). instead intuitively we take infinitesimal velocities and multiply them by infinitesimal intervals and sum those areas up. is this more accurate?
Simon Anciaux
705 posts
Zoom Differential Equation
6 days, 20 hours ago
I think so. But once again, I'm not good at math.
9 posts
Zoom Differential Equation
6 days, 19 hours ago
well whatever the case. thanks for the help, I appreciate you taking the time.
Jesse
59 posts

Programmer at NASA GSFC

Zoom Differential Equation
3 days, 13 hours ago Edited by Jesse on Jan. 14, 2020, 8:22 p.m.
To your second question, yes. The camera's velocity is a function of changing distance _between frames_. If the simulation loop was independent of the rendering loop, this difference could be reasonably approximated if the time between iterations rather quite small, especially if the change in distance was relatively small too. But in general, you can calculate _exactly_ where the camera _should_ be and what velocity it _should_ have when explicitly specified as a differential equation. Compound interest is an analog in the sense that it changes with respect to itself. And so too does the camera's velocity change with respect to its rate of change.

The meaning of life is to dance and sing while the music is being played.