Added a degree getter and setter for rotation

This commit is contained in:
Diren D Bharwani 2022-10-21 00:08:24 +08:00
parent fda33f7461
commit a52f0ddeed
3 changed files with 86 additions and 22 deletions

View File

@ -38,7 +38,7 @@ Collapsed=0
DockId=0x00000002,0
[Docking][Data]
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=-227,-1256 Size=1920,1012 Split=X
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1481,1036 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=349,1036 Split=Y Selected=0x1E6EB881
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881

View File

@ -12,6 +12,8 @@
// Primary Header
#include "SHTransformComponent.h"
// Project Headers
#include "Math/SHMathHelpers.h"
namespace SHADE
{
@ -43,6 +45,15 @@ namespace SHADE
return local.rotation;
}
SHVec3 SHTransformComponent::GetLocalRotationDeg() const noexcept
{
SHVec3 rot = local.rotation;
rot.x = SHMath::RadiansToDegrees(rot.x);
rot.y = SHMath::RadiansToDegrees(rot.y);
rot.z = SHMath::RadiansToDegrees(rot.z);
return rot;
}
const SHVec3& SHTransformComponent::GetLocalScale() const noexcept
{
return local.scale;
@ -58,6 +69,15 @@ namespace SHADE
return world.rotation;
}
SHVec3 SHTransformComponent::GetWorldRotationDeg() const noexcept
{
SHVec3 rot = world.rotation;
rot.x = SHMath::RadiansToDegrees(rot.x);
rot.y = SHMath::RadiansToDegrees(rot.y);
rot.z = SHMath::RadiansToDegrees(rot.z);
return rot;
}
const SHVec3& SHTransformComponent::GetWorldScale() const noexcept
{
return world.scale;
@ -94,6 +114,15 @@ namespace SHADE
local.rotation = newLocalRotation;
}
void SHTransformComponent::SetLocalRotationDeg(SHVec3 newLocalRotationDeg) noexcept
{
dirty = true;
local.rotation.x = SHMath::DegreesToRadians(newLocalRotationDeg.x);
local.rotation.y = SHMath::DegreesToRadians(newLocalRotationDeg.y);
local.rotation.z = SHMath::DegreesToRadians(newLocalRotationDeg.z);
}
void SHTransformComponent::SetLocalRotation(float pitch, float yaw, float roll) noexcept
{
dirty = true;
@ -103,6 +132,13 @@ namespace SHADE
local.rotation.z = roll;
}
void SHTransformComponent::SetLocalRotationDeg(float pitch, float yaw, float roll) noexcept
{
local.rotation.x = SHMath::DegreesToRadians(pitch);
local.rotation.y = SHMath::DegreesToRadians(yaw);
local.rotation.z = SHMath::DegreesToRadians(roll);
}
void SHTransformComponent::SetLocalScale(const SHVec3& newLocalScale) noexcept
{
dirty = true;
@ -125,6 +161,17 @@ namespace SHADE
updateQueue.push({ UpdateCommandType::WORLD_ROTATION, newWorldRotation });
}
void SHTransformComponent::SetWorldRotationDeg(const SHVec3& newWorldRotation) noexcept
{
dirty = true;
world.rotation.x = SHMath::DegreesToRadians(newWorldRotation.x);
world.rotation.y = SHMath::DegreesToRadians(newWorldRotation.y);
world.rotation.z = SHMath::DegreesToRadians(newWorldRotation.z);
updateQueue.push({ UpdateCommandType::WORLD_ROTATION, world.rotation });
}
void SHTransformComponent::SetWorldRotation(float pitch, float yaw, float roll) noexcept
{
dirty = true;
@ -136,6 +183,17 @@ namespace SHADE
updateQueue.push({ UpdateCommandType::WORLD_ROTATION, SHVec3{ pitch, yaw, roll} });
}
void SHTransformComponent::SetWorldRotationDeg(float pitch, float yaw, float roll) noexcept
{
dirty = true;
world.rotation.x = SHMath::DegreesToRadians(pitch);
world.rotation.y = SHMath::DegreesToRadians(yaw);
world.rotation.z = SHMath::DegreesToRadians(roll);
updateQueue.push({ UpdateCommandType::WORLD_ROTATION, world.rotation });
}
void SHTransformComponent::SetWorldScale(const SHVec3& newWorldScale) noexcept
{
dirty = true;
@ -152,7 +210,7 @@ RTTR_REGISTRATION
using namespace rttr;
registration::class_<SHTransformComponent>("Transform Component")
.property("Translate" , &SHTransformComponent::GetLocalPosition , &SHTransformComponent::SetLocalPosition )
.property("Rotate" , &SHTransformComponent::GetLocalRotation , select_overload<void(SHVec3 const&)>(&SHTransformComponent::SetLocalRotation) )
.property("Scale" , &SHTransformComponent::GetLocalScale , &SHTransformComponent::SetLocalScale );
.property("Translate" , &SHTransformComponent::GetLocalPosition , &SHTransformComponent::SetLocalPosition )
.property("Rotate" , &SHTransformComponent::GetLocalRotationDeg, select_overload<void(SHVec3)>(&SHTransformComponent::SetLocalRotationDeg))
.property("Scale" , &SHTransformComponent::GetLocalScale , &SHTransformComponent::SetLocalScale );
}

