2016-06-12 56 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