void Camera::Render() { // Load the rotation and make radian vectors. XMVECTOR rotationVector = XMLoadFloat3( &m_Rotation ); XMVECTOR radianVector = XMVectorReplicate( 0.0174532925f ); // Setup the vector that points upwards. XMVECTOR upVector = XMVectorSet( 0.f, 1.f, 0.f, 0.f ); // Load the position into an XMVECTOR structure. XMVECTOR positionVector = XMLoadFloat3(&m_Position); // Setup where the camera is looking by default. XMVECTOR lookAtVector = XMVectorSet( 0.f, 0.f, 1.f, 0.f ); // Create the rotation matrix from the product of the rotation vector and the radian vector. // This converts the rotations to radians before creating the rotation matrix XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYawFromVector(rotationVector * radianVector); // 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_ViewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector); }
XMFLOAT4X4& ITransform::GetTransformMatrix() { XMMATRIX scl, rot, tsl; scl = XMMatrixScalingFromVector(XMLoadFloat3(&m_vScale)); rot = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&m_vRotation)); tsl = XMMatrixTranslationFromVector(XMLoadFloat3(&m_vPosition)); // worldMat = S*R*T XMStoreFloat4x4(&m_mTransform, (scl*rot*tsl)); return m_mTransform; }
XMFLOAT4X4 gameObject::CalculateWorldMatrix() { XMMATRIX scale, rot, trans, world; scale = XMMatrixScalingFromVector(XMLoadFloat3(&m_scaleVector)); rot = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat3(&m_rotationVector)); trans = XMMatrixTranslationFromVector(XMLoadFloat3(&m_positionVector)); world = scale* rot* trans; XMStoreFloat4x4(&m_matScale, scale); XMStoreFloat4x4(&m_matRot, rot); XMStoreFloat4x4(&m_matTranslation, trans); XMStoreFloat4x4(&m_matTransform, world); return m_matTransform; }