SP3-16 Quaternions #112

Merged
direnbharwani merged 17 commits from SP3-16-Math into main 2022-10-23 20:07:17 +08:00
2 changed files with 8 additions and 13 deletions
Showing only changes of commit e15f7696e6 - Show all commits

View File

@ -127,8 +127,8 @@ namespace SHADE
// We store euler angle rotations separately to interface with transform quaternions.
// Reading quaternions are unreliable.
SHVec3 localRotation; // Stored in degrees
SHVec3 worldRotation; // Stored in degrees
SHVec3 localRotation; // Stored in Radians
SHVec3 worldRotation; // Stored in Radians
SHTransform local; // Local TRS holds Local To World Transform
SHTransform world;

View File

@ -270,7 +270,7 @@ namespace SHADE
tf.world.position = SHVec3::Transform(tf.local.position, localToWorld);
tf.world.scale = tf.local.scale * (parent ? parent->GetLocalScale() : SHVec3::One);
SHVec3 worldRotRad, localRotRad;
if (convertRotation)
{
@ -278,10 +278,11 @@ namespace SHADE
// Set the orientation
// Wrap rotations between -360 and 360 and convert to radians
SHVec3 worldRotRad, localRotRad;
for (size_t i = 0; i < SHVec3::SIZE; ++i)
{
worldRotRad[i] = SHMath::DegreesToRadians(SHMath::Wrap(tf.worldRotation[i], -360.0f, 360.0f));
localRotRad[i] = SHMath::DegreesToRadians(SHMath::Wrap(tf.localRotation[i], -360.0f, 360.0f));
worldRotRad[i] = SHMath::Wrap(tf.worldRotation[i], -SHMath::TWO_PI, SHMath::TWO_PI);
localRotRad[i] = SHMath::Wrap(tf.localRotation[i], -SHMath::TWO_PI, SHMath::TWO_PI);
}
tf.world.orientation = SHQuaternion::FromEuler(worldRotRad);
@ -292,14 +293,8 @@ namespace SHADE
tf.world.orientation = (parent ? parent->GetLocalOrientation() : SHQuaternion::Identity) * tf.local.orientation;
// Set the euler angle rotations
worldRotRad = tf.world.orientation.ToEuler();
localRotRad = tf.local.orientation.ToEuler();
for (size_t i = 0; i < SHVec3::SIZE; ++i)
{
tf.worldRotation[i] = SHMath::RadiansToDegrees(worldRotRad[i]);
tf.localRotation[i] = SHMath::RadiansToDegrees(localRotRad[i]);
}
tf.worldRotation = tf.world.orientation.ToEuler();
tf.localRotation = tf.local.orientation.ToEuler();
}
tf.world.ComputeTRS();