View File

@ -56,32 +56,38 @@ namespace SHADE
/* Getter Functions */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] bool HasChanged () const noexcept;
[[nodiscard]] bool HasChanged () const noexcept;
[[nodiscard]] const SHVec3& GetLocalPosition () const noexcept;
[[nodiscard]] const SHVec3& GetLocalRotation () const noexcept;
[[nodiscard]] const SHVec3& GetLocalScale () const noexcept;
[[nodiscard]] const SHVec3& GetWorldPosition () const noexcept;
[[nodiscard]] const SHVec3& GetWorldRotation () const noexcept;
[[nodiscard]] const SHVec3& GetWorldScale () const noexcept;
[[nodiscard]] const SHVec3& GetLocalPosition () const noexcept;
[[nodiscard]] const SHVec3& GetLocalRotation () const noexcept;
[[nodiscard]] SHVec3 GetLocalRotationDeg () const noexcept;
[[nodiscard]] const SHVec3& GetLocalScale () const noexcept;
[[nodiscard]] const SHVec3& GetWorldPosition () const noexcept;
[[nodiscard]] const SHVec3& GetWorldRotation () const noexcept;
[[nodiscard]] SHVec3 GetWorldRotationDeg () const noexcept;
[[nodiscard]] const SHVec3& GetWorldScale () const noexcept;
[[nodiscard]] const SHMatrix& GetLocalToWorld () const noexcept;
[[nodiscard]] SHMatrix GetWorldToLocal () const noexcept;
[[nodiscard]] const SHMatrix& GetLocalToWorld () const noexcept;
[[nodiscard]] SHMatrix GetWorldToLocal () const noexcept;
[[nodiscard]] const SHMatrix& GetTRS () const noexcept;
[[nodiscard]] const SHMatrix& GetTRS () const noexcept;
/*---------------------------------------------------------------------------------*/
/* Setter Functions */
/*---------------------------------------------------------------------------------*/
void SetLocalPosition (const SHVec3& newLocalPosition) noexcept;
void SetLocalRotation (const SHVec3& newLocalRotation) noexcept;
void SetLocalRotation (float pitch, float yaw, float roll) noexcept;
void SetLocalScale (const SHVec3& newLocalScale) noexcept;
void SetWorldPosition (const SHVec3& newWorldPosition) noexcept;
void SetWorldRotation (const SHVec3& newWorldRotation) noexcept;
void SetWorldRotation (float pitch, float yaw, float roll) noexcept;
void SetWorldScale (const SHVec3& newWorldScale) noexcept;
void SetLocalPosition (const SHVec3& newLocalPosition) noexcept;
void SetLocalRotation (const SHVec3& newLocalRotation) noexcept;
void SetLocalRotationDeg (SHVec3 newLocalRotationDeg) noexcept;
void SetLocalRotation (float pitch, float yaw, float roll) noexcept;
void SetLocalRotationDeg (float pitch, float yaw, float roll) noexcept;
void SetLocalScale (const SHVec3& newLocalScale) noexcept;
void SetWorldPosition (const SHVec3& newWorldPosition) noexcept;
void SetWorldRotation (const SHVec3& newWorldRotation) noexcept;
void SetWorldRotationDeg (const SHVec3& newWorldRotation) noexcept;
void SetWorldRotation (float pitch, float yaw, float roll) noexcept;
void SetWorldRotationDeg (float pitch, float yaw, float roll) noexcept;
void SetWorldScale (const SHVec3& newWorldScale) noexcept;
private:
/*---------------------------------------------------------------------------------*/