Skip to content

Instantly share code, notes, and snippets.

@BlenderSleuth
Last active October 6, 2022 20:35
Show Gist options
  • Save BlenderSleuth/e274f8f8a71aca94ace48cc10f1852ad to your computer and use it in GitHub Desktop.
Save BlenderSleuth/e274f8f8a71aca94ace48cc10f1852ad to your computer and use it in GitHub Desktop.
A UE4 Static library for common quaternion operations
#pragma once
#include "CoreMinimal.h"
/**
* Library of commonly used custom functions
*/
class QuatStaticLibrary
{
public:
// Finds the difference between two quats
static FORCEINLINE FQuat FindDeltaQuat(const FQuat& OldQuat, const FQuat& NewQuat)
{
return NewQuat * OldQuat.Inverse();
}
// Converts Quat from Local Rotation to World rotation (applies delta rotation in local space)
static FORCEINLINE FQuat QuatLocalToWorld(const FQuat& LocalQuat, const FQuat& ComponentQuat)
{
return ComponentQuat * LocalQuat;
}
// Converts Quat from World Rotation to Local rotation
static FORCEINLINE FQuat QuatWorldToLocal(const FQuat& WorldQuat, const FQuat& ComponentQuat)
{
return ComponentQuat.Inverse() * WorldQuat;
}
static FORCEINLINE FQuat ApplyDeltaQuatInWorldSpace(const FQuat& DeltaQuat, const FQuat& ComponentQuat)
{
return DeltaQuat * ComponentQuat;
}
static FORCEINLINE FQuat ApplyDeltaQuatInLocalSpace(const FQuat& DeltaQuat, const FQuat& ComponentQuat)
{
return QuatLocalToWorld(DeltaQuat, ComponentQuat);
}
static FORCEINLINE FRotator RotatorLocalToWorld(const FRotator& LocalRot, const FQuat& ComponentQuat)
{
return QuatStaticLibrary::QuatLocalToWorld(LocalRot.Quaternion(), ComponentQuat).Rotator();
}
static FORCEINLINE FRotator RotatorWorldToLocal(const FRotator& WorldRot, const FQuat& ComponentQuat)
{
return QuatStaticLibrary::QuatWorldToLocal(WorldRot.Quaternion(), ComponentQuat).Rotator();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment