I can’t say whether it’s a bug, feature or if I just don’t get something, but this puzzles me alot. When I create a matrix from a normal vector with FRotationMatrix::MakeFromZ I will get proper matrix where Z points into specified direction. After I create a rotator from it by using Rotator() method, I get a rotator that always faces positive x, y and z axes. This causing my particle effects to look weird.
Examples, normal vector (matrix Z axis) → rotator Z axis
1, 0, 0 → 1, 0, 0
-1, 0, 0 → 1, 0, 0
0, -1, 0 → 0, 1, 0
etc. This happens for all axes as well as for rotated angles so that the effect always points into positive world quadrad. See below the code I’m using.
FMatrix matrix = FRotationMatrix::MakeFromZ(normal);
FRotator rotation = matrix.Rotator();
UGameplayStatics::SpawnEmitterAtLocation(this, pSystem, position, rotation, true);
Any ideas what is wrong?
Edit
I did additional testing and found out that its indeed something to do with rotator (or how I use it). I made following test and ran it twice for vector opposite to each other.
Code I used:
FMatrix matrix = FRotationMatrix::MakeFromZ(normal);
FRotator rotation = matrix.Rotator();
FQuat fromMatrix = FQuat(matrix);
FQuat fromRotator = FQuat(rotation);
LOG4(_T("Matrix %f %f %f %f"), fromMatrix.X, fromMatrix.Y, fromMatrix.Z, fromMatrix.W);
LOG4(_T("Rotator %f %f %f %f"), fromRotator.X, fromRotator.Y, fromRotator.Z, fromRotator.W);
I got following results. The latter one gives different result from same input.
Using vector V
Matrix 0.707107 0.000001 0.000001 0.707107
Rotator 0.707107 0.000001 0.000001 0.707107
Using vector -V
Matrix -0.000001 0.707107 0.707107 -0.000001
Rotator 0.000001 -0.707107 -0.707107 0.000001