-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[merge] Merge pull request #321 from inexorgame/hanni/octree_collision
[collision] First generation of octree collision detection
- Loading branch information
Showing
30 changed files
with
792 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include <inexor/vulkan-renderer/world/collision_query.hpp> | ||
#include <inexor/vulkan-renderer/world/cube.hpp> | ||
|
||
namespace inexor::vulkan_renderer { | ||
|
||
void CubeCollision(benchmark::State &state) { | ||
for (auto _ : state) { | ||
const glm::vec3 world_pos{0, 0, 0}; | ||
world::Cube world(1.0f, world_pos); | ||
world.set_type(world::Cube::Type::SOLID); | ||
|
||
glm::vec3 cam_pos{0.0f, 0.0f, 10.0f}; | ||
glm::vec3 cam_direction{0.0f, 0.0f, -1.0f}; | ||
|
||
benchmark::DoNotOptimize(ray_cube_collision_check(world, cam_pos, cam_direction)); | ||
} | ||
} | ||
|
||
BENCHMARK(CubeCollision); | ||
|
||
}; // namespace inexor::vulkan_renderer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ Reference | |
binary-format-specification | ||
keyboard-mouse-input | ||
octree-file-format | ||
octree-collision |
187 changes: 187 additions & 0 deletions
187
documentation/source/development/reference/octree-collision.rst
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+93.9 KB
...source/development/reference/octree_collision_boundin_sphere_false_positive.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+109 KB
...mentation/source/development/reference/octree_collision_camera_view_blocked.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+98.7 KB
documentation/source/development/reference/octree_collision_cases.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+89 KB
documentation/source/development/reference/octree_collision_cube_facing_camera.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+79.8 KB
documentation/source/development/reference/octree_collision_filled.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+83.3 KB
documentation/source/development/reference/octree_collision_multiple_octrees.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+118 KB
documentation/source/development/reference/octree_collision_nearest_corner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+131 KB
documentation/source/development/reference/octree_collision_octant.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+109 KB
...ntation/source/development/reference/octree_collision_only_front_collisions.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+186 KB
documentation/source/development/reference/octree_collision_real_face.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <glm/vec3.hpp> | ||
|
||
#include <string> | ||
#include <tuple> | ||
|
||
namespace inexor::vulkan_renderer::world { | ||
|
||
/// @brief A wrapper for collisions between a ray and octree geometry. | ||
/// This class is used for octree collision, but it can be used for every cube-like data structure | ||
/// @tparam T A templatable type which offers a size() and center() method. | ||
template <typename T> | ||
class RayCubeCollision { | ||
const T &m_cube; | ||
|
||
glm::vec3 m_intersection; | ||
glm::vec3 m_selected_face; | ||
glm::vec3 m_nearest_corner; | ||
glm::vec3 m_nearest_edge; | ||
|
||
public: | ||
/// @brief Calculate point of intersection, selected face, | ||
/// nearest corner on that face, and nearest edge on that face. | ||
/// @param cube The cube to check for collision. | ||
/// @param ray_pos The start point of the ray. | ||
/// @param ray_dir The direction of the ray. | ||
RayCubeCollision(const T &cube, glm::vec3 ray_pos, glm::vec3 ray_dir); | ||
|
||
RayCubeCollision(const RayCubeCollision &) = delete; | ||
|
||
RayCubeCollision(RayCubeCollision &&other) noexcept; | ||
|
||
~RayCubeCollision() = default; | ||
|
||
RayCubeCollision &operator=(const RayCubeCollision &) = delete; | ||
RayCubeCollision &operator=(RayCubeCollision &&) = delete; | ||
|
||
[[nodiscard]] const T &cube() const noexcept { | ||
return m_cube; | ||
} | ||
|
||
[[nodiscard]] const glm::vec3 &intersection() const noexcept { | ||
return m_intersection; | ||
} | ||
|
||
[[nodiscard]] const glm::vec3 &face() const noexcept { | ||
return m_selected_face; | ||
} | ||
|
||
[[nodiscard]] const glm::vec3 &corner() const noexcept { | ||
return m_nearest_corner; | ||
} | ||
|
||
[[nodiscard]] const glm::vec3 &edge() const noexcept { | ||
return m_nearest_edge; | ||
} | ||
}; | ||
|
||
} // namespace inexor::vulkan_renderer::world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "inexor/vulkan-renderer/world/collision.hpp" | ||
|
||
#include <glm/vec3.hpp> | ||
|
||
#include <optional> | ||
|
||
// Forward declaration | ||
namespace inexor::vulkan_renderer::world { | ||
class Cube; | ||
} // namespace inexor::vulkan_renderer::world | ||
|
||
namespace inexor::vulkan_renderer::world { | ||
|
||
// TODO: Implement PointCubeCollision | ||
|
||
/// @brief ``True`` of the ray build from the two vectors collides with the cube's bounding box. | ||
/// @note There is no such function as glm::intersectRayBox. | ||
/// @param box_bounds An array of two vectors which represent the edges of the bounding box. | ||
/// @param pos The start position of the ray. | ||
/// @param dir The direction of the ray. | ||
/// @return ``True`` if the ray collides with the octree cube's bounding box. | ||
[[nodiscard]] bool ray_box_collision(std::array<glm::vec3, 2> &box_bounds, glm::vec3 &pos, glm::vec3 &dir); | ||
|
||
/// @brief Check for a collision between a camera ray and octree geometry. | ||
/// @param cube The cube to check collisions with. | ||
/// @param pos The camera position. | ||
/// @param dir The camera view direction. | ||
/// @param max_depth The maximum subcube iteration depth. If this depth is reached and the cube is an octant, it | ||
/// will be treated as if it was a solid cube. This is the foundation for the implementation of grid size in octree | ||
/// editor. | ||
/// @note This does not account yet for octree indentation! | ||
/// @return A std::optional which contains the collision data (if any found). | ||
[[nodiscard]] std::optional<RayCubeCollision<Cube>> | ||
ray_cube_collision_check(const Cube &cube, glm::vec3 pos, glm::vec3 dir, | ||
std::optional<std::uint32_t> max_depth = std::nullopt); | ||
|
||
} // namespace inexor::vulkan_renderer::world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.