Advertisement
Ember

proj

Sep 13th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1.     static Float4x4 PerspectiveLH(Float fov, Float aspectRatio, Float near, Float far)
  2.     {
  3.         Float2 angles = Math::SinCos(0.5f * fov);
  4.  
  5.         Float height = angles.y / angles.x;
  6.         Float width = height / aspectRatio;
  7.         Float range = far / (far - near);
  8.  
  9.         Float4x4 matrix;
  10.         matrix[0][0] = width;
  11.         matrix[0][1] = 0.0f;
  12.         matrix[0][2] = 0.0f;
  13.         matrix[0][3] = 0.0f;
  14.  
  15.         matrix[1][0] = 0.0f;
  16.         matrix[1][1] = height;
  17.         matrix[1][2] = 0.0f;
  18.         matrix[1][3] = 0.0f;
  19.  
  20.         matrix[2][0] = 0.0f;
  21.         matrix[2][1] = 0.0f;
  22.         matrix[2][2] = range;
  23.         matrix[2][3] = 1.0f;
  24.  
  25.         matrix[3][0] = 0.0f;
  26.         matrix[3][1] = 0.0f;
  27.         matrix[3][2] = -range * near;
  28.         matrix[3][3] = 0.0f;
  29.  
  30.         return matrix;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement