Ember

Reconstruct

Nov 25th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. //-------------------------------------------------------------------------------------
  2.     void Camera::Reconstruct()
  3.     {
  4.         Vector3D up, position, lookAt;
  5.         float yaw, pitch, roll;
  6.         Matrix rotationMatrix;
  7.        
  8.         // Setup the vector that points upwards.
  9.         up.x = 0.0f;
  10.         up.y = 1.0f;
  11.         up.z = 0.0f;
  12.  
  13.         // Setup the position of the camera in the world.
  14.         position = mPosition;
  15.  
  16.         // Setup where the camera is looking by default.
  17.         lookAt.x = 0.0f;
  18.         lookAt.y = 0.0f;
  19.         lookAt.z = 0.0f;
  20.  
  21.         // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
  22.         pitch = mRotation.x * 0.0174532925f;
  23.         yaw = mRotation.y * 0.0174532925f;
  24.         roll = mRotation.z * 0.0174532925f;
  25.  
  26.         // Create the rotation matrix from the yaw, pitch, and roll values.
  27.         D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);
  28.  
  29.         // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
  30.         D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
  31.         D3DXVec3TransformCoord(&up, &up, &rotationMatrix);
  32.  
  33.         // Translate the rotated camera position to the location of the viewer.
  34.         lookAt = position + lookAt;
  35.  
  36.         // Finally create the view matrix from the three updated vectors.
  37.         D3DXMatrixLookAtLH(&mViewMatrix, &position, &lookAt, &up);
  38.  
  39.         return;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment