mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 17:03:27 +00:00
Merge pull request #178 from orange-cpp/feature/imrovements
Feature/imrovements
This commit is contained in:
@@ -677,11 +677,13 @@ namespace omath
|
||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
||||
{0.f, 0.f, far / (far - near), -(near * far) / (far - near)},
|
||||
{0.f, 0.f, 1.f, 0.f}};
|
||||
else
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
|
||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
||||
{0.f, 0.f, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||
{0.f, 0.f, 1.f, 0.f}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
@@ -697,11 +699,13 @@ namespace omath
|
||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
||||
{0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
|
||||
{0.f, 0.f, -1.f, 0.f}};
|
||||
else
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
|
||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
||||
{0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||
{0.f, 0.f, -1.f, 0.f}};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
@@ -717,7 +721,7 @@ namespace omath
|
||||
{ 0.f, 0.f, static_cast<Type>(1) / (far - near), -near / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
else
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return
|
||||
{
|
||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
@@ -725,6 +729,8 @@ namespace omath
|
||||
{ 0.f, 0.f, static_cast<Type>(2) / (far - near), -(far + near) / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
@@ -740,7 +746,7 @@ namespace omath
|
||||
{ 0.f, 0.f, -static_cast<Type>(1) / (far - near), -near / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
else
|
||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return
|
||||
{
|
||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
||||
@@ -748,6 +754,8 @@ namespace omath
|
||||
{ 0.f, 0.f, -static_cast<Type>(2) / (far - near), -(far + near) / (far - near) },
|
||||
{ 0.f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
else
|
||||
std::unreachable();
|
||||
}
|
||||
template<class T = float, MatStoreType St = MatStoreType::COLUMN_MAJOR>
|
||||
Mat<4, 4, T, St> mat_look_at_left_handed(const Vector3<T>& eye, const Vector3<T>& center, const Vector3<T>& up)
|
||||
|
||||
@@ -41,6 +41,9 @@ namespace omath::cry_engine
|
||||
return mat_perspective_left_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
|
||||
return mat_perspective_left_handed(field_of_view, aspect_ratio, near, far);
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return mat_perspective_left_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
std::unreachable();
|
||||
}
|
||||
} // namespace omath::unity_engine
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace omath::frostbite_engine
|
||||
return mat_perspective_left_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
|
||||
return mat_perspective_left_handed(field_of_view, aspect_ratio, near, far);
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return mat_perspective_left_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
|
||||
std::unreachable();
|
||||
}
|
||||
} // namespace omath::unity_engine
|
||||
|
||||
@@ -50,12 +50,13 @@ namespace omath::iw_engine
|
||||
{0, 0, far / (far - near), -(near * far) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
std::unreachable();
|
||||
};
|
||||
} // namespace omath::iw_engine
|
||||
|
||||
@@ -8,15 +8,15 @@ namespace omath::opengl_engine
|
||||
|
||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec
|
||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_forward);
|
||||
const auto vec =
|
||||
rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_forward);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||
{
|
||||
const auto vec
|
||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_right);
|
||||
const auto vec =
|
||||
rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_right);
|
||||
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace omath::opengl_engine
|
||||
}
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return mat_look_at_right_handed(cam_origin, cam_origin+forward_vector(angles), up_vector(angles));
|
||||
return mat_look_at_right_handed(cam_origin, cam_origin + forward_vector(angles), up_vector(angles));
|
||||
}
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||
{
|
||||
@@ -39,21 +39,14 @@ namespace omath::opengl_engine
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far, const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return mat_perspective_right_handed<float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, -far / (far - near), -(near * far) / (far - near)},
|
||||
{0, 0, -1, 0},
|
||||
};
|
||||
return mat_perspective_right_handed<float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, -(far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||
{0, 0, -1, 0},
|
||||
};
|
||||
std::unreachable();
|
||||
}
|
||||
} // namespace omath::opengl_engine
|
||||
|
||||
@@ -50,12 +50,13 @@ namespace omath::source_engine
|
||||
{0, 0, far / (far - near), -(near * far) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
std::unreachable();
|
||||
}
|
||||
} // namespace omath::source_engine
|
||||
|
||||
@@ -40,7 +40,10 @@ namespace omath::unity_engine
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return omath::mat_perspective_right_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
field_of_view, aspect_ratio, near, far);
|
||||
|
||||
return omath::mat_perspective_right_handed(field_of_view, aspect_ratio, near, far);
|
||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||
return omath::mat_perspective_right_handed<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(field_of_view, aspect_ratio,
|
||||
near, far);
|
||||
std::unreachable();
|
||||
}
|
||||
} // namespace omath::unity_engine
|
||||
|
||||
Reference in New Issue
Block a user