Skip to content

Commit

Permalink
Made Quaternion and Transform serializable.
Browse files Browse the repository at this point in the history
Fixed transform's angle rotation.
  • Loading branch information
Wolftein committed Nov 13, 2024
1 parent 0c8c17e commit 2634b54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
10 changes: 9 additions & 1 deletion Source/Public/Aurora.Math/Quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline namespace Math
{
// -=(Undocumented)=-
template<typename Base>
class Quaternion final
class Quaternion final : public Serializable<Quaternion<Base>>
{
public:

Expand Down Expand Up @@ -160,6 +160,14 @@ inline namespace Math
return (* this);
}

// \see Serializable::OnSerialize
template<typename Stream>
void OnSerialize(Stream Archive)
{
Archive.SerializeObject(mComplexes);
Archive.SerializeNumber(mReal);
}

public:

// -=(Undocumented)=-
Expand Down
29 changes: 16 additions & 13 deletions Source/Public/Aurora.Math/Transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline namespace Math
{
// -=(Undocumented)=-
template<typename Base>
class Transform final
class Transform final : public Serializable<Transform<Base>>
{
public:

Expand Down Expand Up @@ -50,7 +50,6 @@ inline namespace Math
Ref<Transform> SetPosition(Ref<const Vector3<Base>> Position)
{
mPosition = Position;

return (* this);
}

Expand All @@ -70,7 +69,6 @@ inline namespace Math
Ref<Transform> SetScale(Ref<const Vector3<Base>> Scale)
{
mScale = Scale;

return (* this);
}

Expand All @@ -84,7 +82,6 @@ inline namespace Math
Ref<Transform> SetRotation(Ref<const Quaternion<Base>> Rotation)
{
mRotation = Rotation;

return (* this);
}

Expand Down Expand Up @@ -131,30 +128,27 @@ inline namespace Math
Ref<Transform> Rotate(Ref<const Quaternion<Base>> Rotation)
{
mRotation = mRotation * Rotation;

return (* this);
}

// -=(Undocumented)=-
Ref<Transform> Rotate(Ref<const Vector2<Base>> Angles)
{
const Quaternionf XAxis(Vector3<Base>(1, 0, 0), Angles.GetX());
const Quaternionf YAxis(Vector3<Base>(0, 1, 0), Angles.GetY());

mRotation = YAxis * mRotation * XAxis;
const Quaternionf XAxis(Quaternion<Base>::FromAngles(Angles.GetX(), Vector3<Base>(1, 0, 0)));
const Quaternionf YAxis(Quaternion<Base>::FromAngles(Angles.GetY(), Vector3<Base>(0, 1, 0)));

mRotation = mRotation * XAxis * YAxis;
return (* this);
}

// -=(Undocumented)=-
Ref<Transform> Rotate(Ref<const Vector3<Base>> Angles)
{
const Quaternionf XAxis(Vector3<Base>(1, 0, 0), Angles.GetX());
const Quaternionf YAxis(Vector3<Base>(0, 1, 0), Angles.GetY());
const Quaternionf ZAxis(Vector3<Base>(0, 0, 1), Angles.GetZ());
const Quaternionf XAxis(Quaternion<Base>::FromAngles(Angles.GetX(), Vector3<Base>(1, 0, 0)));
const Quaternionf YAxis(Quaternion<Base>::FromAngles(Angles.GetY(), Vector3<Base>(0, 1, 0)));
const Quaternionf ZAxis(Quaternion<Base>::FromAngles(Angles.GetZ(), Vector3<Base>(0, 0, 1)));

mRotation = mRotation * XAxis * YAxis * ZAxis;

return (* this);
}

Expand All @@ -173,6 +167,15 @@ inline namespace Math
return Translation * Rotation * Scale;
}

// \see Serializable::OnSerialize
template<typename Stream>
void OnSerialize(Stream Archive)
{
Archive.SerializeObject(mPosition);
Archive.SerializeObject(mScale);
Archive.SerializeObject(mRotation);
}

private:

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down

0 comments on commit 2634b54

Please sign in to comment.