added rotation matrix

This commit is contained in:
2024-12-04 06:43:54 +03:00
parent db060e7f4d
commit 95c5073d86
2 changed files with 18 additions and 44 deletions

View File

@@ -349,19 +349,19 @@ namespace omath
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
[[nodiscard]]
constexpr Mat<3, 3, Type, St> RotationMatrixAxisX(const Angle& roll) noexcept
Mat<3, 3, Type, St> RotationMatAxisX(const Angle& roll) noexcept
{
return
{
{1, 0, 0},
{0, 0, roll.Cos(), -roll.Sin()},
{0, 0, roll.Sin(), roll.Cos()},
{1, 0, 0},
{0, roll.Cos(), -roll.Sin()},
{0, roll.Sin(), roll.Cos()},
};
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
[[nodiscard]]
constexpr Mat<3, 3, Type, St> RotationMatrixAxisY(const Angle& pitch) noexcept
Mat<3, 3, Type, St> RotationMatAxisY(const Angle& pitch) noexcept
{
return
{
@@ -373,7 +373,7 @@ namespace omath
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
[[nodiscard]]
constexpr Mat<3, 3, Type, St> RotationMatrixAxisZ(const Angle& Yaw) noexcept
Mat<3, 3, Type, St> RotationMatAxisZ(const Angle& Yaw) noexcept
{
return
{
@@ -383,5 +383,10 @@ namespace omath
};
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
[[nodiscard]]
Mat<3, 3, Type, St> RotationMat(const ViewAngles& angles) noexcept
{
return RotationMatAxisY(angles.pitch) * RotationMatAxisZ(angles.yaw) * RotationMatAxisX(angles.roll);
}
} // namespace omath

View File

@@ -10,56 +10,25 @@ namespace omath::source
[[nodiscard]]
inline Vector3 ForwardVector(const ViewAngles& angles)
{
const auto cosPitch = angles.pitch.Cos();
const auto sinPitch = angles.pitch.Sin();
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsForward.x}, {kAbsForward.y}, {kAbsForward.z}});
const auto cosYaw = angles.yaw.Cos();
const auto sinYaw = angles.yaw.Sin();
return {cosPitch * cosYaw, cosPitch * sinYaw, -sinPitch};
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
}
[[nodiscard]]
inline Vector3 RightVector(const ViewAngles& angles)
{
const auto cosPitch = angles.pitch.Cos();
const auto sinPitch = angles.pitch.Sin();
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsRight.x}, {kAbsRight.y}, {kAbsRight.z}});
const auto cosYaw = angles.yaw.Cos();
const auto sinYaw = angles.yaw.Sin();
const auto cosRoll = angles.roll.Cos();
const auto sinRoll = angles.roll.Sin();
return
{
-1 * sinRoll * sinPitch * cosYaw + -1 * cosRoll * -sinYaw,
-1 * sinRoll * sinPitch * sinYaw + -1 * cosRoll * cosYaw,
-1 * sinRoll * cosPitch
};
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
}
[[nodiscard]]
inline Vector3 UpVector(const ViewAngles& angles)
{
const auto cosPitch = angles.pitch.Cos();
const auto sinPitch = angles.pitch.Sin();
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsUp.x}, {kAbsUp.y}, {kAbsUp.z}});
const auto cosYaw = angles.yaw.Cos();
const auto sinYaw = angles.yaw.Sin();
const auto cosRoll = angles.roll.Cos();
const auto sinRoll = angles.roll.Sin();
return
{
cosRoll * sinPitch * cosYaw + - sinRoll * -sinYaw,
cosRoll * sinPitch * sinYaw + - sinRoll * cosYaw,
cosRoll * cosPitch,
};
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
}
[[nodiscard]]