mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
removed method from Mat added method for unity
This commit is contained in:
@@ -16,6 +16,9 @@ namespace omath::iw_engine
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> UpVector(const ViewAngles& angles);
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles);
|
||||||
|
|
||||||
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ namespace omath::source_engine
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4x4 RotationMatrix(const ViewAngles& angles);
|
Mat4x4 RotationMatrix(const ViewAngles& angles);
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> RightVector(const ViewAngles& angles);
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
|
|
||||||
@@ -21,9 +20,6 @@ namespace omath::source_engine
|
|||||||
|
|
||||||
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
|
||||||
|
|
||||||
} // namespace omath::source
|
} // namespace omath::source
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace omath::unity_engine
|
|||||||
|
|
||||||
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
|||||||
@@ -428,13 +428,6 @@ namespace omath
|
|||||||
} * MatTranslation<Type, St>(-cameraOrigin);
|
} * MatTranslation<Type, St>(-cameraOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
|
|
||||||
[[nodiscard]]
|
|
||||||
Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept
|
|
||||||
{
|
|
||||||
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat<4, 4, Type, St> MatPerspectiveLeftHanded(const float fieldOfView, const float aspectRatio, const float near,
|
Mat<4, 4, Type, St> MatPerspectiveLeftHanded(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
|||||||
@@ -9,23 +9,27 @@ namespace omath::iw_engine
|
|||||||
|
|
||||||
Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
const auto vec = RotationMatrix(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)};
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3<float> RightVector(const ViewAngles& angles)
|
Vector3<float> RightVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
const auto vec = RotationMatrix(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)};
|
||||||
}
|
}
|
||||||
Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> UpVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
const auto vec = RotationMatrix(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)};
|
||||||
}
|
}
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
||||||
|
}
|
||||||
|
|
||||||
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ namespace omath::unity_engine
|
|||||||
{
|
{
|
||||||
Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
const auto vec = RotationMatrix(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)};
|
||||||
}
|
}
|
||||||
Vector3<float> RightVector(const ViewAngles& angles)
|
Vector3<float> RightVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
const auto vec = RotationMatrix(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)};
|
||||||
}
|
}
|
||||||
Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> UpVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
const auto vec = RotationMatrix(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)};
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,12 @@ namespace omath::unity_engine
|
|||||||
return MatCameraView<float, MatStoreType::ROW_MAJOR>(ForwardVector(angles), -RightVector(angles),
|
return MatCameraView<float, MatStoreType::ROW_MAJOR>(ForwardVector(angles), -RightVector(angles),
|
||||||
UpVector(angles), cam_origin);
|
UpVector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
return MatRotationAxisZ(angles.roll) *
|
||||||
|
MatRotationAxisY(angles.yaw) *
|
||||||
|
MatRotationAxisX(angles.pitch);
|
||||||
|
}
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
const float far)
|
const float far)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ TEST(UnitTestOpenGL, ForwardVector)
|
|||||||
std::print("{}\n", angles.pitch.AsDegrees());
|
std::print("{}\n", angles.pitch.AsDegrees());
|
||||||
const auto forward2 = omath::opengl_engine::ForwardVector(angles);
|
const auto forward2 = omath::opengl_engine::ForwardVector(angles);
|
||||||
|
|
||||||
std::println("{} {} {}", forward2.x, (int)forward2.y, forward2.z);
|
std::println("{} {} {}", forward2.x, (int)forward2.y, (int)forward2.z);
|
||||||
EXPECT_EQ(forward, omath::opengl_engine::kAbsForward);
|
EXPECT_EQ(forward, omath::opengl_engine::kAbsForward);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user