Normalizing plane normal in setter
This commit is contained in:
@@ -25,7 +25,7 @@ namespace OpenVulkano::Scene
|
||||
void PlaneCameraController::Init(Camera* camera, const Math::Vector3f& planeNormal)
|
||||
{
|
||||
CameraController::Init(camera);
|
||||
m_planeNormal = Math::Utils::normalize(planeNormal);
|
||||
SetPlaneNormal(planeNormal);
|
||||
SetDefaultKeybindings();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenVulkano::Scene
|
||||
|
||||
Math::Vector3f direction(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp),
|
||||
-input->GetAxis(m_actionForward));
|
||||
if (Math::Utils::length2(direction) > 1.0f) { direction = Math::Utils::normalize(direction); }
|
||||
if (Math::Utils::length2(direction) > 0.0f) { direction = Math::Utils::normalize(direction); }
|
||||
|
||||
const float SPEED = 3.0f;
|
||||
const float BOOST_FACTOR = 3.0;
|
||||
@@ -55,10 +55,8 @@ namespace OpenVulkano::Scene
|
||||
if (input->GetButton(m_actionBoost)) { direction *= BOOST_FACTOR; }
|
||||
|
||||
float dt = CURRENT_FRAME.frameTime;
|
||||
|
||||
direction *= dt * SPEED;
|
||||
direction = direction - (Math::Utils::dot(direction, m_planeNormal) * m_planeNormal);
|
||||
m_position += direction;
|
||||
Math::Vector3f projDirection = direction - (Math::Utils::dot(direction, m_planeNormal) * m_planeNormal);
|
||||
m_position += projDirection * dt * SPEED;
|
||||
|
||||
Math::Matrix4f transformation = Math::Utils::translate(m_position);
|
||||
GetCamera()->SetMatrix(transformation);
|
||||
@@ -75,5 +73,8 @@ namespace OpenVulkano::Scene
|
||||
m_actionUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_SPACE, Input::InputKey::Keyboard::KEY_LEFT_CONTROL);
|
||||
}
|
||||
|
||||
void PlaneCameraController::SetPlaneNormal(const Math::Vector3f& planeNormal) { m_planeNormal = planeNormal; }
|
||||
void PlaneCameraController::SetPlaneNormal(const Math::Vector3f& planeNormal)
|
||||
{
|
||||
m_planeNormal = Math::Utils::normalize(planeNormal);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user