Skip to content

Commit

Permalink
[collision-solver] Simplify class
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmNotHanni committed Jul 24, 2021
1 parent cbed1d4 commit 0a0aede
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/inexor/vulkan-renderer/world/collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RayCubeCollision {
/// @brief Default constructor
/// @param The cube to check collisions with
/// @note We need to pass cube as a std::shared_ptr by copy in this case because we want to ensure the lifetime
/// of the object in multithreaded code. We are not accepting const references here, as they could become invalid.
/// of the object in parallelized code. We are not accepting const references here, as they could become invalid.
/// @param ray The start point of the ray
/// @param dir The direction of the ray
/// @param The intersection between ray and vertex geometry of the cube which was found
Expand Down
6 changes: 2 additions & 4 deletions include/inexor/vulkan-renderer/world/collision_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ class OctreeCollisionSolver {
glm::vec3 direction, bool find_only_one_collision = true);

public:
/// @brief Default constructor.
/// @param octree_count The number of octrees
explicit OctreeCollisionSolver(std::size_t octree_count);

// TODO: Implement min/max collision distance if required.
// TODO: Start sorting only after a certain number of worlds.
// TODO: Start sorting octrees by distance to camera only after a certain number of worlds.
// TODO: Implement a bounding volume hierarchy (BVH) tree, for example an octree for all the octrees.

/// @brief Find a collision between a ray and an octree which is closest to the camera.
/// @param worlds The octrees to check for collision
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan-renderer/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void Application::load_octree_geometry() {
m_worlds.emplace_back(std::make_shared<world::Cube>(1.0f, glm::vec3{0, 0, 0}));
m_worlds.emplace_back(std::make_shared<world::Cube>(1.6f, glm::vec3{0, 10, 0}));

m_collision_solver = std::make_unique<world::OctreeCollisionSolver>(m_worlds.size());
m_collision_solver = std::make_unique<world::OctreeCollisionSolver>();

m_worlds[0]->set_type(world::Cube::Type::OCTANT);
m_worlds[1]->set_type(world::Cube::Type::SOLID);
Expand Down
2 changes: 0 additions & 2 deletions src/vulkan-renderer/world/collision_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ std::optional<RayCubeCollision<Cube>> ray_cube_collision_check(const std::shared
continue;
}

// TODO: Implement min/max collision distance if required.

collision_candidates.emplace_back(
std::make_pair(subcube, glm::distance2(subcube->center(), cube->center())));
}
Expand Down
9 changes: 4 additions & 5 deletions src/vulkan-renderer/world/collision_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

namespace inexor::vulkan_renderer::world {

OctreeCollisionSolver::OctreeCollisionSolver(const std::size_t octree_count) {
assert(octree_count > 0);
m_collision_candidates.reserve(octree_count);
}

std::vector<RayCubeCollision<Cube>>
OctreeCollisionSolver::find_all_ray_octree_collisions(const std::vector<std::shared_ptr<world::Cube>> &worlds,
const glm::vec3 position, const glm::vec3 direction,
Expand All @@ -29,6 +24,10 @@ OctreeCollisionSolver::find_all_ray_octree_collisions(const std::vector<std::sha
// We need a critical section because we are modifying m_collision_candidates.
std::scoped_lock lock(m_collision_solver_mutex);
{
// TODO: Optimize this! Avoid memory re-allocation if possible and benchmark it.
m_collision_candidates.clear();
m_collision_candidates.reserve(worlds.size());

for (const auto &world : worlds) {
if (!is_bounding_box_and_bounding_sphere_hit(world, position, direction)) {
continue;
Expand Down

0 comments on commit 0a0aede

Please sign in to comment.