Skip to content

Commit

Permalink
feat: add 3D components (BoxCollider, Control, Movable, RigidBody, Sp…
Browse files Browse the repository at this point in the history
…hereCollider, Transform) for 3D entities
  • Loading branch information
MasterLaplace committed Nov 17, 2024
1 parent c9e6c15 commit 461fad0
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2024-11-11
** File description:
** BoxCollider
*/

#ifndef FLAKKARI_BOXCOLLIDER_HPP_
#define FLAKKARI_BOXCOLLIDER_HPP_

#include "../../../Math/Vector.hpp"

namespace Flakkari::Engine::ECS::Components::_3D {
LPL_PACKED_START

/**
* @brief BoxCollider component for 3D entities
*/
struct BoxCollider {
Math::Vector3f _center;
Math::Vector3f _size;

BoxCollider() : _center(), _size() {}
BoxCollider(Math::Vector3f center, Math::Vector3f size) : _center(center), _size(size) {}
BoxCollider(const BoxCollider &other) : _center(other._center), _size(other._size) {}

BoxCollider &operator=(const BoxCollider &other)
{
if (this != &other)
{
_center = other._center;
_size = other._size;
}

return *this;
}

std::size_t size() const { return sizeof(*this); }
};

LPL_PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_3D

#endif /* !FLAKKARI_BOXCOLLIDER_HPP_ */
85 changes: 85 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/3D/Control.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2024-01-11
** File description:
** Control
*/

#ifndef FLAKKARI_3D_CONTROL_HPP_
#define FLAKKARI_3D_CONTROL_HPP_

#include "../../../Math/Vector.hpp"

namespace Flakkari::Engine::ECS::Components::_3D {
LPL_PACKED_START

/**
* @brief Control component for 3D entities (player, enemies, etc...)
*
* @details
* _move_up: move up (give access to the move up)
* _move_down: move down (give access to the move down)
* _move_left: move left (give access to the move left)
* _move_right: move right (give access to the move right)
* _move_front: move front (give access to the move front)
* _move_back: move back (give access to the move back)
* _look_up: look up (give access to the look up)
* _look_down: look down (give access to the look down)
* _look_left: look left (give access to the look left)
* _look_right: look right (give access to the look right)
* _shoot: shoot (give access to the shoot)
*/
struct Control {
bool _move_up = false;
bool _move_down = false;
bool _move_left = false;
bool _move_right = false;
bool _move_front = false;
bool _move_back = false;
bool _look_up = false;
bool _look_down = false;
bool _look_left = false;
bool _look_right = false;
bool _shoot = false;

Control() = default;
Control(bool m_up, bool m_down, bool m_left, bool m_right, bool m_front, bool m_back, bool l_up, bool l_down,
bool l_left, bool l_right, bool s)
: _move_up(m_up), _move_down(m_down), _move_left(m_left), _move_right(m_right), _move_front(m_front),
_move_back(m_back), _look_up(l_up), _look_down(l_down), _look_left(l_left), _look_right(l_right),
_shoot(s) {};
Control(const Control &other)
: _move_up(other._move_up), _move_down(other._move_down), _move_left(other._move_left),
_move_right(other._move_right), _move_front(other._move_front), _move_back(other._move_back),
_look_up(other._look_up), _look_down(other._look_down), _look_left(other._look_left),
_look_right(other._look_right), _shoot(other._shoot) {};

Control &operator=(const Control &other)
{
if (this != &other)
{
_move_up = other._move_up;
_move_down = other._move_down;
_move_left = other._move_left;
_move_right = other._move_right;
_move_front = other._move_front;
_move_back = other._move_back;
_look_up = other._look_up;
_look_down = other._look_down;
_look_left = other._look_left;
_look_right = other._look_right;
_shoot = other._shoot;
}

return *this;
}

std::size_t size() const { return sizeof(*this); }
};

LPL_PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_3D

#endif /* !FLAKKARI_3D_CONTROL_HPP_ */
47 changes: 47 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/3D/Movable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2024-11-11
** File description:
** Movable
*/

#ifndef FLAKKARI_3D_MOVABLE_HPP_
#define FLAKKARI_3D_MOVABLE_HPP_

#include "../../../Math/Vector.hpp"

namespace Flakkari::Engine::ECS::Components::_3D {
LPL_PACKED_START

/**
* @brief Movable component for 3D entities
*/
struct Movable {
Math::Vector3f _velocity;
Math::Vector3f _acceleration;

Movable() : _velocity(0, 0), _acceleration(0, 0) {}
Movable(const Math::Vector3f &velocity, const Math::Vector3f &acceleration)
: _velocity(velocity), _acceleration(acceleration){};
Movable(const Movable &other) : _velocity(other._velocity), _acceleration(other._acceleration){};

Movable &operator=(const Movable &other)
{
if (this != &other)
{
_velocity = other._velocity;
_acceleration = other._acceleration;
}

return *this;
}

std::size_t size() const { return sizeof(*this); }
};

LPL_PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_3D

#endif /* !FLAKKARI_3D_MOVABLE_HPP_ */
55 changes: 55 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/3D/RigidBody.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2024-11-11
** File description:
** RigidBody
*/

#ifndef FLAKKARI_3D_RIGIDBODY_HPP_
#define FLAKKARI_3D_RIGIDBODY_HPP_

#include "../../../Math/Vector.hpp"

namespace Flakkari::Engine::ECS::Components::_3D {
LPL_PACKED_START

/**
* @brief RigidBody represent the physical properties of a rigid body in a game engine
*/
struct RigidBody {
float _mass;
float _drag;
float _angularDrag;
bool _useGravity = true;
bool _isKinematic = false;

RigidBody() : _mass(0), _drag(0), _angularDrag(0), _useGravity(false), _isKinematic(false) {};
RigidBody(const RigidBody &other)
: _mass(other._mass), _drag(other._drag), _angularDrag(other._angularDrag), _useGravity(other._useGravity),
_isKinematic(other._isKinematic) {};
RigidBody(float mass, float drag, float angularDrag, bool useGravity, bool isKinematic)
: _mass(mass), _drag(drag), _angularDrag(angularDrag), _useGravity(useGravity), _isKinematic(isKinematic) {};

RigidBody &operator=(const RigidBody &other)
{
if (this != &other)
{
_mass = other._mass;
_drag = other._drag;
_angularDrag = other._angularDrag;
_useGravity = other._useGravity;
_isKinematic = other._isKinematic;
}

return *this;
}

std::size_t size() const { return sizeof(*this); }
};

LPL_PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_3D

#endif /* !FLAKKARI_3D_RIGIDBODY_HPP_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2024-11-11
** File description:
** SphereCollider
*/

#ifndef FLAKKARI_SPHERECOLLIDER_HPP_
#define FLAKKARI_SPHERECOLLIDER_HPP_

#include "../../../Math/Vector.hpp"

namespace Flakkari::Engine::ECS::Components::_3D {
LPL_PACKED_START

/**
* @brief SphereCollider component for 3D entities
*/
struct SphereCollider {
Math::Vector3f _center;
float _radius;

SphereCollider() : _center(), _radius() {}
SphereCollider(Math::Vector3f center, float radius) : _center(center), _radius(radius) {}
SphereCollider(const SphereCollider &other) : _center(other._center), _radius(other._radius) {}

SphereCollider &operator=(const SphereCollider &other)
{
if (this != &other)
{
_center = other._center;
_radius = other._radius;
}

return *this;
}

std::size_t size() const { return sizeof(*this); }
};

LPL_PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_3D

#endif /* !FLAKKARI_SPHERECOLLIDER_HPP_ */
49 changes: 49 additions & 0 deletions Flakkari/Engine/EntityComponentSystem/Components/3D/Transform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
** EPITECH PROJECT, 2024
** Title: Flakkari
** Author: MasterLaplace
** Created: 2024-11-11
** File description:
** Transform
*/

#ifndef FLAKKARI_3D_TRANSFORM_HPP_
#define FLAKKARI_3D_TRANSFORM_HPP_

#include "../../../Math/Vector.hpp"

namespace Flakkari::Engine::ECS::Components::_3D {
LPL_PACKED_START

/**
* @brief Transform component for 3D entities
*/
struct Transform {
Math::Vector3f _position;
Math::Vector3f _scale;
Math::Vector3f _rotation;

Transform() : _position(0, 0, 0), _scale(1, 1, 1), _rotation(0, 0, 0) {};
Transform(const Math::Vector2f &position, const Math::Vector2f &scale, const Math::Vector3f &rotation)
: _position(position), _scale(scale), _rotation(rotation) {};
Transform(const Transform &other) : _position(other._position), _scale(other._scale), _rotation(other._rotation) {};

Transform &operator=(const Transform &other)
{
if (this != &other)
{
_position = other._position;
_scale = other._scale;
_rotation = other._rotation;
}

return *this;
}

std::size_t size() const { return sizeof(*this); }
};

LPL_PACKED_END
} // namespace Flakkari::Engine::ECS::Components::_3D

#endif /* !FLAKKARI_3D_TRANSFORM_HPP_ */

0 comments on commit 461fad0

Please sign in to comment.