From 1fbd072429939f76f48880ea7f97d86cfd484714 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Tue, 25 Jun 2024 22:05:55 +0300 Subject: [PATCH] Using MorphableCameraController class in MovingCubeApp example --- examples/ExampleApps/MovingCubeApp.cpp | 58 +++++++++++++------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp index 24874fd..ba970b6 100644 --- a/examples/ExampleApps/MovingCubeApp.cpp +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -16,6 +16,7 @@ #include "Scene/Camera.hpp" #include "Scene/SimpleAnimationController.hpp" #include "Scene/SequenceAnimationController.hpp" +#include "Scene/MorphableCameraController.hpp" #include "Scene/UI/PerformanceInfo.hpp" #include "Input/InputManager.hpp" #include "Host/GraphicsAppManager.hpp" @@ -37,8 +38,8 @@ namespace OpenVulkano class MovingCubeAppImpl final : public MovingCubeApp { Scene::Scene m_scene; - Scene::PerspectiveCamera m_camera; - FreeCamCameraController m_cameraControl; + Scene::MorphableCamera m_camera; + Scene::MorphableCameraController m_cameraControl; Scene::Material m_material; Scene::Shader m_shader; @@ -74,48 +75,50 @@ namespace OpenVulkano CompleteSceneElement(dest); } - void CreatePlane(SceneElement *dest, const Math::Vector4f& color) + void CreatePlane(SceneElement *dest, const Math::Vector4f &color) { dest->m_geometry = Scene::GeometryFactory::MakePlane(1, 1, color); CompleteSceneElement(dest); } - void CreateSphere(SceneElement *dest, const Math::Vector4f& color) + void CreateSphere(SceneElement *dest, const Math::Vector4f &color) { dest->m_geometry = Scene::GeometryFactory::MakeSphere(1, 32, 16, color); CompleteSceneElement(dest); } - void CreateHemisphere(SceneElement *dest, const Math::Vector4f& color) + void CreateHemisphere(SceneElement *dest, const Math::Vector4f &color) { dest->m_geometry = Scene::GeometryFactory::MakeHemisphere(1, 16, 16, color); CompleteSceneElement(dest); } - void CreateTriangle(SceneElement *dest, const Math::Vector4f& color) + void CreateTriangle(SceneElement *dest, const Math::Vector4f &color) { - dest->m_geometry = Scene::GeometryFactory::MakeTriangle(Math::Vector3f(0.5, 0., 0.), Math::Vector3f(0., 0.5, 0.), Math::Vector3f(-0.5, 0., 0.), color); + dest->m_geometry = Scene::GeometryFactory::MakeTriangle( + Math::Vector3f(0.5, 0., 0.), Math::Vector3f(0., 0.5, 0.), Math::Vector3f(-0.5, 0., 0.), color); CompleteSceneElement(dest); } - void CreateCylinder(SceneElement *dest, const Math::Vector4f& color) + void CreateCylinder(SceneElement *dest, const Math::Vector4f &color) { dest->m_geometry = Scene::GeometryFactory::MakeCylinder(1, 3, 64, color); CompleteSceneElement(dest); } - void CreatePyramid(SceneElement *dest, const Math::Vector4f& color) + void CreatePyramid(SceneElement *dest, const Math::Vector4f &color) { dest->m_geometry = Scene::GeometryFactory::MakePyramid(0.5, 2, color); CompleteSceneElement(dest); } public: + MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000) { m_cameraControl.Init(&m_camera); } + void Init() override { auto engineConfig = EngineConfiguration::GetEngineConfiguration(); m_camera.Init(70, 16, 9, 0.1, 100); - // m_camera.SetMatrix(OpenVulkano::Math::Utils::translate(OpenVulkano::Math::Matrix4f(1), OpenVulkano::Math::Vector3f_SIMD(0, 0, -50))); m_scene.Init(); m_scene.SetCamera(&m_camera); @@ -136,16 +139,23 @@ namespace OpenVulkano Math::Pose srcPose(Math::Quaternion(), Math::Vector3f_SIMD(-3, 0, 0)); Math::Pose destPose(Math::Quaternion(), Math::Vector3f_SIMD(3, 0, 0)); m_simpleAnimationController.SetPoses(srcPose, destPose); - m_simpleAnimationController.m_completionEvent += EventHandler(this, &MovingCubeAppImpl::OnSimpleAnimationCompleted); + m_simpleAnimationController.m_completionEvent += + EventHandler(this, &MovingCubeAppImpl::OnSimpleAnimationCompleted); m_sequenceAnimationController.EnableLoop(true); m_sequenceAnimationController.SetNode(&m_redBox.m_node); - m_sequenceAnimationController.AddAnimationStep(Math::PoseF(Math::Utils::normalize(Math::QuaternionF(1, 0, 0, 1)), Math::Vector3f_SIMD(0, 0, 1)), 5); - m_sequenceAnimationController.AddAnimationStep(Math::PoseF(Math::Utils::normalize(Math::QuaternionF(2, 1, 0, 1)), Math::Vector3f_SIMD(1, 1, -1)), 3); - m_sequenceAnimationController.AddAnimationStep(Math::PoseF(Math::Utils::normalize(Math::QuaternionF(1, 1, 1, 1)), Math::Vector3f_SIMD(2, 1, -2)), 3); - m_sequenceAnimationController.AddAnimationStep(Math::PoseF(Math::Utils::normalize(Math::QuaternionF(0, 1, 1, 0)), Math::Vector3f_SIMD(2, 1, -1)), 3); - m_sequenceAnimationController.AddAnimationStep(Math::PoseF(Math::Utils::normalize(Math::QuaternionF(3, 2, 1, 1)), Math::Vector3f_SIMD(1, 1, -1)), 3); - m_sequenceAnimationController.AddAnimationStep(Math::PoseF(Math::Utils::normalize(Math::QuaternionF(0, 0, 1, 1)), Math::Vector3f_SIMD(0, 1, 0)), 1); + m_sequenceAnimationController.AddAnimationStep( + Math::PoseF(Math::Utils::normalize(Math::QuaternionF(1, 0, 0, 1)), Math::Vector3f_SIMD(0, 0, 1)), 5); + m_sequenceAnimationController.AddAnimationStep( + Math::PoseF(Math::Utils::normalize(Math::QuaternionF(2, 1, 0, 1)), Math::Vector3f_SIMD(1, 1, -1)), 3); + m_sequenceAnimationController.AddAnimationStep( + Math::PoseF(Math::Utils::normalize(Math::QuaternionF(1, 1, 1, 1)), Math::Vector3f_SIMD(2, 1, -2)), 3); + m_sequenceAnimationController.AddAnimationStep( + Math::PoseF(Math::Utils::normalize(Math::QuaternionF(0, 1, 1, 0)), Math::Vector3f_SIMD(2, 1, -1)), 3); + m_sequenceAnimationController.AddAnimationStep( + Math::PoseF(Math::Utils::normalize(Math::QuaternionF(3, 2, 1, 1)), Math::Vector3f_SIMD(1, 1, -1)), 3); + m_sequenceAnimationController.AddAnimationStep( + Math::PoseF(Math::Utils::normalize(Math::QuaternionF(0, 0, 1, 1)), Math::Vector3f_SIMD(0, 1, 0)), 1); m_sequenceAnimationController.SetAnimationPoseResetTime(10); CreatePlane(&m_plane, Math::Vector4f(0.3, 0.6, 0.9, 1.0)); @@ -184,18 +194,10 @@ namespace OpenVulkano m_sequenceAnimationController.Tick(); } - void Close() override - { - } + void Close() override {} }; - IGraphicsApp* MovingCubeApp::Create() - { - return new MovingCubeAppImpl(); - } + IGraphicsApp *MovingCubeApp::Create() { return new MovingCubeAppImpl(); } - std::unique_ptr MovingCubeApp::CreateUnique() - { - return std::make_unique(); - } + std::unique_ptr MovingCubeApp::CreateUnique() { return std::make_unique(); } }