서의 공간

속도, MakeFromX, MakeRotFromX 본문

Unreal Engine

속도, MakeFromX, MakeRotFromX

홍서의 2021. 11. 9. 15:15

GetVelocity

////////////// Actor.h/.cpp

/** Returns velocity (in cm/s (Unreal Units/second) of the rootcomponent if it is either using physics or has an associated MovementComponent */
UFUNCTION(BlueprintCallable, Category="Utilities|Transformation")
virtual FVector GetVelocity() const;

FVector AActor::GetVelocity() const
{
	if ( RootComponent )
	{
		return RootComponent->GetComponentVelocity();
	}

	return FVector::ZeroVector;
}

////////////// Pawn.h/.cpp

virtual FVector GetVelocity() const override;

FVector APawn::GetVelocity() const
{
	// RootComponent가 SceneComponent이면 IsSimulatingPhysics는 항상 false이다.
	// RootComponent가 PrimitiveComponent이면 IsSimulatingPhysics는 true/false 두 값을 가질 수 있다.
	if(GetRootComponent() && GetRootComponent()->IsSimulatingPhysics())
	{
		return GetRootComponent()->GetComponentVelocity();
	}

	const UPawnMovementComponent* MovementComponent = GetMovementComponent();
	return MovementComponent ? MovementComponent->Velocity : FVector::ZeroVector;
}

Velocity, 속도는 방향과 크기를 가지는 벡터량이다.

GetVelocity는 Actor 또는 Pawn의 RootComponent의 Velocity를 리턴한다.

Pawn에서는 MovementComponent에서 Velocity를 얻어오기도 한다.

 

Velocity는 월드 좌표계의 벡터이다.


MakeFromX

///////////// RotationMatrix.h

/** Builds a rotation matrix given only a XAxis. Y and Z are unspecified but will be orthonormal. XAxis need not be normalized. */
static CORE_API FMatrix MakeFromX(FVector const& XAxis);


///////////// UnrealMath.cpp

FMatrix FRotationMatrix::MakeFromX(FVector const& XAxis)
{
	FVector const NewX = XAxis.GetSafeNormal();

	// try to use up if possible
	FVector const UpVector = ( FMath::Abs(NewX.Z) < (1.f - KINDA_SMALL_NUMBER) ) ? FVector(0,0,1.f) : FVector(1.f,0,0);

	const FVector NewY = (UpVector ^ NewX).GetSafeNormal();
	const FVector NewZ = NewX ^ NewY;

	return FMatrix(NewX, NewY, NewZ, FVector::ZeroVector);
}
  • 이 함수는 입력 파라미터 벡터를 X축으로 하여 새로운 기저를 구축하고, 그 기저로의 회전 행렬을 리턴한다. 
  • '^' 연산자는 cross product로 연산자 오버라이딩 되어 있다.

 

MakeRotFromX

/////////// KismetMathLibrary.h/.cpp/.ini

/** Builds a rotator given only a XAxis. Y and Z are unspecified but will be orthonormal. XAxis need not be normalized. */
UFUNCTION(BlueprintPure, Category="Math|Rotator", meta=(Keywords="construct build rotation rotate rotator makerotator"))
static FRotator MakeRotFromX(const FVector& X);

KISMET_MATH_FORCEINLINE
FRotator UKismetMathLibrary::MakeRotFromX(const FVector& X)
{
	return FRotationMatrix::MakeFromX(X).Rotator();
}
  • MakeFromX에서 만든 회전행렬의 Rotator를 리턴. 이 rotator는 월드 좌표계에서 입력 파라미터 벡터를 X축으로 하는 좌표계로 이전하기 위해 필요한 회전각이다.

'Unreal Engine' 카테고리의 다른 글

컨트롤러 방향  (2) 2021.12.16
AIController에서 BehaviorTreeComponent  (2) 2021.12.12
Set Timer 사용법  (0) 2021.12.12
Pawn  (0) 2021.11.09
[UMG] Drag & Drop  (0) 2021.10.29
Comments