-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[collision] Setup Google Test for cube collision
- Loading branch information
1 parent
42af7ae
commit 2b1faf8
Showing
2 changed files
with
38 additions
and
4 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 |
---|---|---|
@@ -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 |