Skip to content

Commit 4a04e2c

Browse files
committed
feat: improve query animation and logs
1 parent 5083358 commit 4a04e2c

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

src/core/mesh_point_cloud.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
#include "mesh_point_cloud.h"
22

3+
#include <chrono>
4+
#include <iostream>
5+
36
namespace core
47
{
58

69
MeshPointCloud::MeshPointCloud(const Mesh& mesh)
710
: m_mesh(mesh)
811
{
12+
// Start a timer to know how long it takes to generate the point cloud.
13+
auto timer_start = std::chrono::high_resolution_clock::now();
14+
915
// Add all mesh vertices in the point cloud.
1016
const std::vector<Mesh::Vertex>& vertices = m_mesh.get_vertices();
1117
const std::vector<unsigned int>& triangles = m_mesh.get_triangles();
1218
const std::size_t index_count = triangles.size();
1319
assert(index_count % 3 == 0);
1420

21+
std::cout << "Creating a new mesh point cloud...\n";
22+
std::cout << "\tMesh vertex count: " << vertices.size() << "\n";
23+
std::cout << "\tMesh triangle count: " << (index_count / 3) << "\n";
24+
1525
m_points.reserve(index_count);
1626

1727
for (std::size_t i = 0; i < index_count; ++i)
1828
{
1929
m_points.push_back(vertices[triangles[i]].pos);
2030
}
31+
32+
auto timer_stop = std::chrono::high_resolution_clock::now();
33+
auto process_time = std::chrono::duration_cast<std::chrono::milliseconds>(timer_stop - timer_start).count();
34+
35+
std::cout << "Generated mesh point cloud in " << process_time << "ms.\n";
36+
std::cout << "\tPoint count: " << m_points.size() << "\n";
2137
}
2238

2339
} // namespace core

src/gui/mainwindow.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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

364362
void 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

Comments
 (0)