mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 17:03:27 +00:00
added ureachable
This commit is contained in:
@@ -677,11 +677,13 @@ namespace omath
|
|||||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
{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, far / (far - near), -(near * far) / (far - near)},
|
||||||
{0.f, 0.f, 1.f, 0.f}};
|
{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},
|
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, 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, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||||
{0.f, 0.f, 1.f, 0.f}};
|
{0.f, 0.f, 1.f, 0.f}};
|
||||||
|
else
|
||||||
|
std::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
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, 1.f / fov_half_tan, 0.f, 0.f},
|
||||||
{0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
|
{0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
|
||||||
{0.f, 0.f, -1.f, 0.f}};
|
{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},
|
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, 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, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||||
{0.f, 0.f, -1.f, 0.f}};
|
{0.f, 0.f, -1.f, 0.f}};
|
||||||
|
else
|
||||||
|
std::unreachable();
|
||||||
}
|
}
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
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, static_cast<Type>(1) / (far - near), -near / (far - near) },
|
||||||
{ 0.f, 0.f, 0.f, 1.f }
|
{ 0.f, 0.f, 0.f, 1.f }
|
||||||
};
|
};
|
||||||
else
|
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
{ 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, static_cast<Type>(2) / (far - near), -(far + near) / (far - near) },
|
||||||
{ 0.f, 0.f, 0.f, 1.f }
|
{ 0.f, 0.f, 0.f, 1.f }
|
||||||
};
|
};
|
||||||
|
else
|
||||||
|
std::unreachable();
|
||||||
}
|
}
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
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, -static_cast<Type>(1) / (far - near), -near / (far - near) },
|
||||||
{ 0.f, 0.f, 0.f, 1.f }
|
{ 0.f, 0.f, 0.f, 1.f }
|
||||||
};
|
};
|
||||||
else
|
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{ static_cast<Type>(2) / (right - left), 0.f, 0.f, -(right + left) / (right - left)},
|
{ 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, -static_cast<Type>(2) / (far - near), -(far + near) / (far - near) },
|
||||||
{ 0.f, 0.f, 0.f, 1.f }
|
{ 0.f, 0.f, 0.f, 1.f }
|
||||||
};
|
};
|
||||||
|
else
|
||||||
|
std::unreachable();
|
||||||
}
|
}
|
||||||
template<class T = float, MatStoreType St = MatStoreType::COLUMN_MAJOR>
|
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)
|
Mat<4, 4, T, St> mat_look_at_left_handed(const Vector3<T>& eye, const Vector3<T>& center, const Vector3<T>& up)
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ namespace omath::opengl_engine
|
|||||||
|
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec
|
const auto vec =
|
||||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_forward);
|
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)};
|
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||||
}
|
}
|
||||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec
|
const auto vec =
|
||||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_right);
|
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)};
|
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
|
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
|
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,
|
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 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)
|
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return {
|
return mat_perspective_right_handed<float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
field_of_view, aspect_ratio, near, far);
|
||||||
{0, 1.f / (fov_half_tan), 0, 0},
|
|
||||||
{0, 0, -far / (far - near), -(near * far) / (far - near)},
|
|
||||||
{0, 0, -1, 0},
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
std::unreachable();
|
||||||
{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},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} // namespace omath::opengl_engine
|
} // namespace omath::opengl_engine
|
||||||
|
|||||||
Reference in New Issue
Block a user