Refactor CameraController logic
This commit is contained in:
@@ -11,11 +11,10 @@
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
ArCameraController::ArCameraController() : m_camera(nullptr)
|
||||
{}
|
||||
ArCameraController::ArCameraController() = default;
|
||||
|
||||
ArCameraController::ArCameraController(Scene::Camera* camera, const std::shared_ptr<AR::ArSession>& session, const Math::Matrix4f& registration)
|
||||
: m_arSession(session), m_camera(camera), m_registration(registration), m_updated(false)
|
||||
: CameraController(camera), m_arSession(session), m_registration(registration), m_updated(false)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
@@ -49,14 +48,14 @@ namespace openVulkanoCpp
|
||||
else
|
||||
{
|
||||
Logger::AR->critical("Failed to create AR session for ArCameraController! Error: " + createResult.statusMessage);
|
||||
m_camera = nullptr;
|
||||
SetCamera(nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::AR->critical("No native AR implementation available! Can't start ArCameraController.");
|
||||
m_camera = nullptr;
|
||||
SetCamera(nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -67,28 +66,28 @@ namespace openVulkanoCpp
|
||||
|
||||
void ArCameraController::Init(Scene::Camera* camera, const std::shared_ptr<AR::ArSession>& session, const Math::Matrix4f& registration)
|
||||
{
|
||||
if (m_camera) return;
|
||||
if (GetCamera()) return;
|
||||
CameraController::Init(camera);
|
||||
m_arSession = session;
|
||||
m_camera = camera;
|
||||
m_registration = registration;
|
||||
Init();
|
||||
}
|
||||
|
||||
void ArCameraController::Tick()
|
||||
{
|
||||
if (!m_camera || !m_updated) return;
|
||||
if (!GetCamera() || !m_updated) return;
|
||||
std::unique_lock lock(m_mutex);
|
||||
|
||||
Math::Matrix4f mat = m_registration * Math::Utils::inverse(m_matrixToUpdate);
|
||||
m_camera->SetMatrix(mat);
|
||||
GetCamera()->SetMatrix(mat);
|
||||
m_updated = false;
|
||||
}
|
||||
|
||||
void ArCameraController::Close()
|
||||
{
|
||||
if (!m_camera) return;
|
||||
if (!GetCamera()) return;
|
||||
m_arSession->OnNewCameraViewMatrix -= EventHandler(this, &ArCameraController::UpdateCameraTransformation);
|
||||
m_camera = nullptr;
|
||||
SetCamera(nullptr);
|
||||
m_arSession = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user