1616#include < GLFW/glfw3.h>
1717#include < glad/glad.h>
1818#include < glm/gtc/type_ptr.hpp>
19+ #include < glm/gtx/rotate_vector.hpp>
1920
2021// Standard includes.
2122#include < cassert>
@@ -234,7 +235,7 @@ void MainWindow::imgui_draw()
234235 ImGui::Text (" Position" );
235236 glm::vec3 readonly_pos = m_closest_point_pos;
236237 ImGui::DragFloat3 (" " , glm::value_ptr (readonly_pos));
237- ImGui::Text (" Time %" PRId64 " ms" , m_closest_point_query_time);
238+ ImGui::Text (" Last query time %" PRId64 " ms" , m_closest_point_query_time);
238239 ImGui::TreePop ();
239240 }
240241
@@ -333,13 +334,10 @@ void MainWindow::find_closest_point()
333334 auto timer_start = std::chrono::high_resolution_clock::now ();
334335
335336 // Run the query.
336- for (int i = 0 ; i < 100 ; ++i)
337- {
338- m_closest_point_found = run && m_closest_point_query->get_closest_point (
339- m_query_point_pos,
340- m_query_point_max_serach_radius,
341- m_closest_point_pos);
342- }
337+ m_closest_point_found = run && m_closest_point_query->get_closest_point (
338+ m_query_point_pos,
339+ m_query_point_max_serach_radius,
340+ m_closest_point_pos);
343341
344342 auto timer_stop = std::chrono::high_resolution_clock::now ();
345343 m_closest_point_query_time = std::chrono::duration_cast<std::chrono::milliseconds>(timer_stop - timer_start).count ();
@@ -363,14 +361,17 @@ void MainWindow::find_closest_point()
363361
364362void MainWindow::animate_query_point ()
365363{
366- // Try to move the query point arround the model with some wiggle.
367- const glm::vec3 towards_model = m_closest_point_pos - m_query_point_pos;
368- const glm::vec3 fake_tangent = glm::cross (towards_model, glm::vec3 (0 .0f , 1 .0f , 0 .0f ));
369-
370- const float wiggle = std::sin (m_time_since_startup) * 0 .5f ;
371-
372- m_query_point_pos += fake_tangent * wiggle * m_frame_delta_time;
373- m_query_point_pos += glm::cross (fake_tangent, towards_model) * wiggle * m_frame_delta_time;
364+ // Rotate the query point arround the model.
365+ const float rotation =
366+ m_frame_delta_time
367+ + std::sin (m_time_since_startup * 0 .5f ) * m_frame_delta_time;
368+ m_query_point_pos -= m_closest_point_pos;
369+ m_query_point_pos =
370+ glm::rotate (
371+ m_query_point_pos,
372+ rotation,
373+ glm::vec3 (1 .0f , 1 .0f , 1 .0f ));
374+ m_query_point_pos += m_closest_point_pos;
374375}
375376
376377// GLFW Window callbacks.
0 commit comments