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)
|
void PlaneCameraController::Init(Camera* camera, const Math::Vector3f& planeNormal)
|
||||||
{
|
{
|
||||||
CameraController::Init(camera);
|
CameraController::Init(camera);
|
||||||
m_planeNormal = Math::Utils::normalize(planeNormal);
|
SetPlaneNormal(planeNormal);
|
||||||
SetDefaultKeybindings();
|
SetDefaultKeybindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ namespace OpenVulkano::Scene
|
|||||||
|
|
||||||
Math::Vector3f direction(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp),
|
Math::Vector3f direction(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp),
|
||||||
-input->GetAxis(m_actionForward));
|
-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 SPEED = 3.0f;
|
||||||
const float BOOST_FACTOR = 3.0;
|
const float BOOST_FACTOR = 3.0;
|
||||||
@@ -55,10 +55,8 @@ namespace OpenVulkano::Scene
|
|||||||
if (input->GetButton(m_actionBoost)) { direction *= BOOST_FACTOR; }
|
if (input->GetButton(m_actionBoost)) { direction *= BOOST_FACTOR; }
|
||||||
|
|
||||||
float dt = CURRENT_FRAME.frameTime;
|
float dt = CURRENT_FRAME.frameTime;
|
||||||
|
Math::Vector3f projDirection = direction - (Math::Utils::dot(direction, m_planeNormal) * m_planeNormal);
|
||||||
direction *= dt * SPEED;
|
m_position += projDirection * dt * SPEED;
|
||||||
direction = direction - (Math::Utils::dot(direction, m_planeNormal) * m_planeNormal);
|
|
||||||
m_position += direction;
|
|
||||||
|
|
||||||
Math::Matrix4f transformation = Math::Utils::translate(m_position);
|
Math::Matrix4f transformation = Math::Utils::translate(m_position);
|
||||||
GetCamera()->SetMatrix(transformation);
|
GetCamera()->SetMatrix(transformation);
|
||||||
@@ -75,5 +73,8 @@ namespace OpenVulkano::Scene
|
|||||||
m_actionUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_SPACE, Input::InputKey::Keyboard::KEY_LEFT_CONTROL);
|
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