Orthographic Projection
template <typename T> GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> ortho ( T left, T right, T bottom, T top, T zNear, T zFar ) { tmat4x4<T, defaultp> Result(1); Result[0][0] = static_cast<T>(2) / (right - left); Result[1][1] = static_cast<T>(2) / (top - bottom); Result[2][2] = - static_cast<T>(2) / (zFar - zNear); Result[3][0] = - (right + left) / (right - left); Result[3][1] = - (top + bottom) / (top - bottom); Result[3][2] = - (zFar + zNear) / (zFar - zNear); return Result; }
Perspective Projection
template <typename T> GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustum ( T left, T right, T bottom, T top, T nearVal, T farVal ) { tmat4x4<T, defaultp> Result(0); Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left); Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom); Result[2][0] = (right + left) / (right - left); Result[2][1] = (top + bottom) / (top - bottom); Result[2][2] = -(farVal + nearVal) / (farVal - nearVal); Result[2][3] = static_cast<T>(-1); Result[3][2] = -(static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal); return Result; }
http://www.songho.ca/opengl/gl_projectionmatrix.html
mat4 projectionMatrix = glm::perspective (float fovy, float aspect, float near, float far) fovy radian
top = tan(fovy/2) * near
right = top * aspect
projectionMatrix = glm::frustum(-right, right, -top, top, near, far)