add infinitePerspectiveRH_ZO

This commit is contained in:
azhirnov 2023-09-19 09:06:02 +03:00 committed by Christophe
parent 9cb19aa43f
commit ed1059731f
2 changed files with 63 additions and 3 deletions

View File

@ -483,7 +483,7 @@ namespace glm
} }
template<typename T> template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveRH(T fovy, T aspect, T zNear) GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveRH_NO(T fovy, T aspect, T zNear)
{ {
T const range = tan(fovy / static_cast<T>(2)) * zNear; T const range = tan(fovy / static_cast<T>(2)) * zNear;
T const left = -range * aspect; T const left = -range * aspect;
@ -500,6 +500,24 @@ namespace glm
return Result; return Result;
} }
template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveRH_ZO(T fovy, T aspect, T zNear)
{
T const range = tan(fovy / static_cast<T>(2)) * zNear;
T const left = -range * aspect;
T const right = range * aspect;
T const bottom = -range;
T const top = range;
mat<4, 4, T, defaultp> Result(static_cast<T>(0));
Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
Result[2][2] = - static_cast<T>(1);
Result[2][3] = - static_cast<T>(1);
Result[3][2] = - zNear;
return Result;
}
template<typename T> template<typename T>
GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveLH_NO(T fovy, T aspect, T zNear) GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveLH_NO(T fovy, T aspect, T zNear)
{ {
@ -543,8 +561,10 @@ namespace glm
return infinitePerspectiveLH_ZO(fovy, aspect, zNear); return infinitePerspectiveLH_ZO(fovy, aspect, zNear);
# elif GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO # elif GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO
return infinitePerspectiveLH_NO(fovy, aspect, zNear); return infinitePerspectiveLH_NO(fovy, aspect, zNear);
# else # elif GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO
return infinitePerspectiveRH(fovy, aspect, zNear); return infinitePerspectiveRH_ZO(fovy, aspect, zNear);
# elif GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO
return infinitePerspectiveRH_NO(fovy, aspect, zNear);
# endif # endif
} }

View File

@ -33,6 +33,26 @@ int test_perspective()
Error += glm::notEqual(F.z, 1.f, Eps); Error += glm::notEqual(F.z, 1.f, Eps);
} }
Projection = glm::perspectiveRH_ZO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
{
glm::vec4 N = Projection * glm::vec4{0.f, 0.f, -Near, 1.f};
glm::vec4 F = Projection * glm::vec4{0.f, 0.f, -Far, 1.f};
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, 0.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::perspectiveRH_NO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
{
glm::vec4 N = Projection * glm::vec4{0.f, 0.f, -Near, 1.f};
glm::vec4 F = Projection * glm::vec4{0.f, 0.f, -Far, 1.f};
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, -1.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
return Error; return Error;
} }
@ -66,6 +86,26 @@ int test_infinitePerspective()
Error += glm::notEqual(F.z, 1.f, Eps); Error += glm::notEqual(F.z, 1.f, Eps);
} }
Projection = glm::infinitePerspectiveRH_ZO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
{
glm::vec4 N = Projection * glm::vec4{0.f, 0.f, -Near, 1.f};
glm::vec4 F = Projection * glm::vec4{0.f, 0.f, -Inf, 1.f};
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, 0.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::infinitePerspectiveRH_NO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
{
glm::vec4 N = Projection * glm::vec4{0.f, 0.f, -Near, 1.f};
glm::vec4 F = Projection * glm::vec4{0.f, 0.f, -Inf, 1.f};
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, -1.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
return Error; return Error;
} }