-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from epitech-mirroring/feature/epi-46-collision…
…s-methods 💥 Add collisions methods
- Loading branch information
Showing
8 changed files
with
268 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** StellarForge | ||
** File description: | ||
** No file there , just an epitech header example . | ||
*/ | ||
|
||
#include "Sphere.hpp" | ||
#include "Box.hpp" | ||
#include "Physics.hpp" | ||
|
||
Box::Box(Vector3 position, Vector3 size) : position(position), size(size) | ||
{ | ||
} | ||
|
||
bool Box::collide(ICollider *collider) { | ||
if (dynamic_cast<Box *>(collider) != nullptr) { | ||
return Physics::Collision::boxCollideBox(*this, *dynamic_cast<Box *>(collider)); | ||
} else if (dynamic_cast<Sphere *>(collider) != nullptr) { | ||
return Physics::Collision::boxCollideSphere(*this, *dynamic_cast<Sphere *>(collider)); | ||
} | ||
return false; | ||
} |
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,48 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** StellarForge | ||
** File description: | ||
** No file there , just an epitech header example . | ||
*/ | ||
|
||
#ifndef STELLARFORGE_BOX_HPP | ||
#define STELLARFORGE_BOX_HPP | ||
|
||
#include "Collider.hpp" | ||
|
||
/** | ||
* @class Box | ||
* @brief A class that represents a box in 3D space. | ||
* @details This class contains the position and size of the box. | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @author Landry GIGANT | ||
*/ | ||
class Box : public ICollider { | ||
public: | ||
/** | ||
* @brief The position of the box in 3D space. | ||
*/ | ||
Vector3 position; | ||
|
||
/** | ||
* @brief The size of the box in 3D space. | ||
*/ | ||
Vector3 size; | ||
|
||
/** | ||
* @brief Constructor for the Box class. | ||
* @param position The position of the box in 3D space. | ||
* @param size The size of the box in 3D space. | ||
*/ | ||
Box(Vector3 position, Vector3 size); | ||
|
||
/** | ||
* @brief Check if the box collides with another collider. | ||
* @param collider The collider to check for collision. | ||
* @return True if the box collides with the collider, false otherwise. | ||
*/ | ||
bool collide(ICollider *collider) override; | ||
}; | ||
|
||
#endif //STELLARFORGE_BOX_HPP |
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,44 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** StellarForge | ||
** File description: | ||
** No file there , just an epitech header example . | ||
*/ | ||
|
||
#ifndef STELLARFORGE_COLLIDER_HPP | ||
#define STELLARFORGE_COLLIDER_HPP | ||
|
||
#include <glm/glm.hpp> | ||
|
||
using Vector3 = glm::vec3; | ||
|
||
/** | ||
* @class ICollider | ||
* @brief Interface for colliders in the physics system. | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @details This interface defines the basic structure for colliders, including a method to check for collisions. | ||
* @author Landry GIGANT | ||
*/ | ||
class ICollider { | ||
public: | ||
/** | ||
* @brief Virtual destructor for the ICollider interface. | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @author Landry GIGANT | ||
*/ | ||
virtual ~ICollider() = default; | ||
|
||
/** | ||
* @brief Check if this collider collides with another collider. | ||
* @param collider Pointer to the other collider. | ||
* @return True if the colliders collide, false otherwise. | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @author Landry GIGANT | ||
*/ | ||
virtual bool collide(ICollider *collider) = 0; | ||
}; | ||
|
||
#endif //STELLARFORGE_COLLIDER_HPP |
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,23 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** StellarForge | ||
** File description: | ||
** No file there , just an epitech header example . | ||
*/ | ||
|
||
#include "Sphere.hpp" | ||
#include "Box.hpp" | ||
#include "Physics.hpp" | ||
|
||
Sphere::Sphere(Vector3 position, float radius) : position(position), radius(radius) | ||
{ | ||
} | ||
|
||
bool Sphere::collide(ICollider *collider) { | ||
if (dynamic_cast<Sphere *>(collider) != nullptr) { | ||
return Physics::Collision::sphereCollideSphere(*this, *dynamic_cast<Sphere *>(collider)); | ||
} else if (dynamic_cast<Box *>(collider) != nullptr) { | ||
return Physics::Collision::sphereCollideBox(*this, *dynamic_cast<Box *>(collider)); | ||
} | ||
return false; | ||
} |
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,48 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** StellarForge | ||
** File description: | ||
** No file there , just an epitech header example . | ||
*/ | ||
|
||
#ifndef STELLARFORGE_SPHERE_HPP | ||
#define STELLARFORGE_SPHERE_HPP | ||
|
||
#include "Collider.hpp" | ||
|
||
/** | ||
* @class Sphere | ||
* @brief A class that represents a sphere in 3D space. | ||
* @details This class contains the position and radius of the sphere. | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @author Landry GIGANT | ||
*/ | ||
class Sphere : public ICollider { | ||
public: | ||
/** | ||
* @brief The position of the sphere in 3D space. | ||
*/ | ||
Vector3 position; | ||
|
||
/** | ||
* @brief The radius of the sphere. | ||
*/ | ||
float radius; | ||
|
||
/** | ||
* @brief Constructor for the Sphere class. | ||
* @param position The position of the sphere in 3D space. | ||
* @param radius The radius of the sphere. | ||
*/ | ||
Sphere(Vector3 position, float radius); | ||
|
||
/** | ||
* @brief Check if the sphere collides with another collider. | ||
* @param collider The collider to check for collision. | ||
* @return True if the sphere collides with the collider, false otherwise. | ||
*/ | ||
bool collide(ICollider *collider) override; | ||
}; | ||
|
||
#endif //STELLARFORGE_SPHERE_HPP |