Advertisement
Guest User

Oblique near clipping plane

a guest
Mar 19th, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. 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) {
  2.     if (p_flip_fov) {
  3.         p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
  4.     }
  5.  
  6.     real_t sine, cotangent, deltaZ;
  7.     real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
  8.  
  9.     deltaZ = p_z_far - p_z_near;
  10.     sine = Math::sin(radians);
  11.  
  12.     if ((deltaZ == 0) || (sine == 0) || (p_aspect == 0)) {
  13.         return;
  14.     }
  15.     cotangent = Math::cos(radians) / sine;
  16.  
  17.     set_identity();
  18.  
  19.     matrix[0][0] = cotangent / p_aspect;
  20.     matrix[1][1] = cotangent;
  21.     matrix[2][2] = -(p_z_far + p_z_near) / deltaZ;
  22.     matrix[2][3] = -1;
  23.     matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ;
  24.     matrix[3][3] = 0;
  25.  
  26.     // Here goes oblique magic!
  27.     Quat q;
  28.     q.x = (sign(oblique_near_plane.x) + matrix[2][0]) / matrix[0][0];
  29.     q.y = (sign(oblique_near_plane.y) + matrix[2][1]) / matrix[1][1];
  30.     q.z = -1.0F;
  31.     q.w = (1.0F + matrix[2][2]) / matrix[3][2];
  32.     Quat c = oblique_near_plane * (2.0F / oblique_near_plane.dot(q));
  33.     matrix[0][2] = c.x;
  34.     matrix[1][2] = c.y;
  35.     matrix[2][2] = c.z + 1.0F;
  36.     matrix[3][2] = c.w;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement