Skip to content

Commit ceb09db

Browse files
committed
[*] Remove old collision detection
1 parent e5a7616 commit ceb09db

File tree

11 files changed

+13
-493
lines changed

11 files changed

+13
-493
lines changed

benchmarks/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
set(INEXOR_BENCHMARKING_SOURCE_FILES
22
engine_benchmark_main.cpp
3-
4-
world/cube_collision.cpp
53
)
64

75
add_executable(inexor-vulkan-renderer-benchmarks ${INEXOR_BENCHMARKING_SOURCE_FILES})

benchmarks/world/cube_collision.cpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

include/inexor/vulkan-renderer/application.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "inexor/vulkan-renderer/input/keyboard_mouse_data.hpp"
44
#include "inexor/vulkan-renderer/renderer.hpp"
5-
#include "inexor/vulkan-renderer/world/collision_query.hpp"
65
#include "inexor/vulkan-renderer/world/cube.hpp"
76

87
#include <GLFW/glfw3.h>
@@ -32,6 +31,15 @@ class Application : public VulkanRenderer {
3231
/// Inexor engine supports a variable number of octrees.
3332
std::vector<std::shared_ptr<world::Cube>> m_worlds;
3433

34+
/// If multiple root octrees exist, we check for collisions between camera ray and octree by increasing square of
35+
/// the distance between the camera and the root octree's center. This way, we check for collisions with the nearest
36+
/// root octrees first. Furthermore, we avoid using a sqrt function for distance calculation, which is an expensive
37+
/// calculation to perform.
38+
/// The first value of the std::pair is the index in the m_worlds vector, the second value is the square of the
39+
/// distance betweeen the camera and the root octree's center.
40+
/// We do not perform any memory allocations on m_collision_candidates as long as m_worlds does not change.
41+
std::vector<std::pair<std::size_t, float>> m_collision_candidates;
42+
3543
// If the user specified command line argument "--stop-on-validation-message", the program will call
3644
// std::abort(); after reporting a validation layer (error) message.
3745
bool m_stop_on_validation_message{false};

include/inexor/vulkan-renderer/world/collision.hpp

Lines changed: 0 additions & 60 deletions
This file was deleted.

include/inexor/vulkan-renderer/world/collision_query.hpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ set(INEXOR_SOURCE_FILES
4343
vulkan-renderer/wrapper/window.cpp
4444
vulkan-renderer/wrapper/window_surface.cpp
4545

46-
vulkan-renderer/world/collision.cpp
47-
vulkan-renderer/world/collision_query.cpp
4846
vulkan-renderer/world/cube.cpp
4947
vulkan-renderer/world/indentation.cpp)
5048

src/vulkan-renderer/application.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "inexor/vulkan-renderer/octree_gpu_vertex.hpp"
66
#include "inexor/vulkan-renderer/standard_ubo.hpp"
77
#include "inexor/vulkan-renderer/tools/cla_parser.hpp"
8-
#include "inexor/vulkan-renderer/world/collision.hpp"
98
#include "inexor/vulkan-renderer/world/cube.hpp"
109
#include "inexor/vulkan-renderer/wrapper/cpu_texture.hpp"
1110
#include "inexor/vulkan-renderer/wrapper/descriptor_builder.hpp"
@@ -200,6 +199,9 @@ void Application::load_octree_geometry(bool initialize) {
200199
m_worlds.push_back(
201200
world::create_random_world(2, {10.0f, 0.0f, 0.0f}, initialize ? std::optional(60) : std::nullopt));
202201

202+
// Reserve memory for collision checks
203+
m_collision_candidates.reserve(m_worlds.size());
204+
203205
m_octree_vertices.clear();
204206
for (const auto &world : m_worlds) {
205207
for (const auto &polygons : world->polygons(true)) {
@@ -575,24 +577,7 @@ void Application::process_mouse_input() {
575577
}
576578

577579
void Application::check_octree_collisions() {
578-
// Check for collision between camera ray and every octree
579-
for (const auto &world : m_worlds) {
580-
const auto collision = ray_cube_collision_check(*world, m_camera->position(), m_camera->front());
581-
582-
if (collision) {
583-
const auto intersection = collision.value().intersection();
584-
const auto face_normal = collision.value().face();
585-
const auto corner = collision.value().corner();
586-
const auto edge = collision.value().edge();
587-
588-
spdlog::trace("pos {} {} {} | face {} {} {} | corner {} {} {} | edge {} {} {}", intersection.x,
589-
intersection.y, intersection.z, face_normal.x, face_normal.y, face_normal.z, corner.x,
590-
corner.y, corner.z, edge.x, edge.y, edge.z);
591-
592-
// Break after one collision.
593-
break;
594-
}
595-
}
580+
// TODO
596581
}
597582

598583
void Application::run() {

src/vulkan-renderer/world/collision.cpp

Lines changed: 0 additions & 183 deletions
This file was deleted.

0 commit comments

Comments
 (0)