C#从位置到位置 [英] C# Lerping from position to position

查看:130
本文介绍了C#从位置到位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个图片框,以便从一个位置移动到另一个位置(就像您可以团结一致地进行操作一样).
我该怎么做,有内置功能吗?
谢谢:)

I need to make a picture box to lerp from position to position (like you can do that in unity).
How can I do that , is there a built-in function?
thanks :)

推荐答案

线性插值(lerp)实际上是一个非常容易实现的函数.等式是

Linear interpolation (lerp) is actually a pretty easy function to implement. The equation is

float Lerp(float firstFloat, float secondFloat, float by)
{
     return firstFloat * (1 - by) + secondFloat * by;
}

高阶Lerp只会包裹低阶lerps:

A higher order Lerp just wraps lower order lerps:

Vector2 Lerp(Vector2 firstVector, Vector2 secondVector, float by)
{
    float retX = Lerp(firstVector.x, secondVector.x, by);
    float retY = Lerp(firstVector.y, secondVector.y, by);
    return new Vector2(retX, retY);
}

DirectX SDK具有像Unity之类的所有数学功能,但是仅为Lerp带来很多开销.您可能最好只是实现自己的.

The DirectX SDK has all manner of math functions like Unity, but that's a lot of overhead to bring in just for Lerp. You're probably best off just implementing your own.

这篇关于C#从位置到位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