简体   繁体   English

线性插值更线性

[英]Linear Interpolation More Linearly

I'm curious if there's a way to make this function:我很好奇是否有办法实现这个功能:

float linearInterpolation(float startPoint, float endPoint, float time)
{
    return startPoint + ((endPoint - startPoint) * time);
}

More linear, as right now when the start point nears its endpoint it goes slower, i just want it to go the same speed all the way through no slowing down/speeding up.更线性,因为现在当起点接近终点时它会变慢,我只是希望它一直保持相同的速度,而不会减速/加速。 If i need to implement another variable or something that can be done.如果我需要实现另一个变量或可以完成的事情。 Another function that would take the same variables and output the next value would also be acceptable.另一个采用相同变量并输出下一个值的函数也是可以接受的。

That looks like a correct implementation of lerp to me.对我来说,这看起来像是 lerp 的正确实现。 Without seeing the code that you are calling it with, I'm going to guess that the reason it is slowing down is that you are calling it with a different startPoint (calling with the previous result of the call to linearInterpolation would cause this) each time (frame?) which would cause it to slow down as the distance to interpolate is reduced each time it is called.在没有看到您调用它的代码的情况下,我会猜测它变慢的原因是您使用不同的 startPoint 调用它(使用调用 linearInterpolation 的先前结果调用会导致此)每个时间(帧?)这会导致它变慢,因为每次调用它时插入的距离都会减少。

Make sure the startPoint and endPoint variables are the same for each call over the life of the interpolation and only the time variable is increasing.确保插值期间每次调用的 startPoint 和 endPoint 变量都相同,并且只有时间变量在增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM