Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CameraMatrix::set_oblique_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, Quat oblique_near_plane, bool p_flip_fov) {
- if (p_flip_fov) {
- p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
- }
- real_t sine, cotangent, deltaZ;
- real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
- deltaZ = p_z_far - p_z_near;
- sine = Math::sin(radians);
- if ((deltaZ == 0) || (sine == 0) || (p_aspect == 0)) {
- return;
- }
- cotangent = Math::cos(radians) / sine;
- set_identity();
- matrix[0][0] = cotangent / p_aspect;
- matrix[1][1] = cotangent;
- matrix[2][2] = -(p_z_far + p_z_near) / deltaZ;
- matrix[2][3] = -1;
- matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ;
- matrix[3][3] = 0;
- // Here goes oblique magic!
- Quat q;
- q.x = (sign(oblique_near_plane.x) + matrix[2][0]) / matrix[0][0];
- q.y = (sign(oblique_near_plane.y) + matrix[2][1]) / matrix[1][1];
- q.z = -1.0F;
- q.w = (1.0F + matrix[2][2]) / matrix[3][2];
- Quat c = oblique_near_plane * (2.0F / oblique_near_plane.dot(q));
- matrix[0][2] = c.x;
- matrix[1][2] = c.y;
- matrix[2][2] = c.z + 1.0F;
- matrix[3][2] = c.w;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement