虚幻引擎初学者 FMath::Sin.
Unreal Engine Beginner FMath::Sin
好的,所以我目前正在学习虚幻引擎编程教程。这是我感到困惑的代码:
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?太令人困惑了。
就是这样!感谢您的时间(希望对您有所帮助)!
Super::Tick( 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
float DeltaHeight
堆栈上创建新的float
变量
= (FMath::Sin(RunningTime + DeltaTime) -
FMath::Sin(RunningTime));
使用 FMath
类的 FMath::Sin
Sin
方法进行基本的 SIN 计算。你可以在这里做一个关于正弦和余弦的简单教程
最后让我们看看
NewLocation.Z += DeltaHeight * 20.0f;
NewLocation
是一个FVector
,是虚幻引擎版本的矢量。这条线所做的只是将先前计算的称为 DeltaHeight
的float
添加到 NewLocation
的Z
值,并将该值缩放 20。
要了解有关基本向量数学的更多信息,我会推荐Daniel Shiffman的The Nature of Code。
FMath在UE4 API中用于许多核心数学函数。FMath::Abs 给你绝对值(例如 psotive 值)
FMath::Sin 表示您使用来自 FMath 类的 sin 函数。 :: 表示继承自或"来自",因此可以将其视为"FMath 有一个函数 im 调用称为 Sin"
Super::Tick(DeltaTime); 只是意味着你的 actor 类在 tick 函数中滴答(执行每一帧)。
相关文章:
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 为什么 std::round(sin(pi/6)) 不等于 1?
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- 未解析的外部符号 fabs, cos, sin.
- 如何提高iOS上的std :: sin功能的精度
- sin cos 函数在大于 90 的度数时给出错误的结果
- 如何计算特殊操作(Exp SIN SQRT)的FOP总数和浮点性能
- 移动方程式deltAheight =(sin(runningtime deltatime) - sin(runni
- 用C 创建SIN/COS图
- 使用SIN和COS函数迭代时,NAN会导致
- 虚幻引擎初学者 FMath::Sin.
- 为什么所有核心上的sin(Vector)可以和一个核心上的sin(V)一样快
- 我的神经网络学习sin x,但不学习cos x
- C 程序创建SIN COS和切线值
- 创建快速sin()函数以改善fps?快速sin()函数
- 来自 sin() 生成声音的金属声音
- 设置 std::function 变量以引用 std::sin 函数
- C++ : sin(M_PI/6) = 0.5?
- cos 和 sin 不提供预期的输出
- 将 cos 和 sin 存储到一个向量中并获得奇怪的值