글을 쓰는 목적
회전된 DecalActor를 스폰하는 경우가 생겨서 Matrix 연산을 통해 스폰된 액터의 Transform을 구했는데 구현하는데 조금 막히는 곳이 있어 글을 씀
작업 환경
UE4.26
Matrix 연산을 통해 Transform 구하기
행렬 좌표 계산은 3D 수학을 공부해 본 사람이라면 아시다 싶이 Scale Matrix * Rotation Matrix * Translation Matrix * Orbit Matrix* Parents Matrix를 곱해서 Transform을 알 수 있다.
FVector scale;
FRotator rotation;
FVector location;
float Degree;
FVector parentsLocation;
FMatrix scaleMat = FScaleMatrix::Make(scale);
FMatrix rotationMat = FRotationMatrix::Make(rotation);
FMatrix translationMat = FTranslationMatrix::Make(location);
FMatrix orbitMat = FRotationMatrix::Make(FRotator(0, Degree, 0).Quaternion());
FMatrix parentsMat = FTranslationMatrix::Make(parentsLocation);
FMatrix resultMat = scaleMat * rotationMat * translationMat * orbitMat * parentsMat;
SetActorTransform(FTransform(resultMat));
Transform을 구하면서 문제가 발생했었는데 데칼 액터의 UV 좌표 때문에 데칼 액터는 (pitch : 0, yaw : -90, roll : 90)로 회전해서 스폰해야했다. 하지만 FRotator를 블루프린트를 통해 수정하는 것과 코드에서 FRotator를 수정하는 값이 달라 헤맸다. 아직 C++을 통해 정상적으로 값을 바꾸는 방법은 모르겠으나 블루프린트 값을 통해 정상적인 값을 얻을 수 있었다.
'UE4' 카테고리의 다른 글
UE4 Widget Animation C++ (0) | 2022.02.23 |
---|---|
[UE4][BUG] Android에서 시작 맵이 변경되지 않는 현상 (0) | 2021.12.21 |
UE4 ParticleSystemComponent Trails C++ (0) | 2021.12.02 |
UE4 UMG Image에 Mask를 이용한 Material 적용 (0) | 2021.11.11 |
UE4 Change Overall Scalability C++ (0) | 2021.10.27 |