Merge branch 'main' into ImGui-V2
This commit is contained in:
@@ -109,4 +109,63 @@ XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix)
|
||||
{
|
||||
viewMatrix = m_viewMatrix;
|
||||
return viewMatrix;
|
||||
}
|
||||
|
||||
void CameraClass::RenderReflection(float height)
|
||||
{
|
||||
XMFLOAT3 up, position, lookAt;
|
||||
XMVECTOR upVector, positionVector, lookAtVector;
|
||||
float yaw, pitch, roll;
|
||||
XMMATRIX rotationMatrix;
|
||||
|
||||
|
||||
// Setup the vector that points upwards.
|
||||
up.x = 0.0f;
|
||||
up.y = 1.0f;
|
||||
up.z = 0.0f;
|
||||
|
||||
// Load it into a XMVECTOR structure.
|
||||
upVector = XMLoadFloat3(&up);
|
||||
|
||||
// Setup the position of the camera in the world.
|
||||
position.x = m_positionX;
|
||||
position.y = -m_positionY + (height * 2.0f);
|
||||
position.z = m_positionZ;
|
||||
|
||||
// Load it into a XMVECTOR structure.
|
||||
positionVector = XMLoadFloat3(&position);
|
||||
|
||||
// Setup where the camera is looking by default.
|
||||
lookAt.x = 0.0f;
|
||||
lookAt.y = 0.0f;
|
||||
lookAt.z = 1.0f;
|
||||
|
||||
// Load it into a XMVECTOR structure.
|
||||
lookAtVector = XMLoadFloat3(&lookAt);
|
||||
|
||||
// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
|
||||
pitch = (-1.0f * m_rotationX) * 0.0174532925f; // Invert for reflection
|
||||
yaw = m_rotationY * 0.0174532925f;
|
||||
roll = m_rotationZ * 0.0174532925f;
|
||||
|
||||
// Create the rotation matrix from the yaw, pitch, and roll values.
|
||||
rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
|
||||
|
||||
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
|
||||
lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
|
||||
upVector = XMVector3TransformCoord(upVector, rotationMatrix);
|
||||
|
||||
// Translate the rotated camera position to the location of the viewer.
|
||||
lookAtVector = XMVectorAdd(positionVector, lookAtVector);
|
||||
|
||||
// Finally create the view matrix from the three updated vectors.
|
||||
m_reflectionViewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix)
|
||||
{
|
||||
reflectionViewMatrix = m_reflectionViewMatrix;
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user