Unreal Engine 初学者 FMath::Sin

Unreal Engine Beginner FMath::Sin

好的,我目前正在学习 Unreal Engine programming tutorial。这是我混淆的代码:

void AFloatingActor::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );
    FVector NewLocation = GetActorLocation();
    float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
    NewLocation.Z += DeltaHeight * 20.0f; // Scale our height by a factor of 20
    RunningTime += DeltaTime;
    SetActorLocation(NewLocation);
}

我不明白它所说的部分:

void AFloatingActor::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );

这部分:

float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
    NewLocation.Z += DeltaHeight * 20.0f; // Scale our height by a factor of 20

它有什么作用?它是如何做到的?什么是 FMath::Sin?太乱了。

就是这样!感谢您抽出宝贵时间(希望能有所帮助)!

FMath 在 UE4 API 中用于许多核心数学函数。 FMath::Abs 给你绝对值(例如正值)

FMath::Sin 表示您使用 FMath class 中的 sin 函数。 :: 表示从 "coming from" 继承,因此可以将其视为 "FMath has a function im calling called Sin"

Super::Tick(DeltaTime);只是意味着你的演员 class 在滴答函数中滴答作响(每帧执行)。

Super::Tick( DeltaTime ); 正在使用 Super 关键字调用父 class 的 Tick 方法。

DeltaTime是引擎中每一帧之间传递的时间量,游戏开发中非常常用和必要的概念,您可以详细了解here

现在让我们看看:

float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - 
    FMath::Sin(RunningTime));
    NewLocation.Z += DeltaHeight * 20.0f; // Scale our height by a factor of 20

float DeltaHeight 在堆栈上创建一个新的 float 变量

= (FMath::Sin(RunningTime + DeltaTime) - 
    FMath::Sin(RunningTime));

使用FMathclass的FMath::SinSin方法进行基本的sin计算。你可以做一个简单的 tutorial on sin and cosine here

最后让我们看看

   NewLocation.Z += DeltaHeight * 20.0f;

NewLocation 是一个 FVector,它是 Unreal 版本的 Vector。此行所做的就是将先前计算的 float 称为 DeltaHeight 添加到 NewLocationZ 值,并将该值缩放 20。

要了解有关基本矢量数学的更多信息,我会推荐 Daniel Shiffman 的 The Nature of Code