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();
|
||||
@@ -20,7 +27,7 @@ namespace OpenVulkano
|
||||
m_actionUp = input->GetAction("up");
|
||||
m_actionLookUp = input->GetAction("look up");
|
||||
m_actionLookSide = input->GetAction("look side");
|
||||
|
||||
|
||||
m_actionForwardOrtho = input->GetAction("ArcForwardOrtho");
|
||||
m_actionSideOrtho = input->GetAction("ArcSideOrtho");
|
||||
m_actionUpOrtho = input->GetAction("ArcUpOrtho");
|
||||
@@ -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())
|
||||
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)
|
||||
{
|
||||
@@ -118,7 +140,7 @@ namespace OpenVulkano
|
||||
if (!GetCamera()) return;
|
||||
Math::Vector3f viewDir = Math::Utils::normalize(GetCamera()->GetViewDirection());
|
||||
m_pivotPoint = GetCamera()->GetPosition() + Math::Vector4f(viewDir * m_distance, 0);
|
||||
|
||||
|
||||
m_pitch = Math::Utils::asin(viewDir.y);
|
||||
m_yaw = Math::Utils::atan(-viewDir.x, -viewDir.z);
|
||||
}
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user