You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find a bug in fucntion "perspective" which located at line 245 ~ 257 in glm/gtc/matrix_transform.inl.
When zNear = 0.0, the perspective matrix result is wrong.
because:
Result[0][0] = (2 * zNear) / (right - left)-----------------(1)
= (2* zNear) / (2.0 * tan(rad/2) * zNear aspect)--(2)
= 1.0 / (aspect * tan(rad/2))----------------(3)
Result[1][1] = (2 * zNear) / (right - left)------------------(1)
= (2 zNear) / (2.0 * tan(rad/2) * zNear )----(2)
= 1.0 / (tan(rad/2)) --------------------------(3)
your code use equation 2, when zNear = 0, it is make wrong result.
But if directly use equation 3, will reslut correct answer when zNear=0.
I don't know how to give this code into repository, so i send the modified
code in attachment.
I find a bug in fucntion "perspective" which located at line 245 ~ 257 in glm/gtc/matrix_transform.inl.
When zNear = 0.0, the perspective matrix result is wrong.
because:
Result[0][0] = (2 * zNear) / (right - left)-----------------(1)
= (2* zNear) / (2.0 * tan(rad/2) * zNear aspect)--(2)
= 1.0 / (aspect * tan(rad/2))----------------(3)
Result[1][1] = (2 * zNear) / (right - left)------------------(1)
= (2 zNear) / (2.0 * tan(rad/2) * zNear )----(2)
= 1.0 / (tan(rad/2)) --------------------------(3)
your code use equation 2, when zNear = 0, it is make wrong result.
But if directly use equation 3, will reslut correct answer when zNear=0.
I don't know how to give this code into repository, so i send the modified
code in attachment.
ifdef GLM_FORCE_RADIANS
else
endif
// the bug for zNear = 0.0, because of float err accumulate
// valType range = tan(rad / valType(2)) * zNear;
// valType left = -range * aspect;
// valType right = range * aspect;
// valType bottom = -range;
// valType top = range;
// detail::tmat4x4 Result(valType(0));
// Result[0][0] = (valType(2) * zNear) / (right - left);
// Result[1][1] = (valType(2) * zNear) / (top - bottom);
// Result[2][2] = - (zFar + zNear) / (zFar - zNear);
// Result[2][3] = - valType(1);
// Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
// return Result;
The text was updated successfully, but these errors were encountered: