Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-engine-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
ccache-

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCUBOS_CORE_SAMPLES=ON -DCUBOS_ENGINE_SAMPLES=ON -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
run: cmake -B ${{github.workspace}}/build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_FLAGS="-Wno-c2y-extensions" -DCUBOS_CORE_SAMPLES=ON -DCUBOS_ENGINE_SAMPLES=ON -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
shell: bash

- name: CCache Prolog
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Hidden trait from hiding components on the inspector (#1526, **@R-Camacho**).
- Checkbox for showing components that are hidden by default in the entity inspector (#1526, **@R-Camacho**).
- Collider component (#1426, **@fallenatlas**).
- ColliderBundle that can add area behavior to the entity (#1426, **@fallenatlas**).
- Collider start and end intersection events (#1426, **@fallenatlas**).
- RigidBodyBundle and StaticBodyBundle which replace RigidBodyBundle (#1426, **@fallenatlas**).
- Methods to change mass and Infinite mass constant on Inertia and Mass components (#1426, **@fallenatlas**).

### Changed

- Made AccumulatedCorrection component private (#1426, **@fallenatlas**).

### Removed

### Fixed
Expand Down
7 changes: 6 additions & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ set(CUBOS_ENGINE_SOURCE
"src/collisions/plugin.cpp"
"src/collisions/interface/plugin.cpp"
"src/collisions/interface/colliding_with.cpp"
"src/collisions/interface/intersection_start.cpp"
"src/collisions/interface/intersection_end.cpp"
"src/collisions/interface/contact_manifold.cpp"
"src/collisions/interface/shapes/box.cpp"
"src/collisions/interface/raycast.cpp"
"src/collisions/interface/shapes/capsule.cpp"
"src/collisions/interface/shapes/voxel.cpp"
"src/collisions/interface/collision_layers.cpp"
"src/collisions/interface/collision_mask.cpp"
"src/collisions/interface/collider.cpp"
"src/collisions/interface/collider_aabb.cpp"
"src/collisions/interface/collider_bundle.cpp"
"src/collisions/broad_phase/plugin.cpp"
"src/collisions/broad_phase/sweep_and_prune.cpp"
"src/collisions/broad_phase/potentially_colliding_with.cpp"
"src/collisions/broad_phase/collision_group.cpp"
"src/collisions/narrow_phase/plugin.cpp"

"src/physics/plugin.cpp"
Expand All @@ -125,6 +128,8 @@ set(CUBOS_ENGINE_SOURCE
"src/physics/components/impulse.cpp"
"src/physics/components/angular_impulse.cpp"
"src/physics/components/physics_material.cpp"
"src/physics/components/rigid_body_bundle.cpp"
"src/physics/components/static_body_bundle.cpp"

"src/input/plugin.cpp"
"src/input/input.cpp"
Expand Down
66 changes: 66 additions & 0 deletions engine/include/cubos/engine/collisions/collider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/// @file
/// @brief Component @ref cubos::engine::CollisionMask.
/// @ingroup collisions-plugin

#pragma once

#include <cstdint>

#include <cubos/core/reflection/reflect.hpp>

#include <cubos/engine/api.hpp>

namespace cubos::engine
{
/// @brief Component that identifies an entity as the owner of a Collider. Works with a CollisionShape (added
/// separately).
///
/// Between intersecting colliders exist the relations:
/// @ref IntersectionStart.
/// @ref CollidingWith.
/// @ref IntersectionEnd.
///
/// @note Since these relations are created during the collision phase, any system that uses them must run
/// after the `collisionsTag`.
///
/// Next is an example of how to use the relations associated with Colliders:
///
/// @code{.cpp}
/// cubos.system("exited area")
/// .after(collisionsTag)
/// .call([](Query<Entity, Collider&, IntersectionEnd&, Entity, Collider&> query,
/// State& state) {
/// for (auto [ent1, collider1, intersectionEnd, ent2, collider2] : query)
/// {
/// if (collider1.isArea && collider2.isStatic) {
/// CUBOS_INFO("An area just stopped hitting a static collider. Disabling Area.");
/// collider1.isActive = false;
/// }
/// }
/// });
/// @endcode
///
/// @ingroup collisions-plugin
struct Collider
{
CUBOS_REFLECT;

/// @brief Whether the collider is an Area.
///
/// An area collider detects collisions with other Colliders, however, collision manifolds are not generated.
///
/// Cannot be changed after creation.
const bool isArea = false;

/// @brief Whether the Collider is Static.
///
/// Used when it does not move, or its movement is limited. Static Colliders do not collide with each other.
///
/// Cannot be changed after creation.
const bool isStatic = false;

/// @brief Identities if a collider is active. When a Collider is not active, no collisions will be detected
/// with it.
bool isActive = true;
};
} // namespace cubos::engine
41 changes: 41 additions & 0 deletions engine/include/cubos/engine/collisions/collider_bundle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// @file
/// @brief Component @ref cubos::engine::ColliderBundle.
/// @ingroup collisions-plugin

#pragma once

#include <cstdint>

#include <cubos/core/reflection/reflect.hpp>

#include <cubos/engine/api.hpp>

namespace cubos::engine
{
/// @brief Bundle that packs the components for a Collider entity.
///
/// Adds @ref Collider, @ref CollisionLayers and @ref CollisionMask.
///
/// A CollisionShape must be added separately.
///
/// @ingroup collisions-plugin
struct CUBOS_ENGINE_API ColliderBundle
{
CUBOS_REFLECT;

/// @brief Whether the @ref Collider is an Area.
bool isArea = false;

/// @brief Whether the @ref Collider is Static.
bool isStatic = false;

/// @brief Whether the collider is active.
bool isActive = true;

/// @brief Layers of the collider.
uint32_t layers = 0x00000001;

/// @brief Mask of layers which the collider can collide with.
uint32_t mask = 0x00000001;
};
} // namespace cubos::engine
23 changes: 23 additions & 0 deletions engine/include/cubos/engine/collisions/intersection_end.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// @file
/// @brief Relation @ref cubos::engine::IntersectionEnd.
/// @ingroup collisions-plugin

#pragma once

#include <glm/vec3.hpp>

#include <cubos/core/reflection/reflect.hpp>

#include <cubos/engine/api.hpp>

namespace cubos::engine
{
/// @brief Relation which identifies the frame when two entities stop colliding.
///
/// This relation becomes obsolete when observers support relations.
/// @ingroup collisions-plugin
struct CUBOS_ENGINE_API IntersectionEnd
{
CUBOS_REFLECT;
};
} // namespace cubos::engine
23 changes: 23 additions & 0 deletions engine/include/cubos/engine/collisions/intersection_start.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// @file
/// @brief Relation @ref cubos::engine::IntersectionStart.
/// @ingroup collisions-plugin

#pragma once

#include <glm/vec3.hpp>

#include <cubos/core/reflection/reflect.hpp>

#include <cubos/engine/api.hpp>

namespace cubos::engine
{
/// @brief Relation which identifies the frame when two entities start colliding.
///
/// This relation becomes obsolete when observers support relations.
/// @ingroup collisions-plugin
struct CUBOS_ENGINE_API IntersectionStart
{
CUBOS_REFLECT;
};
} // namespace cubos::engine
18 changes: 12 additions & 6 deletions engine/include/cubos/engine/collisions/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ namespace cubos::engine
/// @brief Adds collision detection to @b Cubos
///
/// ## Components
/// - @ref BoxCollisionShape - holds the box collision shape.
/// - @ref CapsuleCollisionShape - holds the capsule collision shape.
/// - @ref VoxelCollisionShape - holds the voxel collision shape.
/// - @ref BoxCollisionShape - holds a box collision shape for a Collider.
/// - @ref CapsuleCollisionShape - holds a capsule collision shape for a Collider.
/// - @ref VoxelCollisionShape - holds a voxel collision shape for a Collider.
/// - @ref ColliderAABB - holds collider AABB data.
/// - @ref CollisionLayers - holds the collision layers where the collider appears in.
/// - @ref CollisionMask - holds the mask of layers which the collider can collide with.
/// - @ref Collider - identifies an entity as the owner of a Collider and its settings.
///
/// ## Events
/// - @ref CollisionEvent - (TODO) emitted when a collision occurs.
/// - @ref TriggerEvent - (TODO) emitted when a trigger is entered or exited.
/// ## Bundles
/// - @ref ColliderBundle - contains all the necessary components for an entity to have collision detection (A
/// CollisionShape must be added separately).
///
/// ## Relations
/// - @ref IntersectionStart - Relates entities during the frame when two entities start colliding.
/// - @ref CollidingWith - Relates entities while they are colliding.
/// - @ref IntersectionEnd - Relates entities during the frame when two entities stop colliding.
///
/// ## Dependencies
/// - @ref transform-plugin
Expand Down
4 changes: 4 additions & 0 deletions engine/include/cubos/engine/physics/components/inertia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ namespace cubos::engine
{
CUBOS_REFLECT;

static constexpr glm::mat3 INFINITE =
glm::mat3(std::numeric_limits<float>::infinity(), 0.0F, 0.0F, 0.0F, std::numeric_limits<float>::infinity(),
0.0F, 0.0F, 0.0F, std::numeric_limits<float>::infinity());

/// @brief The inertia tensor in local space.
glm::mat3 inertia;

Expand Down
12 changes: 12 additions & 0 deletions engine/include/cubos/engine/physics/components/mass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,21 @@ namespace cubos::engine
{
CUBOS_REFLECT;

/// @brief Represents infinite mass. A body with infinite mass does not move.
static constexpr float INFINITE = std::numeric_limits<float>::infinity();

float mass;
float inverseMass;

bool changed = true;

/// @brief Sets the mass
/// @param m The mass
void setMass(float m)
{
mass = m;
inverseMass = (mass == INFINITE) ? 0.0F : 1.0F / mass;
changed = true;
}
};
} // namespace cubos::engine
35 changes: 0 additions & 35 deletions engine/include/cubos/engine/physics/physics_bundle.hpp

This file was deleted.

7 changes: 4 additions & 3 deletions engine/include/cubos/engine/physics/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <cubos/core/reflection/external/glm.hpp>
#include <cubos/core/reflection/external/primitives.hpp>

#include <cubos/engine/physics/components/accumulated_correction.hpp>
#include <cubos/engine/physics/components/angular_impulse.hpp>
#include <cubos/engine/physics/components/angular_velocity.hpp>
#include <cubos/engine/physics/components/center_of_mass.hpp>
Expand All @@ -22,7 +21,6 @@
#include <cubos/engine/physics/components/physics_material.hpp>
#include <cubos/engine/physics/components/torque.hpp>
#include <cubos/engine/physics/components/velocity.hpp>
#include <cubos/engine/physics/physics_bundle.hpp>
#include <cubos/engine/physics/resources/damping.hpp>
#include <cubos/engine/physics/resources/solver_constants.hpp>
#include <cubos/engine/prelude.hpp>
Expand All @@ -40,8 +38,11 @@ namespace cubos::engine
/// - @ref Substeps - holds the amount of substeps for the physics update.
/// - @ref SolverConstants - holds the constants for the solver.
///
/// ## Bundles
/// - @ref RigidBodyBundle - encapsulates the creation all components required for a rigid body.
/// - @ref StaticBodyBundle - encapsulates the creation all components required for a static body.
///
/// ## Components
/// - @ref PhysicsBundle - bundle that holds the physics information to give to a new entity.
/// - @ref Velocity - holds the information for moving an object straight.
/// - @ref AngularVelocity - holds the angular velocity of an object.
/// - @ref Force - holds forces applied on a particle.
Expand Down
Loading
Loading