Commit cdb56818 authored by chili's avatar chili
Browse files

better camera rotation with lookAt + rotation of view direction

parent 305895dc
......@@ -11,8 +11,19 @@ Camera::Camera() noexcept
DirectX::XMMATRIX Camera::GetMatrix() const noexcept
{
return dx::XMMatrixTranslation( -pos.x,-pos.y,-pos.z ) *
dx::XMMatrixRotationRollPitchYaw( -pitch,-yaw,0.0f );
using namespace dx;
const dx::XMVECTOR forwardBaseVector = XMVectorSet( 0.0f,0.0f,1.0f,0.0f );
// apply the camera rotations to a base vector
const auto lookVector = XMVector3Transform( forwardBaseVector,
XMMatrixRotationRollPitchYaw( pitch,yaw,0.0f )
);
// generate camera transform (applied to all objects to arrange them relative
// to camera position/orientation in world) from cam position and direction
// camera "top" always faces towards +Y (cannot do a barrel roll)
const auto camPosition = XMLoadFloat3( &pos );
const auto camTarget = camPosition + lookVector;
return XMMatrixLookAtLH( camPosition,camTarget,XMVectorSet( 0.0f,1.0f,0.0f,0.0f ) );
}
void Camera::SpawnControlWindow() noexcept
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment