2
\$\begingroup\$

I was just wondering if it's possible to to a linear interpolation between two rotations without maintaining any kind of state.

What I mean is let's say I have a loop function where all my code is running, which is called at a certain interval (amount of times per second). When you call the lerp function, you pass in point a, b, and the progress (percentage between the two points). I want to interpolate between rotation a and rotation b very smoothly by using the lerp function.

The problem is, I don't know what to pass in for progress. Ideally, you would keep track of how much time has elapsed, then divide by the total amount of time that it should take. The problem is, I don't want to use any variables keeping track of how much time has passed or when the interpolation started.

So my question is, is it possible for you interpolate between the two points, without using any such variables?

If this is possible, please tell me how.

Thanks!

\$\endgroup\$
4
  • \$\begingroup\$ It wouldn't really be a lerp anymore, but you could just apply a fixed rotation transformation to the thing every step and stop when it's near/past the target rotation. If you insist on it being a proper lerp, then there is no way to do a real lerp without the t or "progress" argument. \$\endgroup\$
    – Romen
    Oct 27 '21 at 18:53
  • 1
    \$\begingroup\$ If your rotation speed is a function of the current and destination rotations (including a constant function), then you can do this: compute the rotational delta using that speed, then apply the delta to the current rotation. This will take different forms depending on what you want your speed behaviour to be. You could make it a universal constant that rotation always proceeds at speed X, you could make speed proportional to the angle remaining, etc. \$\endgroup\$
    – DMGregory
    Oct 27 '21 at 19:19
  • \$\begingroup\$ You will find that lerp has trouble with rotations going from 0 to 360 degrees, but there is slerp for that. Also I think keeping track of an animation without knowing the start time or progress percentage is not possible \$\endgroup\$
    – Jay
    Oct 28 '21 at 0:57
  • \$\begingroup\$ Where can I find an implementation of the slerp function in java? \$\endgroup\$
    – Day Trip
    Oct 30 '21 at 21:28

You must log in to answer this question.

Browse other questions tagged .