Skip to content

Commit

Permalink
[collision] Setup Google Test for cube collision
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmNotHanni committed Apr 17, 2021
1 parent 42af7ae commit 2b1faf8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 7 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
add_executable(inexor-vulkan-renderer-tests unit_tests_main.cpp)
set(INEXOR_UNIT_TEST_SOURCE_FILES
unit_tests_main.cpp

world/cube_collision.cpp
)

add_executable(inexor-vulkan-renderer-tests ${INEXOR_UNIT_TEST_SOURCE_FILES})

set_target_properties(
inexor-vulkan-renderer-tests PROPERTIES
Expand Down
34 changes: 31 additions & 3 deletions tests/world/cube_collision.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
//
// Created by johannes on 4/17/21.
//
#include <gtest/gtest.h>

#include <inexor/vulkan-renderer/world/collision_query.hpp>
#include <inexor/vulkan-renderer/world/cube.hpp>

namespace inexor::vulkan_renderer {

TEST(CubeCollision, CollisionCheck) {
const glm::vec3 world_pos{0, 0, 0};
world::Cube world(world::Cube::Type::SOLID, 1.0f, world_pos);

glm::vec3 cam_pos{0.0f, 0.0f, 10.0f};
glm::vec3 cam_direction{0.0f, 0.0f, 0.0f};

world::OctreeCollisionQuery collision_check(world);
auto collision1 = collision_check.check_for_collision(cam_pos, cam_direction);
bool collision_found = collision1.has_value();

// There must be no collision for this data setup.
ASSERT_EQ(collision_found, false);

cam_direction = {0.0f, 0.0f, -1.0f};

auto collision2 = collision_check.check_for_collision(cam_pos, cam_direction);
collision_found = collision2.has_value();

// Since we are now directly looking down on the cube, we collide with it.
ASSERT_EQ(collision_found, true);
}

}; // namespace inexor::vulkan_renderer

0 comments on commit 2b1faf8

Please sign in to comment.