-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
8,655 additions
and
4,862 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 330 core | ||
out vec4 FragColor; | ||
|
||
uniform vec3 aabbColor = vec3(0,0.8,0); | ||
|
||
void main() { | ||
FragColor = vec4(aabbColor, 1.0); | ||
} |
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,10 @@ | ||
#version 330 core | ||
layout (location = 0) in vec3 aPos; | ||
|
||
uniform mat4 model = mat4(1.0); | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
void main() { | ||
gl_Position = projection * view * model * vec4(aPos, 1.0); | ||
} |
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 not shown.
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "Collider.h" | ||
|
||
#include "World/Physics/CollisionRegister.h" | ||
#include "pch.h" | ||
#include <utility> | ||
|
||
Collider::Collider(CollisionRegister& collisionRegister) | ||
: mCollisionRegister(collisionRegister) | ||
{ | ||
mCollisionRegister.add(*this); | ||
} | ||
|
||
Collider::~Collider() | ||
{ | ||
mCollisionRegister.remove(*this); | ||
} | ||
|
||
void Collider::executeCallback(const Collider& other) const | ||
{ | ||
if (mCallback) | ||
{ | ||
mCallback(other); | ||
} | ||
} | ||
|
||
void Collider::callback(std::function<void(const Collider&)> callbackFunction) | ||
{ | ||
mCallback = std::move(callbackFunction); | ||
} | ||
|
||
ColliderTag Collider::colliderTag() const | ||
{ | ||
return mColliderTag; | ||
} | ||
|
||
void Collider::colliderTag(ColliderTag colliderTag) | ||
{ | ||
mColliderTag = colliderTag; | ||
} |
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,78 @@ | ||
#pragma once | ||
#include "World/Physics/ColliderTag.h" | ||
|
||
class SphereCollider; | ||
class RectangleCollider; | ||
class RayCollider; | ||
class CollisionRegister; | ||
|
||
/** | ||
* \brief Base class for collision detection objects. | ||
*/ | ||
class Collider | ||
{ | ||
public: | ||
/** | ||
* \brief Constructor that registers the collider with a collision management system. | ||
* \param collisionRegister Reference to the collision register for tracking colliders. | ||
*/ | ||
Collider(CollisionRegister& collisionRegister); | ||
virtual ~Collider(); | ||
|
||
/** | ||
* \brief Pure virtual method to check collision with another collider. | ||
* \param other Reference to another collider. | ||
* \return True if collision occurs, false otherwise. | ||
*/ | ||
[[nodiscard]] virtual bool checkCollision(const Collider& other) const = 0; | ||
|
||
/** | ||
* \brief Checks collision with a SphereCollider. | ||
* \param other SphereCollider to check against. | ||
* \return True if collision occurs, false otherwise. | ||
*/ | ||
[[nodiscard]] virtual bool checkCollisionWith(const SphereCollider& other) const = 0; | ||
|
||
/** | ||
* \brief Checks collision with a RectangleCollider. | ||
* \param other RectangleCollider to check against. | ||
* \return True if collision occurs, false otherwise. | ||
*/ | ||
[[nodiscard]] virtual bool checkCollisionWith(const RectangleCollider& other) const = 0; | ||
|
||
/** | ||
* \brief Checks collision with a RayCollider. | ||
* \param other RayCollider to check against. | ||
* \return True if collision occurs, false otherwise. | ||
*/ | ||
[[nodiscard]] virtual bool checkCollisionWith(const RayCollider& other) const = 0; | ||
|
||
/** | ||
* \brief Executes a callback function upon collision detection. | ||
* \param other Collider that triggered the callback. | ||
*/ | ||
void executeCallback(const Collider& other) const; | ||
|
||
/** | ||
* \brief Sets the callback function to be executed on collision. | ||
* \param callbackFunction The function to call on collision. | ||
*/ | ||
virtual void callback(std::function<void(const Collider&)> callbackFunction); | ||
|
||
/** | ||
* \brief Gets the tag identifying the type of collider. | ||
* \return The collider's tag. | ||
*/ | ||
[[nodiscard]] ColliderTag colliderTag() const; | ||
|
||
/** | ||
* \brief Sets the tag identifying the type of collider. | ||
* \param colliderTag The tag to set. | ||
*/ | ||
void colliderTag(ColliderTag colliderTag); | ||
|
||
private: | ||
std::function<void(const Collider&)> mCallback; | ||
CollisionRegister& mCollisionRegister; | ||
ColliderTag mColliderTag{ColliderTag::None}; | ||
}; |
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,11 @@ | ||
#pragma once | ||
|
||
/** | ||
* \brief Tag identifying the type of collider. | ||
*/ | ||
enum class ColliderTag | ||
{ | ||
None, | ||
Solid, | ||
GunShot, | ||
}; |
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,38 @@ | ||
#include "CollisionRegister.h" | ||
#include "Collider.h" | ||
#include "pch.h" | ||
|
||
void CollisionRegister::add(const Collider& collider) | ||
{ | ||
mColliderToAdd.push_back(&collider); | ||
} | ||
|
||
void CollisionRegister::remove(const Collider& collider) | ||
{ | ||
mColliderToRemove.push_back(&collider); | ||
} | ||
|
||
void CollisionRegister::updateAllCollisions() | ||
{ | ||
for (auto& collider: mColliderToAdd) | ||
{ | ||
mColliders.push_back(collider); | ||
} | ||
mColliderToAdd.clear(); | ||
for (auto& collider: mColliderToRemove) | ||
{ | ||
mColliders.erase(std::find(mColliders.begin(), mColliders.end(), collider)); | ||
} | ||
mColliderToRemove.clear(); | ||
for (size_t i = 0; i < mColliders.size(); ++i) | ||
{ | ||
for (size_t j = i + 1; j < mColliders.size(); ++j) | ||
{ | ||
if (mColliders[i]->checkCollision(*mColliders[j])) | ||
{ | ||
mColliders[i]->executeCallback(*mColliders[j]); | ||
mColliders[j]->executeCallback(*mColliders[i]); | ||
} | ||
} | ||
} | ||
} |
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,32 @@ | ||
#pragma once | ||
|
||
class Collider; | ||
|
||
/** | ||
* \brief Manages the registration and tracking of colliders for collision detection. | ||
*/ | ||
class CollisionRegister | ||
{ | ||
public: | ||
/** | ||
* \brief Adds a collider to the registry for collision tracking. | ||
* \param collider Reference to the collider to be added. | ||
*/ | ||
void add(const Collider& collider); | ||
|
||
/** | ||
* \brief Removes a collider from the registry. | ||
* \param collider Reference to the collider to be removed. | ||
*/ | ||
void remove(const Collider& collider); | ||
|
||
/** | ||
* \brief Updates and checks for collisions among all registered colliders. | ||
*/ | ||
void updateAllCollisions(); | ||
|
||
private: | ||
std::vector<const Collider*> mColliders; | ||
std::vector<const Collider*> mColliderToRemove; | ||
std::vector<const Collider*> mColliderToAdd; | ||
}; |
Oops, something went wrong.