Hi everybody,
I’m a Java developer getting into Unreal C++ and I’m having an hard time trying to figure out how to solve a simple (i guess) task: rotate a vector accordingly to mesh rotation.
I have a BP derived directly from a C++ class. The BP has a Scene component which contains 1 collision box and 4 UStaticMeshComponents.
The Scene has the pivot in lower right corner (see picture)
In the OnConstruction(FTransform& Transform)
method, I “draw” 4 debug lines which frame the frontal mesh component (see picture)
So far so good but when I try to rotate my BP by one or more axis then the frame is no more aligned with rotation.
I’m 100% sure that this is a rotation problem and i simply cannot find the correct way to do it.
I tried both using FRotationMatrix
and FRotator.RotateVector(FVector)
but none of them worked.
Here’s the relevant code:
// Getting the diagonal of my frontal mesh
FVector LowerDiagonalMeshPoint = FVector::ZeroVector;
FVector UpperDiagonalMeshPoint = FVector::ZeroVector;
FrontalMesh->GetLocalBounds(LowerDiagonalMeshPoint , UpperDiagonalMeshPoint );
// Getting the origin point in WorldSpace and relative Rotator
FVector OriginPointInWS = RootComponent->GetComponentLocation();
FRotator MeshRotator = RootComponent->GetComponentRotation();
// Calculate the correct position by taking into account the MeshLocation
FVector RelativeMin = MeshLocation + LowerDiagonalMeshPoint ;
FVector RelativeMax = MeshLocation + UpperDiagonalMeshPoint ;
// Calculate the front face corner points
FVector BottomLeft =FVector(RelativeMax.X, RelativeMax.Y, RelativeMin.Z);
FVector TopLeft = FVector(RelativeMax.X, RelativeMax.Y, RelativeMax.Z);
FVector BottomRight = FVector(RelativeMax.X, RelativeMin.Y, RelativeMin.Z);
FVector TopRight = FVector(RelativeMax.X, RelativeMin.Y, RelativeMax.Z);
//Draw debug lines
DrawDebugLine(GetWorld(), BottomLeft, TopLeft, FColor::Purple, false, 5.f, 0, 2.f);
DrawDebugLine(GetWorld(), TopLeft, TopRight, FColor::Purple, false, 5.f, 0, 2.f); DrawDebugLine(GetWorld(), TopRight, BottomRight, FColor::Purple, false, 5.f, 0, 2.f);
DrawDebugLine(GetWorld(), BottomRight, BottomLeft, FColor::Purple, false, 5.f, 0, 2.f);
Thanks for your help
Luca