From 6ccf249b513a97dd58156b318ccd3ecadffd2a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <49535803+damacaa@users.noreply.github.com> Date: Fri, 20 Jun 2025 10:10:54 +0200 Subject: [PATCH 1/4] Collision ballback --- include/weird-engine/Scene.h | 15 ++-- include/weird-physics/Simulation2D.h | 85 ++++++++++-------- src/weird-engine/Scene.cpp | 26 +++--- src/weird-physics/Simulation2D.cpp | 125 ++++++++++----------------- 4 files changed, 111 insertions(+), 140 deletions(-) diff --git a/include/weird-engine/Scene.h b/include/weird-engine/Scene.h index a5df8c0..ae354c6 100644 --- a/include/weird-engine/Scene.h +++ b/include/weird-engine/Scene.h @@ -27,10 +27,10 @@ namespace WeirdEngine void get2DShapesData(WeirdRenderer::Dot2D*& data, uint32_t& size); - Scene(const Scene&) = default; // Deleted copy constructor + Scene(const Scene&) = default; // Deleted copy constructor Scene& operator=(const Scene&) = default; // Deleted copy assignment operator - Scene(Scene&&) = default; // Defaulted move constructor - Scene& operator=(Scene&&) = default; // Defaulted move assignment operator + Scene(Scene&&) = default; // Defaulted move constructor + Scene& operator=(Scene&&) = default; // Defaulted move assignment operator WeirdRenderer::Camera& getCamera(); std::vector& getLigths(); @@ -39,7 +39,7 @@ namespace WeirdEngine void fillShapeDataBuffer(WeirdRenderer::Dot2D*& data, uint32_t& size); - enum class RenderMode + enum class RenderMode { Simple3D, RayMarching3D, @@ -47,8 +47,6 @@ namespace WeirdEngine RayMarchingBoth }; - - RenderMode getRenderMode() const; protected: @@ -56,6 +54,7 @@ namespace WeirdEngine virtual void onStart() = 0; virtual void onUpdate(float delta) = 0; virtual void onRender(WeirdRenderer::RenderTarget& renderTarget) {}; + virtual void onCollision(WeirdEngine::CollisionEvent& event) {}; virtual void onDestroy() {}; ECSManager m_ecs; @@ -94,7 +93,6 @@ namespace WeirdEngine void loadFont(const char* imagePath, int charWidth, int charHeight, const char* characters); private: - // Char lookup table std::array m_CharLookUpTable{}; @@ -108,9 +106,10 @@ namespace WeirdEngine bool m_runSimulationInThread; - void updateCustomShapesShader(WeirdRenderer::Shader& shader); std::vector m_lights; + + static void Scene::handleCollision(WeirdEngine::CollisionEvent& event, void* userData); }; } \ No newline at end of file diff --git a/include/weird-physics/Simulation2D.h b/include/weird-physics/Simulation2D.h index a29bb1b..879f91e 100644 --- a/include/weird-physics/Simulation2D.h +++ b/include/weird-physics/Simulation2D.h @@ -1,34 +1,30 @@ #pragma once -#include - -#include "../weird-engine/ecs/Entity.h" -// #include "../weird-engine/ecs/ComponentArray.h" -#include "../weird-engine/ecs/Components/Transform.h" - -#include "../weird-engine/ecs/Components/CustomShape.h" - #include #include #include #include #include #include - -#include "CollisionDetection/UniformGrid2D.h" -#include "CollisionDetection/DynamicAABBTree2D.h" - -#include "CollisionDetection/SpatialHash.h" -#include "../weird-engine/Input.h" -#include "CollisionDetection/Octree.h" - #include #include #include #include + +#include #include -#include "../weird-engine/math/MathExpressions.h" +#include "weird-engine/ecs/Entity.h" +#include "weird-engine/ecs/Components/Transform.h" +#include "weird-engine/ecs/Components/CustomShape.h" +#include "weird-engine/Input.h" +#include "weird-engine/math/MathExpressions.h" + +#include "CollisionDetection/UniformGrid2D.h" +#include "CollisionDetection/DynamicAABBTree2D.h" +#include "CollisionDetection/SpatialHash.h" +#include "CollisionDetection/Octree.h" + namespace WeirdEngine { @@ -39,7 +35,6 @@ namespace WeirdEngine using vec2 = glm::vec2; - class CustomBitset { public: @@ -47,14 +42,16 @@ namespace WeirdEngine void set(SimulationID pos) { - if (pos < size) { + if (pos < size) + { bits[pos / 64] |= (1ULL << (pos % 64)); } } void clear(SimulationID pos) { - if (pos < size) { + if (pos < size) + { bits[pos / 64] &= ~(1ULL << (pos % 64)); } } @@ -73,13 +70,19 @@ namespace WeirdEngine size_t size; }; + struct CollisionEvent + { + SimulationID bodyA; + SimulationID bodyB; + // bool firstContact; TODO + }; - + // Define the function pointer type and include a user data pointer + using CollisionCallbackFn = void (*)(CollisionEvent&, void*); class Simulation2D { - public: Simulation2D(size_t size); ~Simulation2D(); @@ -92,7 +95,6 @@ namespace WeirdEngine void startSimulationThread(); void stopSimulationThread(); - void update(double delta); double getSimulationTime(); @@ -117,7 +119,6 @@ namespace WeirdEngine void updateTransform(Transform& transform, SimulationID id); void setMass(SimulationID id, float mass); - void setSDFs(std::vector>& sdfs); void updateShape(CustomShape& shape); @@ -136,30 +137,30 @@ namespace WeirdEngine void solveConstraints(); void step(float timeStep); - struct Collision { public: - Collision() { + Collision() + { A = -1; B = -1; AB = vec2(); } - - Collision(int a, int b, vec2 ab) { + Collision(SimulationID a, SimulationID b, vec2 ab) + { A = a; B = b; AB = ab; } - - bool operator==(const Collision& other) const { + bool operator==(const Collision& other) const + { return (A == other.A && B == other.B) || (A == other.B && B == other.A); } - int A; - int B; + SimulationID A; + SimulationID B; vec2 AB; }; @@ -199,7 +200,6 @@ namespace WeirdEngine Distance = 1.0f; } - DistanceConstraint(int a, int b, float distance) { A = a; @@ -222,7 +222,6 @@ namespace WeirdEngine g = 1.0f; } - GravitationalConstraint(int a, int b, float gravity) { A = a; @@ -235,8 +234,10 @@ namespace WeirdEngine float g; }; - struct CollisionHash { - std::size_t operator()(const Collision& s) const { + struct CollisionHash + { + std::size_t operator()(const Collision& s) const + { bool flip = s.A < s.B; int first = flip ? s.B : s.A; int last = flip ? s.A : s.B; @@ -251,7 +252,6 @@ namespace WeirdEngine MethodTree }; - struct DistanceFieldObject2D { Entity owner; @@ -325,6 +325,17 @@ namespace WeirdEngine bool m_attracttionEnabled = false; bool m_repulsionEnabled = false; bool m_liftEnabled = false; + + private: + CollisionCallbackFn m_collisionCallback = nullptr; + void* m_callbackUserData = nullptr; + + public: + void setCollisionCallback(CollisionCallbackFn callback, void* userData) + { + m_collisionCallback = callback; + m_callbackUserData = userData; + } }; } \ No newline at end of file diff --git a/src/weird-engine/Scene.cpp b/src/weird-engine/Scene.cpp index 3c7f965..e9f2c26 100644 --- a/src/weird-engine/Scene.cpp +++ b/src/weird-engine/Scene.cpp @@ -7,23 +7,21 @@ #include #include - namespace WeirdEngine { + + void Scene::handleCollision(WeirdEngine::CollisionEvent& event, void* userData) + { + // Unsafe cast! Prone to error. + Scene* self = static_cast(userData); + self->onCollision(event); + } + // vec3 g_cameraPosition(15.0f, 50.f, 60.0f); vec3 g_cameraPosition(0, 1, 20); Scene::Scene() - : m_simulation2D(MAX_ENTITIES) - , m_sdfRenderSystem(m_ecs) - , m_sdfRenderSystem2D(m_ecs) - , m_renderSystem(m_ecs) - , m_instancedRenderSystem(m_ecs) - , m_rbPhysicsSystem2D(m_ecs) - , m_physicsInteractionSystem(m_ecs) - , m_playerMovementSystem(m_ecs) - , m_cameraSystem(m_ecs) - , m_runSimulationInThread(true) + : m_simulation2D(MAX_ENTITIES), m_sdfRenderSystem(m_ecs), m_sdfRenderSystem2D(m_ecs), m_renderSystem(m_ecs), m_instancedRenderSystem(m_ecs), m_rbPhysicsSystem2D(m_ecs), m_physicsInteractionSystem(m_ecs), m_playerMovementSystem(m_ecs), m_cameraSystem(m_ecs), m_runSimulationInThread(true) { // Custom component managers @@ -44,6 +42,8 @@ namespace WeirdEngine { m_simulation2D.startSimulationThread(); } + + m_simulation2D.setCollisionCallback(&handleCollision, this); } Scene::~Scene() @@ -73,15 +73,13 @@ namespace WeirdEngine case WeirdEngine::Scene::RenderMode::RayMarching2D: { FlyMovement2D& fly = m_ecs.addComponent(m_mainCamera); - fly.targetPosition = g_cameraPosition; + // fly.targetPosition = g_cameraPosition; break; } default: break; } } - - } // TODO: pass render target instead of shader. Shaders should be accessed in a different way, through the resource manager diff --git a/src/weird-physics/Simulation2D.cpp b/src/weird-physics/Simulation2D.cpp index 25550d6..fde213b 100644 --- a/src/weird-physics/Simulation2D.cpp +++ b/src/weird-physics/Simulation2D.cpp @@ -3,10 +3,9 @@ namespace WeirdEngine { -#define MEASURE_PERFORMANCE false +#define MEASURE_PERFORMANCE false #define INTEGRATION_METHOD 1 - using namespace std::chrono; constexpr float SIMULATION_FREQUENCY = 250; @@ -19,10 +18,7 @@ namespace WeirdEngine std::mutex g_fixMutex; std::mutex g_collisionTreeUpdateMutex; - - - Simulation2D::Simulation2D(size_t size) : - m_isPaused(false), + Simulation2D::Simulation2D(size_t size) : m_isPaused(false), m_positions(new vec2[size]), m_previousPositions(new vec2[size]), m_velocities(new vec2[size]), @@ -86,7 +82,6 @@ namespace WeirdEngine return m_isPaused; } - #pragma region PhysicsUpdate void Simulation2D::update(double delta) @@ -136,7 +131,6 @@ namespace WeirdEngine m_simulationDelay -= FIXED_DELTA_TIME; } - #if MEASURE_PERFORMANCE // Get the ending time auto end = std::chrono::high_resolution_clock::now(); @@ -183,7 +177,6 @@ namespace WeirdEngine std::vector previousAABBs; std::vector previousAABBPositions; - void Simulation2D::checkCollisions() { // Detect collisions @@ -219,10 +212,10 @@ namespace WeirdEngine } break; } - case Simulation2D::MethodTree: + case Simulation2D::MethodTree: { - //std::lock_guard lock(g_collisionTreeUpdateMutex); + // std::lock_guard lock(g_collisionTreeUpdateMutex); // Add new objects for (size_t i = m_tree.count; i < m_size; i++) @@ -248,20 +241,19 @@ namespace WeirdEngine p.x - halfw, p.y - halfw, p.x + halfh, - p.y + halfh - ); + p.y + halfh); // Update the object in the tree m_tree.updateObject(m_treeIDs[i], updatedBox); // Optimization ideas // Lazy update: only update the tree if the object has moved significantly - //if (!previousAABBs[i].overlaps(updatedBox)) + // if (!previousAABBs[i].overlaps(updatedBox)) //{ // m_tree.updateObject(m_treeIDs[i], updatedBox); // previousAABBs[i] = updatedBox; //} - //else { + // else { // //std::cout << "Nope: " << i << std::endl; //} @@ -280,7 +272,6 @@ namespace WeirdEngine }*/ } - std::vector possibleCollisions; // Perform collision queries for (size_t i = 0; i < m_treeIDs.size(); ++i) @@ -293,7 +284,7 @@ namespace WeirdEngine { if (id != m_treeIDs[i] && m_tree.nodes[id].box.overlaps(m_tree.nodes[m_treeIDs[i]].box)) { - //std::cout << "Object " << m_treeIDs[i] << " is colliding with object " << id << std::endl; + // std::cout << "Object " << m_treeIDs[i] << " is colliding with object " << id << std::endl; int a = i; int b = m_treeIdToSimulationID[id]; @@ -317,7 +308,6 @@ namespace WeirdEngine } } - break; } default: @@ -330,11 +320,11 @@ namespace WeirdEngine #endif } - void Simulation2D::solveCollisionsPositionBased() { // Calculate forces - for (auto it = m_collisions.begin(); it != m_collisions.end(); ++it) { + for (auto it = m_collisions.begin(); it != m_collisions.end(); ++it) + { Collision col = *it; vec2 penetration = 0.5f * ((m_radious + m_radious) - length(col.AB)) * normalize(col.AB); @@ -343,15 +333,14 @@ namespace WeirdEngine } } - - - float Simulation2D::map(vec2 p) + float Simulation2D::map(vec2 p) { float d = 1.0f; for (DistanceFieldObject2D& obj : m_objects) { - if (obj.distanceFieldId >= m_sdfs->size()) { + if (obj.distanceFieldId >= m_sdfs->size()) + { continue; } @@ -366,7 +355,6 @@ namespace WeirdEngine d = std::min(d, dist); } - return d; } @@ -385,7 +373,6 @@ namespace WeirdEngine } } - // Attraction force if (m_attracttionEnabled) { @@ -397,7 +384,8 @@ namespace WeirdEngine float distanceSquared = (ij.x * ij.x) + (ij.y * ij.y); - if (distanceSquared > m_diameterSquared) { + if (distanceSquared > m_diameterSquared) + { vec2 attractionForce = (0.1f * (m_mass[i] * m_mass[j]) / distanceSquared) * normalize(ij); m_forces[i] += attractionForce; m_forces[j] -= attractionForce; @@ -416,7 +404,8 @@ namespace WeirdEngine float distanceSquared = (ij.x * ij.x) + (ij.y * ij.y); - if (distanceSquared > m_diameterSquared) { + if (distanceSquared > m_diameterSquared) + { vec2 attractionForce = -(0.1f * (m_mass[i] * m_mass[j]) / distanceSquared) * normalize(ij); m_forces[i] += attractionForce; m_forces[j] -= attractionForce; @@ -433,7 +422,6 @@ namespace WeirdEngine } } - // Sphere collisions for (auto it = m_collisions.begin(); it != m_collisions.end(); ++it) { @@ -443,13 +431,11 @@ namespace WeirdEngine vec2 normal = lengthSquared > 0.0f ? normalize(col.AB) : vec2(1.0f); float penetration = (m_radious + m_radious) - length(col.AB); - // Position + // Position /*vec2 translation = 0.5f * penetration * normal; m_positions[col.A] -= translation; m_positions[col.B] += translation;*/ - - // Impulse method float restitution = 0.5f; vec2 vRel = m_velocities[col.B] - m_velocities[col.A]; @@ -460,25 +446,25 @@ namespace WeirdEngine m_velocities[col.A] -= m_invMass[col.A] * impulse; m_velocities[col.B] += m_invMass[col.B] * impulse; - // Penalty method vec2 penalty = m_push * penetration * normal; m_forces[col.A] -= m_mass[col.A] * penalty; m_forces[col.B] += m_mass[col.B] * penalty; + // Notify collision callback + if (m_collisionCallback) + m_collisionCallback(CollisionEvent{ col.A, col.B }, m_callbackUserData); #if MEASURE_PERFORMANCE g_collisionCount++; #endif } - - // Apply extra forces for (size_t i = 0; i < m_size; i++) { vec2& p = m_positions[i]; - //vec2& force = m_forces[i]; + // vec2& force = m_forces[i]; // Gravity if (!m_attracttionEnabled) @@ -503,37 +489,34 @@ namespace WeirdEngine // Position p += penetration * normal; - // Impulse float restitution = 0.5f; vec2 vRel = -m_velocities[i]; float velocityAlongNormal = glm::dot(normal, vRel); - float impulseMagnitude = -(1 + restitution) * velocityAlongNormal; // * m_mass[i]; -> cancels out later + float impulseMagnitude = -(1 + restitution) * velocityAlongNormal; // * m_mass[i]; -> cancels out later vec2 impulse = impulseMagnitude * normal; - //m_velocities[i] -= impulse; // * m_invMass[i] - + // m_velocities[i] -= impulse; // * m_invMass[i] // Penalty vec2 v = penetration * normal; vec2 force = m_mass[i] * m_push * v; - //force -= (10000.0f * m_damping * m_velocities[i]); // Drag ??? + // force -= (10000.0f * m_damping * m_velocities[i]); // Drag ??? m_forces[i] += force; - } - - // Old walls if (Input::GetKey(Input::R)) { - if (p.x < m_radious) { + if (p.x < m_radious) + { p.x += m_radious - p.x; m_velocities[i].x = -0.5f * m_velocities[i].x; } - else if (p.x > 30.0f - m_radious) { + else if (p.x > 30.0f - m_radious) + { p.x -= m_radious - (30.0f - p.x); m_velocities[i].x = -0.5f * m_velocities[i].x; } @@ -551,7 +534,7 @@ namespace WeirdEngine vec2 n = normalize(v); float distance = length(v); float d = spring.Distance - distance; - //d = std::clamp(d, -10.0f, 10.0f); + // d = std::clamp(d, -10.0f, 10.0f); vec2 springForce = 0.5f * spring.K * d * n; vec2 damping = spring.Damping * (m_velocities[spring.B] - m_velocities[spring.A]); @@ -590,8 +573,6 @@ namespace WeirdEngine float f = constraint.g * (m_mass[constraint.A] * m_mass[constraint.B]) / (distance * distance); - - m_forces[constraint.A] += f * n; m_forces[constraint.B] -= f * n; } @@ -609,13 +590,11 @@ namespace WeirdEngine } } - - void Simulation2D::step(float timeStep) { #if INTEGRATION_METHOD == 0 - //Integrate with euler + // Integrate with euler for (size_t i = 0; i < m_size; i++) { vec2 acc = m_forces[i] * m_invMass[i]; @@ -624,12 +603,11 @@ namespace WeirdEngine // Reset forces m_forces[i] = vec2(0.0f); - } #elif INTEGRATION_METHOD == 1 - //Integrate with verlet + // Integrate with verlet float invTimeStep = 1.0f / timeStep; for (size_t i = 0; i < m_size; i++) { @@ -654,15 +632,13 @@ namespace WeirdEngine } #endif - } #pragma endregion - SimulationID Simulation2D::generateSimulationID() { - //std::cout << (m_lastIdGiven + 1) << std::endl; + // std::cout << (m_lastIdGiven + 1) << std::endl; return ++m_lastIdGiven; } @@ -679,7 +655,6 @@ namespace WeirdEngine m_forces[toId] = m_forces[fromId]; m_externalForces[toId] = m_externalForces[fromId]; - // Fix constraints (potentially slow...) // Remove constraints that affect deleted object @@ -692,10 +667,8 @@ namespace WeirdEngine { return true; } - return false; - }), - container.end() - ); + return false; }), + container.end()); }; RemoveByID(m_springs); @@ -705,7 +678,6 @@ namespace WeirdEngine // Remove all occurrences deleted id m_fixedObjects.erase(std::remove(m_fixedObjects.begin(), m_fixedObjects.end(), toId), m_fixedObjects.end()); - // If a constraint targeted the moved object, change it to its new id auto ChangeByID = [fromId, toId](auto& container) { @@ -730,18 +702,17 @@ namespace WeirdEngine ChangeByID(m_distanceConstraints); ChangeByID(m_gravitationalConstraints); - // Find if moved object is fixed auto it = std::find(m_fixedObjects.begin(), m_fixedObjects.end(), fromId); // If it is, fix it at its new id - if (it != m_fixedObjects.end()) { + if (it != m_fixedObjects.end()) + { // Compute the index by subtracting the beginning iterator int index = it - m_fixedObjects.begin(); m_fixedObjects[index] = toId; } - // Adjust size m_lastIdGiven--; m_size--; @@ -752,7 +723,6 @@ namespace WeirdEngine return m_size; } - void Simulation2D::addForce(SimulationID id, vec2 force) { std::lock_guard lock(g_externalForcesMutex); @@ -799,10 +769,9 @@ namespace WeirdEngine m_fixedObjects.erase(std::remove(m_fixedObjects.begin(), m_fixedObjects.end(), id), m_fixedObjects.end()); } - vec2 Simulation2D::getPosition(SimulationID entity) { - return m_positions[entity]; + return m_positions[entity]; } void Simulation2D::setPosition(SimulationID id, vec2 pos) @@ -811,7 +780,7 @@ namespace WeirdEngine m_positions[id] = pos; m_previousPositions[id] = pos; m_velocities[id] = vec2(0.0f); - //m_forces[entity] = vec2(0.0f); + // m_forces[entity] = vec2(0.0f); m_size = std::max((uint32_t)m_size, id + 1); } @@ -832,8 +801,6 @@ namespace WeirdEngine m_sdfs = std::make_shared>>(sdfs); } - - void Simulation2D::updateShape(CustomShape& shape) { if (shape.m_screenSpace) @@ -843,12 +810,14 @@ namespace WeirdEngine // Check if the key exists auto it = m_entityToObjectsIdx.find(shape.Owner); - if (it != m_entityToObjectsIdx.end()) { + if (it != m_entityToObjectsIdx.end()) + { // Key exists, get the value auto id = it->second; m_objects[id] = sdf; } - else { + else + { // Key does not exist m_objects.push_back(sdf); m_entityToObjectsIdx[shape.Owner] = m_objects.size() - 1; @@ -884,7 +853,6 @@ namespace WeirdEngine m_entityToObjectsIdx.erase(shape.Owner); } - SimulationID Simulation2D::raycast(vec2 pos) { if (m_collisionDetectionMethod == None || m_collisionDetectionMethod == MethodNaive) @@ -901,8 +869,6 @@ namespace WeirdEngine { return i; } - - } return -1; @@ -913,7 +879,7 @@ namespace WeirdEngine std::lock_guard lock(g_collisionTreeUpdateMutex); AABB boundinBox(pos.x - size, pos.y - size, pos.x + size, pos.y + size); std::vector possibleCollisions; - //possibleCollisions.reserve(3); + // possibleCollisions.reserve(3); m_tree.query(boundinBox, possibleCollisions); if (possibleCollisions.size() == 0) @@ -923,9 +889,6 @@ namespace WeirdEngine } } - - - void Simulation2D::runSimulationThread() { while (m_simulating) From d4f63e126c1c50a1a289668d68987a15b4011728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <49535803+damacaa@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:12:36 +0200 Subject: [PATCH 2/4] Removed extra qualification --- include/weird-engine/Scene.h | 2 +- src/weird-engine/Scene.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/weird-engine/Scene.h b/include/weird-engine/Scene.h index ae354c6..e0c85d1 100644 --- a/include/weird-engine/Scene.h +++ b/include/weird-engine/Scene.h @@ -110,6 +110,6 @@ namespace WeirdEngine std::vector m_lights; - static void Scene::handleCollision(WeirdEngine::CollisionEvent& event, void* userData); + static void Scene::handleCollision(CollisionEvent& event, void* userData); }; } \ No newline at end of file diff --git a/src/weird-engine/Scene.cpp b/src/weird-engine/Scene.cpp index e9f2c26..3f75385 100644 --- a/src/weird-engine/Scene.cpp +++ b/src/weird-engine/Scene.cpp @@ -10,7 +10,7 @@ namespace WeirdEngine { - void Scene::handleCollision(WeirdEngine::CollisionEvent& event, void* userData) + void Scene::handleCollision(CollisionEvent &event, void *userData) { // Unsafe cast! Prone to error. Scene* self = static_cast(userData); From c4b7fc9d0a06d8d2d87ed813f29734be4d590fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <49535803+damacaa@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:19:41 +0200 Subject: [PATCH 3/4] Update Scene.h --- include/weird-engine/Scene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/weird-engine/Scene.h b/include/weird-engine/Scene.h index e0c85d1..0a33040 100644 --- a/include/weird-engine/Scene.h +++ b/include/weird-engine/Scene.h @@ -110,6 +110,6 @@ namespace WeirdEngine std::vector m_lights; - static void Scene::handleCollision(CollisionEvent& event, void* userData); + static void handleCollision(CollisionEvent& event, void* userData); }; } \ No newline at end of file From 15ebd24297da2d765ea02243921ae6747760a684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <49535803+damacaa@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:40:10 +0200 Subject: [PATCH 4/4] Update Simulation2D.cpp --- src/weird-physics/Simulation2D.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/weird-physics/Simulation2D.cpp b/src/weird-physics/Simulation2D.cpp index fde213b..179d399 100644 --- a/src/weird-physics/Simulation2D.cpp +++ b/src/weird-physics/Simulation2D.cpp @@ -452,8 +452,11 @@ namespace WeirdEngine m_forces[col.B] += m_mass[col.B] * penalty; // Notify collision callback - if (m_collisionCallback) - m_collisionCallback(CollisionEvent{ col.A, col.B }, m_callbackUserData); + if (m_collisionCallback) + { + CollisionEvent event{ col.A, col.B }; + m_collisionCallback(event, m_callbackUserData); + } #if MEASURE_PERFORMANCE g_collisionCount++;