Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. // camera view matrix
  2. void Library::Camera::CalculateVeiw()
  3. {
  4.     DirectX::XMVECTOR R = DirectX::XMLoadFloat3(&m_right);
  5.     DirectX::XMVECTOR U = DirectX::XMLoadFloat3(&m_up);
  6.     DirectX::XMVECTOR L = DirectX::XMLoadFloat3(&m_look);
  7.     DirectX::XMVECTOR P = DirectX::XMLoadFloat3(&m_position);  
  8.  
  9.     // Keep camera's axes orthogonal to each other and of unit length.
  10.     L = DirectX::XMVector3Normalize(L);
  11.     U = DirectX::XMVector3Normalize(DirectX::XMVector3Cross(L, R));
  12.  
  13.     // U, L already ortho-normal, so no need to normalize cross product.
  14.     R = DirectX::XMVector3Cross(U, L);
  15.  
  16.     DirectX::XMMATRIX V = DirectX::XMMatrixLookToRH(P, L, U);
  17.     DirectX::XMStoreFloat4x4(&m_view, V);
  18.  
  19.     DirectX::XMStoreFloat3(&m_position, P);
  20.     DirectX::XMStoreFloat3(&m_up, U);
  21.     DirectX::XMStoreFloat3(&m_look, L);
  22.     DirectX::XMStoreFloat3(&m_right, R);
  23. }
  24.  
  25.  
  26. // light view matrix
  27. void ShadowMap::SetLightSource(const LightSource * light)
  28. {
  29.     for (unsigned int i = 0; i < MAX_LIGHT_SOURCES; i++)
  30.     {
  31.         if (!light[i].Type)
  32.             continue;
  33.  
  34.         m_lightSource[i] = light[i];
  35.  
  36.         DirectX::XMVECTOR pos;
  37.         DirectX::XMVECTOR dir = DirectX::XMVector4Normalize((DirectX::XMLoadFloat4(&(m_lightSource[i].LightDir))));
  38.         pos = DirectX::XMLoadFloat4(&(m_lightSource[i].LightPos));
  39.  
  40.         DirectX::XMMATRIX V = DirectX::XMMatrixLookToRH(pos, dir, DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.f));
  41.         DirectX::XMStoreFloat4x4(&(m_lightView[i]), V);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement