Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto state = m_mouse->GetState();
- float mouseX = state.x;
- float mouseY = state.y;
- float m_screenWidth = m_deviceResources->GetScreenViewport().Width;
- float m_screenHeight = m_deviceResources->GetScreenViewport().Height;
- // Normalized device coordinates
- float x = (2.0f * mouseX) / m_screenWidth - 1.0f;
- float y = 1.0f - (2.0f * mouseY) / m_screenHeight;
- DirectX::XMMATRIX viewMatrix = DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&cameraComponentHandle->view));
- DirectX::XMMATRIX projectionMatrix = DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&cameraComponentHandle->projection));
- DirectX::XMMATRIX inverseviewproj = DirectX::XMMatrixInverse(nullptr, viewMatrix * projectionMatrix);
- DirectX::SimpleMath::Vector3 origin = DirectX::SimpleMath::Vector3(x, y, 0);
- DirectX::SimpleMath::Vector3 farPoint = DirectX::SimpleMath::Vector3(x, y, 1);
- DirectX::SimpleMath::Vector3 rayorigin = DirectX::XMVector3TransformCoord(origin, inverseviewproj);
- DirectX::SimpleMath::Vector3 rayend = DirectX::XMVector3TransformCoord(farPoint, inverseviewproj);
- DirectX::SimpleMath::Vector3 raydirection = (rayend - rayorigin);
- raydirection.Normalize();
- rayComponentHandle->position = rayorigin;
- rayComponentHandle->direction = raydirection;
Add Comment
Please, Sign In to add comment