平滑旋转到一个角度
Smooth Rotation to an Angle
我正在努力将一个物体旋转 160 度 degrees/second,然后让它在预先指定的角度减速到完全停止。例如,如果选择的角度是 30 度,它会旋转得很快,然后减速,最终停在 30 度处。我无法想出执行此操作的算法,这正是我所要求的。
暂时,假设您需要做的就是设置旋转 object.Rotation = 30(度)。随意写在 Java/Lua/C++/JavaScript.
目前我所掌握的(基本没有):
//Assume that wait(1) waits 1 second
int angle = 70;//Fast rotations at first but slow down as time goes on
for (int i = 140; i > .1; i = i - 5)//Must work for every angle
{
for (int a = 0; a < i; a = a + 10)
{
object.Rotation = a;
wait(.05);
}
}
伪代码:
int max_speed = 10
int target_angle = 30
while (target_angle != object.Rotation) do
int delta = target_angle - object.Rotation
delta = max(min(delta / 5, max_speed), -max_speed) + max(min(delta, 1), -1)
object.Rotation = object.Rotation + delta
wait(.05)
end while
我正在努力将一个物体旋转 160 度 degrees/second,然后让它在预先指定的角度减速到完全停止。例如,如果选择的角度是 30 度,它会旋转得很快,然后减速,最终停在 30 度处。我无法想出执行此操作的算法,这正是我所要求的。
暂时,假设您需要做的就是设置旋转 object.Rotation = 30(度)。随意写在 Java/Lua/C++/JavaScript.
目前我所掌握的(基本没有):
//Assume that wait(1) waits 1 second
int angle = 70;//Fast rotations at first but slow down as time goes on
for (int i = 140; i > .1; i = i - 5)//Must work for every angle
{
for (int a = 0; a < i; a = a + 10)
{
object.Rotation = a;
wait(.05);
}
}
伪代码:
int max_speed = 10
int target_angle = 30
while (target_angle != object.Rotation) do
int delta = target_angle - object.Rotation
delta = max(min(delta / 5, max_speed), -max_speed) + max(min(delta, 1), -1)
object.Rotation = object.Rotation + delta
wait(.05)
end while