@@ -126,6 +126,10 @@ void MainWindow::run()
126126 process_glfw_window_inputs ();
127127 ImGui_ImplGlfwGL3_NewFrame ();
128128
129+ // Animation query point.
130+ if (m_animate_query_point)
131+ animate_query_point ();
132+
129133 // Run query.
130134 if (m_closest_point_query)
131135 find_closest_point ();
@@ -148,7 +152,13 @@ void MainWindow::release()
148152
149153void MainWindow::load_scene (const std::string& path)
150154{
155+ // Stop the running animation.
156+ m_animate_query_point = false ;
157+
158+ // Load the scene.
151159 m_scene.reset (core::load_scene_from_file (path));
160+
161+ // Prepare closest point queries.
152162 core::ClosestPointQuery* query = new core::ClosestPointQuery (m_scene->get_mesh ());
153163 m_closest_point_query.reset (query);
154164}
@@ -157,6 +167,7 @@ void MainWindow::load_scene(const std::string& path)
157167MainWindow::MainWindow ()
158168 : m_query_point_max_serach_radius(10 .0f )
159169 , m_query_point_pos(-1 .2f , 1 .6f , 2 .8f )
170+ , m_animate_query_point(false )
160171{}
161172
162173// Singleton instance.
@@ -189,9 +200,20 @@ void MainWindow::imgui_draw()
189200 {
190201 ImGui::Text (" Position" );
191202 ImGui::DragFloat3 (" " , glm::value_ptr (m_query_point_pos), 0 .1f );
203+
192204 ImGui::Text (" Maximum search radius" );
193205 ImGui::DragFloat (" " , &m_query_point_max_serach_radius, 0 .1f , 0 .0f );
194206 m_query_point_max_serach_radius = std::max (m_query_point_max_serach_radius, 0 .0f );
207+
208+ if (!m_animate_query_point && ImGui::Button (" Animate query point" ))
209+ {
210+ m_animate_query_point = true ;
211+ }
212+ else if (m_animate_query_point && ImGui::Button (" Stop animation" ))
213+ {
214+ m_animate_query_point = false ;
215+ }
216+
195217 ImGui::TreePop ();
196218 }
197219
@@ -300,7 +322,7 @@ void MainWindow::find_closest_point()
300322 auto timer_start = std::chrono::high_resolution_clock::now ();
301323
302324 // Run the query.
303- bool found = run && m_closest_point_query->get_closest_point (
325+ m_closest_point_found = run && m_closest_point_query->get_closest_point (
304326 m_query_point_pos,
305327 m_query_point_max_serach_radius,
306328 m_closest_point_pos);
@@ -316,7 +338,7 @@ void MainWindow::find_closest_point()
316338 { 0.8 , 0.8 , 0.8 , 1.0 }
317339 });
318340 // Add the closest result point (in green).
319- if (found )
341+ if (m_closest_point_found )
320342 points.push_back ({
321343 m_closest_point_pos,
322344 { 0.1 , 1.0 , 0.1 , 1.0 }
@@ -325,6 +347,18 @@ void MainWindow::find_closest_point()
325347 m_scene_points.set_points (points);
326348}
327349
350+ void MainWindow::animate_query_point ()
351+ {
352+ // Try to move the query point arround the model with some wiggle.
353+ const glm::vec3 towards_model = m_closest_point_pos - m_query_point_pos;
354+ const glm::vec3 somewhere_else = glm::cross (towards_model, glm::vec3 (0 .0f , 1 .0f , 0 .0f ));
355+
356+ const float wiggle = std::sin (m_time_since_startup) * 0 .5f ;
357+
358+ m_query_point_pos += towards_model * wiggle * m_frame_delta_time;
359+ m_query_point_pos += somewhere_else * m_frame_delta_time;
360+ }
361+
328362// GLFW Window callbacks.
329363void MainWindow::glfw_framebuffer_size_callback (GLFWwindow* window, int width, int height)
330364{
0 commit comments