def ortho_matrix(aspect, near, far, width): """ Camera frustum looks along -Z axis. Result frustum camera looks along -Z axis, like in OpenGL. """ height = aspect * width P = transformations.clip_matrix(-width/2, width/2, -height/2, height/2, near, far, perspective=False) P = np.dot(P, scale_matrix([1, 1, -1])) return np.float32(P)
def perspective_matrix(aspect, near, far, fov_h=45): """ Camera frustum looks along -Z axis. Result frustum camera looks along -Z axis, like in OpenGL. """ tan = np.tan(np.radians(fov_h) / 2) right = tan * near left = -right bottom, top = aspect * left, aspect * right P = transformations.clip_matrix(left, right, bottom, top, near, far, perspective=True) P = np.dot(P, scale_matrix([1, 1, -1])) return np.float32(-P)