Update ArcballCameraController for ortho cameras
This commit is contained in:
@@ -12,6 +12,13 @@
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
namespace
|
||||
{
|
||||
constexpr float MAX_ZOOM = 40;
|
||||
constexpr float MIN_ZOOM = 7;
|
||||
constexpr float ZOOM_RANGE = MAX_ZOOM - MIN_ZOOM;
|
||||
}
|
||||
|
||||
void ArcballCameraController::SetupInputActions()
|
||||
{
|
||||
auto input = Input::InputManager::GetInstance();
|
||||
@@ -33,7 +40,7 @@ namespace OpenVulkano
|
||||
float inYaw = (m_lockYaw) ? 0 : input->GetAxis(m_actionLookSide);
|
||||
float inPitch = (m_lockPitch) ? 0 : input->GetAxis(m_actionLookUp);
|
||||
|
||||
if (inYaw != 0 || inPitch != 0)
|
||||
if (inYaw != 0 || inPitch != 0 || m_distUpated)
|
||||
{
|
||||
m_yaw += inYaw;
|
||||
m_pitch = std::min(1.5f, std::max(-1.5f, m_pitch + inPitch));
|
||||
@@ -41,9 +48,10 @@ namespace OpenVulkano
|
||||
Math::Matrix4f rotateY = Math::Utils::rotate(m_yaw, Math::Vector3f_SIMD(0, 1, 0));
|
||||
Math::Vector4f x = rotateY * Math::Vector4f(1, 0, 0, 0);
|
||||
Math::Matrix4f rotateX = Math::Utils::rotate(m_pitch, Math::Vector3f_SIMD(x));
|
||||
m_framePosition = rotateX * rotateY * Math::Vector4f_SIMD(0, 0, m_distance, 0);
|
||||
m_framePosition = rotateX * rotateY * Math::Vector4f_SIMD(0, 0, m_frameDistance, 0);
|
||||
m_framePosition += m_pivotPoint;
|
||||
m_frameUpdated = true;
|
||||
m_distUpated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +78,7 @@ namespace OpenVulkano
|
||||
void ArcballCameraController::HandleMovementOrtho()
|
||||
{
|
||||
Input::InputManager* input = Input::InputManager::GetInstance();
|
||||
Math::Vector4f vec(input->GetAxis(m_actionSideOrtho), input->GetAxis(m_actionUpOrtho), -input->GetAxis(m_actionForwardOrtho), 0);
|
||||
Math::Vector4f vec(input->GetAxis(m_actionSideOrtho), input->GetAxis(m_actionUpOrtho), /*-input->GetAxis(m_actionForwardOrtho)*/0, 0);
|
||||
if (vec != Math::Vector4f(0))
|
||||
{
|
||||
vec /= GetCamera()->GetZoom();
|
||||
@@ -97,11 +105,25 @@ namespace OpenVulkano
|
||||
m_frameUpdated = false;
|
||||
m_framePosition = GetCamera()->GetPosition();
|
||||
|
||||
HandleRotation();
|
||||
if (GetCamera()->IsOrtho())
|
||||
{
|
||||
HandleMovementOrtho();
|
||||
if (GetCamera()->GetZoom() > 50)
|
||||
{
|
||||
float nDist = std::max<float>(((ZOOM_RANGE - sqrt(GetCamera()->GetZoom())) / ZOOM_RANGE) * m_distance, 0.1f);
|
||||
if (nDist != m_frameDistance)
|
||||
{
|
||||
m_distUpated = true;
|
||||
m_frameDistance = nDist;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleMovement();
|
||||
m_frameDistance = m_distance;
|
||||
}
|
||||
HandleRotation();
|
||||
|
||||
if (m_frameUpdated)
|
||||
{
|
||||
@@ -154,7 +176,7 @@ namespace OpenVulkano
|
||||
m_pivotPoint = pivotPoint;
|
||||
if (updateDistance && GetCamera())
|
||||
{
|
||||
m_distance = Math::Utils::length(m_pivotPoint - GetCamera()->GetPosition());
|
||||
SetDistance(Math::Utils::length(m_pivotPoint - GetCamera()->GetPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace OpenVulkano
|
||||
class ArcballCameraController final : public CameraController
|
||||
{
|
||||
Math::Vector4f m_pivotPoint{ 0, 0, 0, 1 };
|
||||
float m_yaw = 0, m_pitch = 0, m_distance = 3;
|
||||
float m_yaw = 0, m_pitch = 0, m_distance = 3, m_frameDistance;
|
||||
|
||||
Input::InputAction* m_actionForward = nullptr;
|
||||
Input::InputAction* m_actionSide = nullptr;
|
||||
@@ -32,7 +32,7 @@ namespace OpenVulkano
|
||||
Input::InputAction* m_actionZoomOrtho = nullptr;
|
||||
|
||||
Math::Vector4f m_framePosition;
|
||||
bool m_frameUpdated = false;
|
||||
bool m_frameUpdated = false, m_distUpated = true;
|
||||
bool m_lockYaw = false, m_lockPitch = false;
|
||||
|
||||
void SetupInputActions();
|
||||
@@ -69,6 +69,6 @@ namespace OpenVulkano
|
||||
|
||||
void SetYaw(float y) { m_yaw = y; }
|
||||
void SetPitch(float p) { m_pitch = p; }
|
||||
void SetDistance(float dist) { m_distance = dist; }
|
||||
void SetDistance(float dist) { m_distance = dist; m_distUpated = true; }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user