Created
May 26, 2017 23:05
-
-
Save braustin20/bf40eed0adef1b4ed577cce34ce419f0 to your computer and use it in GitHub Desktop.
Unreal 4 snippet which calculates difference in rotation over time for stunt detection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FVector ATacopocalypsePawn::CalcQuatDifference() | |
{ | |
//Get the current rotation in quaternion | |
FQuat CurrentQuat = GetTransform().GetRotation(); | |
//Get the quaternion rotational difference | |
FQuat TempQuat = PrevQuat.Inverse() * CurrentQuat; | |
//Update the previous rotation value | |
PrevQuat = CurrentQuat; | |
//Get the axis values | |
float roll = FMath::Atan2(2 * TempQuat.Y * TempQuat.W - 2 * TempQuat.X * TempQuat.Z, 1 - 2 * TempQuat.Y * TempQuat.Y - 2 * TempQuat.Z * TempQuat.Z); | |
float pitch = FMath::Atan2(2 * TempQuat.X * TempQuat.W - 2 * TempQuat.Y * TempQuat.Z, 1 - 2 * TempQuat.X * TempQuat.X - 2 * TempQuat.Z * TempQuat.Z); | |
float yaw = FMath::Asin(2 * TempQuat.X * TempQuat.Y + 2 * TempQuat.Z * TempQuat.W); | |
//Convert the values to degrees | |
roll = FMath::RadiansToDegrees(roll); | |
pitch = FMath::RadiansToDegrees(pitch); | |
yaw = FMath::RadiansToDegrees(yaw); | |
//Make sure the values are positive | |
FVector DifferenceVector = FVector(FMath::Abs(pitch), FMath::Abs(roll), FMath::Abs(yaw)); | |
return FVector(DifferenceVector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment