ok,所以我目前使用DirectX11制作自己的小引擎。我有很多事情有效,并决定回到我的转型课程,以使其更加优美。我从

问题描述 投票:0回答:0
是的,希望你们能帮助我🥲

这里是我的相机运动代码:

void FreeMovement::HandleRotation(float deltaTime) { // Get data Transform* pTransform = GetGameObject()->GetTransform(); InputManager* pInput = InputManager::GetInstance(); Rotator cameraRotation = pTransform->GetLocalRotation(); const float deltaAngle = m_RotateSpeed * deltaTime; // Handle input if (pInput->IsKeyPressed(VK_LEFT)) { cameraRotation = Rotator::FromAxisAngle(Vector3::Up(), -deltaAngle) * cameraRotation; } if (pInput->IsKeyPressed(VK_RIGHT)) { cameraRotation = Rotator::FromAxisAngle(Vector3::Up(), deltaAngle) * cameraRotation; } if (pInput->IsKeyPressed(VK_UP)) { cameraRotation = Rotator::FromAxisAngle(Vector3::Right(), -deltaAngle) * cameraRotation; } if (pInput->IsKeyPressed(VK_DOWN)) { cameraRotation = Rotator::FromAxisAngle(Vector3::Right(), deltaAngle) * cameraRotation; } // Set data cameraRotation.Normalize(); pTransform->SetLocalRotation(cameraRotation); }

the fromaxisangle()和旋转器乘法:

DirectX_Rotator DirectX_Rotator::FromAxisAngle(const Vector3& axis, float angle) { return DirectX_Rotator{ DirectX::XMQuaternionRotationAxis(axis.GetVector(), angle * toRadians) }; } DirectX_Rotator DirectX_Rotator::operator* (const DirectX_Rotator& other) const { return DirectX_Rotator{ DirectX::XMQuaternionMultiply(GetVector(), other.GetVector()) }; }

我也可以在需要时显示“转换类”和/或世界和视图 - 玛特里克斯。
或更多,只是问。

BTW,您可能已经注意到我显示了两个不同的旋转器类:“旋转器”和“ DirectX_rotator”。但这是因为我正在使用“使用”关键字,以防万一我想允许不同的渲染apis。

ok,我通过将相机运动代码更改为以下方式修复了:

void FreeMovement::HandleRotation(float deltaTime) { // Get data Transform* pTransform = GetGameObject()->GetTransform(); InputManager* pInput = InputManager::GetInstance(); const float deltaAngle = m_RotateSpeed * deltaTime; // Handle input if (pInput->IsKeyPressed(VK_LEFT)) m_TotalYaw -= deltaAngle; if (pInput->IsKeyPressed(VK_RIGHT)) m_TotalYaw += deltaAngle; if (pInput->IsKeyPressed(VK_UP)) m_TotalPitch -= deltaAngle; if (pInput->IsKeyPressed(VK_DOWN)) m_TotalPitch += deltaAngle; // Set data pTransform->SetLocalRotation(Rotator::FromEuler(m_TotalPitch, m_TotalYaw, 0.f)); }

说,这对我来说仍然没有意义,为什么我以前的代码不起作用。

c++ camera rotation quaternions directxmath
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.