diff --git a/app/next/src/main_window.cpp b/app/next/src/main_window.cpp index ade8b3d..53b4d33 100644 --- a/app/next/src/main_window.cpp +++ b/app/next/src/main_window.cpp @@ -90,6 +90,16 @@ namespace zephyr { camera_transform.SetPosition(camera_position); camera_transform.GetRotation().SetFromEuler(euler_x, euler_y, 0.0f); + for(SceneNode* cube : m_dynamic_cubes) { + Vector3 position = cube->GetTransform().GetPosition(); + position.X() += 0.01; + cube->GetTransform().SetPosition(position); + + Quaternion rotation = cube->GetTransform().GetRotation().GetAsQuaternion(); + rotation = Quaternion::FromAxisAngle({0, 1, 0}, 0.01f) * rotation; + cube->GetTransform().GetRotation().SetFromQuaternion(rotation); + } + RenderFrame(); } } @@ -268,6 +278,10 @@ namespace zephyr { cube->CreateComponent(cube_geometry, std::shared_ptr{}); cube->GetTransform().SetPosition({(f32)x, (f32)y, (f32)-z}); cube->GetTransform().SetScale({0.1, 0.1, 0.1}); + + if(m_dynamic_cubes.size() < 32768) { + m_dynamic_cubes.push_back(cube.get()); + } } } } diff --git a/app/next/src/main_window.hpp b/app/next/src/main_window.hpp index d66ce04..85c0b4d 100644 --- a/app/next/src/main_window.hpp +++ b/app/next/src/main_window.hpp @@ -45,6 +45,7 @@ namespace zephyr { std::shared_ptr m_scene_graph{}; std::shared_ptr m_camera_node{}; std::shared_ptr m_behemoth_scene{}; + std::vector m_dynamic_cubes{}; int m_fps_counter{}; std::chrono::steady_clock::time_point m_time_point_last_update{}; diff --git a/zephyr/scene/include/zephyr/scene/scene_graph.hpp b/zephyr/scene/include/zephyr/scene/scene_graph.hpp index 2417b1a..24d4fe2 100644 --- a/zephyr/scene/include/zephyr/scene/scene_graph.hpp +++ b/zephyr/scene/include/zephyr/scene/scene_graph.hpp @@ -31,6 +31,7 @@ namespace zephyr { void SignalNodeTransformChanged(SceneNode* node); std::shared_ptr m_root_node{}; + std::vector m_pending_nodes_with_dirty_transforms{}; std::vector m_nodes_with_dirty_transform{}; }; diff --git a/zephyr/scene/src/scene_graph.cpp b/zephyr/scene/src/scene_graph.cpp index 0c2f318..185d426 100644 --- a/zephyr/scene/src/scene_graph.cpp +++ b/zephyr/scene/src/scene_graph.cpp @@ -33,11 +33,8 @@ namespace zephyr { } void SceneGraph::SignalNodeTransformChanged(SceneNode* node) { + // TODO(fleroviux): try to efficiently eliminate redundant updates. node->Traverse([this](SceneNode* child_node) { - const auto match = std::ranges::find(m_nodes_with_dirty_transform, child_node); - if(match != m_nodes_with_dirty_transform.end()) { - m_nodes_with_dirty_transform.erase(match); - } m_nodes_with_dirty_transform.push_back(child_node); return true; });