언리얼 엔진의 KismetMathLibrary
언리얼 엔진과 C++코드를 사용한 학습을 진행하던중, 수학적인 계산이 필요한 경우가 있었습니다.
학습을 진행하던 중 KismetMathLibrary의 함수를 사용하게 되었고, 사용한 함수 외에도 유용한 다른 함수들이 어떤것이 있는지에 대해 알아보았습니다.
이번 포스팅에서는 KismetMathLibrary의 함수들에 대해 알아보겠습니다.
Kismet
언리얼 엔진에서의 Kismet은 UE3에서 도입된 비주얼 스크립팅 시스템입니다.
코드를 작성하지 않고 노드 기반 인터페이스로 이벤트, 조건, 액션 등을 연결하여 동작을 제어할 수 있었습니다.
UE4부터 비쥬얼 스크립팅은 BluePrint을 채용하게 되었고, 기존의 Kismet은 엔진 내부에서 다양한 기능을 가지는 범용 클래스로 변경되었습니다.
그 중 UKismetMathLibrary는 수학 계산과 관련된 함수들을 제공하는 클래스입니다.
해당 클래스의 주요 함수들에 대해 몇가지 알아보겠습니다.
UKismetMathLibrary
FindLookAtRotation : Start에 있는 객체가 Target 객체를 바라보는 회전 값을 반환합니다.
FRotator UKismetMathLibrary::FindLookAtRotation(const FVector& Start, const FVector& Target)
{
return MakeRotFromX(Target - Start);
}
ComposeRotators : Rotator A와 B의 합한 값을 반환합니다.
FRotator UKismetMathLibrary::ComposeRotators(FRotator A, FRotator B)
{
FQuat AQuat = FQuat(A);
FQuat BQuat = FQuat(B);
return FRotator(BQuat*AQuat);
}
RandomFloatInRange, RandomIntegerInRange, RandomInitVector : 주어진 범위 내에서 무작위 값을 생성합니다.
Cos, Sin, Tan : 삼각함수 값을 반환합니다.
※ 해당 함수들은 FMath의 함수들을 반환합니다. 즉, FMath 클래스 내 함수와 동일합니다.
double UKismetMathLibrary::RandomFloatInRange(double Min, double Max)
{
return FMath::FRandRange(Min, Max);
}
Lerp : 선형 보간을 수행하며, A와 B를 V의 비율에 따라 계산합니다.
- V가 0일경우 A의 100%, 1일경우 B의 100%의 값을 계산합니다.
double UKismetMathLibrary::Lerp(double A, double B, double V)
{
return A + V*(B-A);
}
MakeTransform : 물리적인 객체를 이동하거나 회전시킬 때 사용합니다.
FTransform UKismetMathLibrary::MakeTransform(FVector Translation, FRotator Rotation, FVector Scale)
{
return FTransform(Rotation, Translation, Scale);
}
FInterpTo : UI 애니메이션 또는 숫자 등의 속도를 제어합니다.
double UKismetMathLibrary::FInterpTo(double Current, double Target, double DeltaTime, double InterpSpeed)
{
return FMath::FInterpTo(Current, Target, DeltaTime, InterpSpeed);
}
NormalizeAxis : 해당 각도를 -180 ~ 180의 값으로 변환하여 반환합니다.
float UKismetMathLibrary::NormalizeAxis(float Angle)
{
return FRotator::NormalizeAxis(Angle);
}
GetDirectionUnitVector : From에서 To까지의 벡터 값을 받아옵니다. 위치가 같을시 (0,0,0)을 반환합니다.
FVector UKismetMathLibrary::GetDirectionUnitVector(FVector From, FVector To)
{
return (To - From).GetSafeNormal();
}
ProjectPointOnToPlane : 정규화된 벡터로 정의된 평면에 해당 벡터를 투영합니다.
※ 화면 상의 위치를 특정 평면으로 매핑하는 경우 사용합니다.
FVector UKismetMathLibrary::ProjectPointOnToPlane(FVector Point, FVector PlaneBase, FVector PlaneNormal)
{
return FVector::PointPlaneProject(Point, PlaneBase, PlaneNormal);
}
이 외에도 다양한 함수들이 존재하며, 그 중 언리얼 엔진을 사용한 클라이언트 개발자가 프로젝트 제작 시 자주 사용하는 것들에 대해 알아보았습니다.
언리얼 공식 사이트 - UKismetMathLibrary 클래스