mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
added rotation matrix
This commit is contained in:
@@ -349,19 +349,19 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Mat<3, 3, Type, St> RotationMatrixAxisX(const Angle& roll) noexcept
|
Mat<3, 3, Type, St> RotationMatAxisX(const Angle& roll) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{1, 0, 0},
|
{1, 0, 0},
|
||||||
{0, 0, roll.Cos(), -roll.Sin()},
|
{0, roll.Cos(), -roll.Sin()},
|
||||||
{0, 0, roll.Sin(), roll.Cos()},
|
{0, roll.Sin(), roll.Cos()},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Mat<3, 3, Type, St> RotationMatrixAxisY(const Angle& pitch) noexcept
|
Mat<3, 3, Type, St> RotationMatAxisY(const Angle& pitch) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
@@ -373,7 +373,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Mat<3, 3, Type, St> RotationMatrixAxisZ(const Angle& Yaw) noexcept
|
Mat<3, 3, Type, St> RotationMatAxisZ(const Angle& Yaw) noexcept
|
||||||
{
|
{
|
||||||
return
|
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
|
} // namespace omath
|
||||||
|
|||||||
@@ -10,56 +10,25 @@ namespace omath::source
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3 ForwardVector(const ViewAngles& angles)
|
inline Vector3 ForwardVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto cosPitch = angles.pitch.Cos();
|
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsForward.x}, {kAbsForward.y}, {kAbsForward.z}});
|
||||||
const auto sinPitch = angles.pitch.Sin();
|
|
||||||
|
|
||||||
const auto cosYaw = angles.yaw.Cos();
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
const auto sinYaw = angles.yaw.Sin();
|
|
||||||
|
|
||||||
|
|
||||||
return {cosPitch * cosYaw, cosPitch * sinYaw, -sinPitch};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3 RightVector(const ViewAngles& angles)
|
inline Vector3 RightVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto cosPitch = angles.pitch.Cos();
|
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsRight.x}, {kAbsRight.y}, {kAbsRight.z}});
|
||||||
const auto sinPitch = angles.pitch.Sin();
|
|
||||||
|
|
||||||
const auto cosYaw = angles.yaw.Cos();
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3 UpVector(const ViewAngles& angles)
|
inline Vector3 UpVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto cosPitch = angles.pitch.Cos();
|
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsUp.x}, {kAbsUp.y}, {kAbsUp.z}});
|
||||||
const auto sinPitch = angles.pitch.Sin();
|
|
||||||
|
|
||||||
const auto cosYaw = angles.yaw.Cos();
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|||||||
Reference in New Issue
Block a user