Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. maths::C_Ray C_Camera::GetRayToNearPlane(float x, float y) const
  2. {
  3.     maths::C_Ray ray;
  4.  
  5.     maths::C_Matrix4 invMV = ComputeInverseMatrix();
  6.  
  7.     maths::C_Matrix4 mvp = m_Matrix * m_ProjectionMatrix;
  8.     maths::C_Frustum frustum = mvp.ExtractFrustum();
  9.  
  10.     maths::C_Vector3 points[8];
  11.     frustum.GetCornerPoints(points);
  12.  
  13.     float nx = 1.0f - x;
  14.     float ny = 1.0f - y;
  15.  
  16.     maths::C_Vector3 target = points[0] * nx * ny + points[1] * x * ny + points[2] * x * y + points[3] * nx * y;
  17.  
  18.     ray.m_Position.Set(invMV.Cell[12], invMV.Cell[13], invMV.Cell[14]);
  19.     ray.m_Direction = (target - ray.m_Position);
  20.     ray.m_Direction.Normalize();
  21.  
  22.     ray.m_Position.Set(invMV.Cell[12], invMV.Cell[13], invMV.Cell[14]);
  23.  
  24.     return ray;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement