2016-06-12 287 views
-1

好的,所以我现在正在学习一个Unreal Engine programming tutorial。这是我很困惑的代码:虚幻引擎初学者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?这很混乱。

就是这样!谢谢你的时间(希望有帮助)!

+1

“*我不明白*”不是一个很好的问题描述。这可能意味着什么,从不理解C++到不理解什么是'::',等等。 – PaulMcKenzie

回答

1

FMath在UE4 API中用于很多核心数学函数。 FMath :: Abs为您提供aboslute(例如,令人兴奋的值)

FMath :: Sin表示您使用FMath类的sin函数。 ::意味着继承或“来自”,所以把它想象成“FMath有一个函数即时调用称为Sin”

Super :: Tick(DeltaTime);只是表示你的演员类正在勾选(执行每一帧)滴答功能。

0

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::SinSin方法做一个基本的sin计算:

现在,在让我们来看看。你可以做一个简单的tutorial on sin and cosine here

最后让我们来看看

NewLocation.Z += DeltaHeight * 20.0f; 

NewLocationFVector,这是虚幻的版本载体。所有这行代码添加先前计算float称为DeltaHeightNewLocationZ值,以及由20

标定值要详细了解基本的矢量数学我会由Daniel Shiffman建议更换The Nature of Code