gpt4 book ai didi

c++ - Mathf.SmoothDamp() 如何工作?它是什么算法?

转载 作者:行者123 更新时间:2023-12-03 07:12:22 25 4
gpt4 key购买 nike

我想知道 SmoothDamp 是如何统一工作的。我正在尝试在 unity 之外重新创建函数,但问题是我不知道它是如何工作的。

最佳答案

来自 Unity3d C# 引用 source code :

// Gradually changes a value towards a desired goal over time.
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, [uei.DefaultValue("Mathf.Infinity")] float maxSpeed, [uei.DefaultValue("Time.deltaTime")] float deltaTime)
{
// Based on Game Programming Gems 4 Chapter 1.10
smoothTime = Mathf.Max(0.0001F, smoothTime);
float omega = 2F / smoothTime;

float x = omega * deltaTime;
float exp = 1F / (1F + x + 0.48F * x * x + 0.235F * x * x * x);
float change = current - target;
float originalTo = target;

// Clamp maximum speed
float maxChange = maxSpeed * smoothTime;
change = Mathf.Clamp(change, -maxChange, maxChange);
target = current - change;

float temp = (currentVelocity + omega * change) * deltaTime;
currentVelocity = (currentVelocity - omega * temp) * exp;
float output = target + (change + temp) * exp;

// Prevent overshooting
if (originalTo - current > 0.0F == output > originalTo)
{
output = originalTo;
currentVelocity = (output - originalTo) / deltaTime;
}

return output;
}

关于c++ - Mathf.SmoothDamp() 如何工作?它是什么算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61372498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com