mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 15:33:26 +00:00
switched to 4x4
This commit is contained in:
@@ -349,44 +349,47 @@ 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]]
|
||||||
Mat<3, 3, Type, St> RotationMatAxisX(const Angle& roll) noexcept
|
Mat<4, 4, Type, St> RotationMatAxisX(const Angle& angle) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{1, 0, 0},
|
{1, 0, 0, 0},
|
||||||
{0, roll.Cos(), -roll.Sin()},
|
{0, angle.Cos(), -angle.Sin(), 0},
|
||||||
{0, roll.Sin(), roll.Cos()},
|
{0, angle.Sin(), angle.Cos(), 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat<3, 3, Type, St> RotationMatAxisY(const Angle& pitch) noexcept
|
Mat<4, 4, Type, St> RotationMatAxisY(const Angle& angle) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{pitch.Cos(), 0, pitch.Sin()},
|
{angle.Cos(), 0, angle.Sin(), 0},
|
||||||
{0 , 1, 0},
|
{0 , 1, 0, 0},
|
||||||
{-pitch.Sin(), 0, pitch.Cos()},
|
{-angle.Sin(), 0, angle.Cos(), 0},
|
||||||
|
{0 , 0, 0, 1}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat<3, 3, Type, St> RotationMatAxisZ(const Angle& Yaw) noexcept
|
Mat<4, 4, Type, St> RotationMatAxisZ(const Angle& angle) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{Yaw.Cos(), -Yaw.Sin(), 0},
|
{angle.Cos(), -angle.Sin(), 0, 0},
|
||||||
{Yaw.Sin(), Yaw.Cos(), 0},
|
{angle.Sin(), angle.Cos(), 0, 0},
|
||||||
{0, 0, 1},
|
{0, 0, 1, 0},
|
||||||
|
{0, 0, 0, 1},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat<3, 3, Type, St> RotationMat(const ViewAngles& angles) noexcept
|
Mat<4, 4, Type, St> RotationMat(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return RotationMatAxisY(angles.pitch) * RotationMatAxisZ(angles.yaw) * RotationMatAxisX(angles.roll);
|
return RotationMatAxisZ(angles.yaw) * RotationMatAxisY(angles.pitch) * RotationMatAxisX(angles.roll);
|
||||||
}
|
}
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace omath::source
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3 ForwardVector(const ViewAngles& angles)
|
inline Vector3 ForwardVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsForward.x}, {kAbsForward.y}, {kAbsForward.z}});
|
const auto vec = RotationMat(angles) * MatColumnFromVector(kAbsForward);
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace omath::source
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3 RightVector(const ViewAngles& angles)
|
inline Vector3 RightVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsRight.x}, {kAbsRight.y}, {kAbsRight.z}});
|
const auto vec = RotationMat(angles) * MatColumnFromVector(kAbsRight);
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace omath::source
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3 UpVector(const ViewAngles& angles)
|
inline Vector3 UpVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = RotationMat(angles) * Mat<3, 1>({{kAbsUp.x}, {kAbsUp.y}, {kAbsUp.z}});
|
const auto vec = RotationMat(angles) * MatColumnFromVector(kAbsUp);
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ namespace omath::source
|
|||||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{-1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||||
{0, -1.f / (fovHalfTan), 0, 0},
|
{0, -1.f / (fovHalfTan), 0, 0},
|
||||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||||
{0, 0, 1, 0},
|
{0, 0, 1, 0},
|
||||||
|
|||||||
Reference in New Issue
Block a user