【问题标题】:Unreal Engine Beginner FMath::Sin虚幻引擎初学者 FMath::Sin
【发布时间】:2016-06-12 06:06:52
【问题描述】:

好的,我目前正在学习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?太混乱了。

就是这样!感谢您的宝贵时间(希望能提供帮助)!

【问题讨论】:

  • 我不明白”不能很好地描述问题所在。这可能意味着从不了解 C++ 到不了解 :: 的作用等等。

标签: c++ unreal-engine4


【解决方案1】:

Super::Tick( DeltaTime ); 正在使用 Super 关键字调用父类的 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));

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

最后让我们看看

   NewLocation.Z += DeltaHeight * 20.0f;

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

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

【讨论】:

    【解决方案2】:

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

    FMath::Sin 表示您使用 FMath 类中的 sin 函数。 :: 表示继承自或“来自”,因此可以将其视为“FMath 有一个名为 Sin 的函数”

    Super::Tick(DeltaTime);只是意味着你的actor类在tick函数中滴答作响(执行每一帧)。

    【讨论】:

      猜你喜欢
      • 2019-01-06
      • 2022-12-04
      • 2018-09-01
      • 1970-01-01
      • 2022-06-28
      • 2015-02-04
      • 2020-07-24
      • 2015-02-04
      • 2020-07-15
      相关资源
      最近更新 更多