From e15f7696e62ad51896e58fde0bda32df87339d8a Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sun, 23 Oct 2022 18:22:58 +0800 Subject: [PATCH] Rotations are stored as radians to reduce the number of conversions --- .../src/Math/Transform/SHTransformComponent.h | 4 ++-- .../src/Math/Transform/SHTransformSystem.cpp | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/SHADE_Engine/src/Math/Transform/SHTransformComponent.h b/SHADE_Engine/src/Math/Transform/SHTransformComponent.h index ce8bb6fe..2fe67bdd 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformComponent.h +++ b/SHADE_Engine/src/Math/Transform/SHTransformComponent.h @@ -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; diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index 8bd01fb4..5a540cd4 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -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();