From 3beeeebc1da4a270d1438ce2cbefa543c44ca84a Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 Mar 2019 18:59:18 +0100 Subject: [PATCH 1/5] Physics2D/RigidBody: Add position offset --- .../NDK/Components/CollisionComponent2D.hpp | 6 ++ .../NDK/Components/CollisionComponent2D.inl | 10 --- .../NDK/Components/CollisionComponent2D.cpp | 67 +++++++++++++++---- include/Nazara/Physics2D/RigidBody2D.hpp | 5 +- include/Nazara/Physics2D/RigidBody2D.inl | 5 ++ src/Nazara/Physics2D/RigidBody2D.cpp | 22 ++++-- 6 files changed, 86 insertions(+), 29 deletions(-) diff --git a/SDK/include/NDK/Components/CollisionComponent2D.hpp b/SDK/include/NDK/Components/CollisionComponent2D.hpp index aecdc5197..140846d62 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.hpp +++ b/SDK/include/NDK/Components/CollisionComponent2D.hpp @@ -28,10 +28,14 @@ namespace Ndk CollisionComponent2D(const CollisionComponent2D& collision); ~CollisionComponent2D() = default; + void Align(const Nz::Rectf& aabb); + Nz::Rectf GetAABB() const; const Nz::Collider2DRef& GetGeom() const; + const Nz::Vector2f& GetGeomOffset() const; void SetGeom(Nz::Collider2DRef geom); + void SetGeomOffset(const Nz::Vector2f& geomOffset); CollisionComponent2D& operator=(Nz::Collider2DRef geom); CollisionComponent2D& operator=(CollisionComponent2D&& collision) = default; @@ -40,6 +44,8 @@ namespace Ndk private: void InitializeStaticBody(); + Nz::RigidBody2D* GetRigidBody(); + const Nz::RigidBody2D* GetRigidBody() const; Nz::RigidBody2D* GetStaticBody(); void OnAttached() override; diff --git a/SDK/include/NDK/Components/CollisionComponent2D.inl b/SDK/include/NDK/Components/CollisionComponent2D.inl index b85fe3017..010780443 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.inl +++ b/SDK/include/NDK/Components/CollisionComponent2D.inl @@ -28,16 +28,6 @@ namespace Ndk { } - /*! - * \brief Gets the collision box representing the entity - * \return The physics collision box - */ - - inline Nz::Rectf CollisionComponent2D::GetAABB() const - { - return m_staticBody->GetAABB(); - } - /*! * \brief Gets the geometry representing the entity * \return A constant reference to the physics geometry diff --git a/SDK/src/NDK/Components/CollisionComponent2D.cpp b/SDK/src/NDK/Components/CollisionComponent2D.cpp index 5cdfd1589..84582c261 100644 --- a/SDK/src/NDK/Components/CollisionComponent2D.cpp +++ b/SDK/src/NDK/Components/CollisionComponent2D.cpp @@ -17,28 +17,41 @@ namespace Ndk * \brief NDK class that represents a two-dimensional collision geometry */ + void CollisionComponent2D::Align(const Nz::Rectf& aabb) + { + const Nz::RigidBody2D* rigidBody = GetRigidBody(); + SetGeomOffset(aabb.GetCenter() - rigidBody->GetAABB().GetCenter() + rigidBody->GetPositionOffset()); + } + + /*! + * \brief Gets the collision box representing the entity + * \return The physics collision box + */ + Nz::Rectf CollisionComponent2D::GetAABB() const + { + return GetRigidBody()->GetAABB(); + } + + const Nz::Vector2f& CollisionComponent2D::GetGeomOffset() const + { + return GetRigidBody()->GetPositionOffset(); + } + /*! * \brief Sets geometry for the entity * * \param geom Geometry used for collisions - * - * \remark Produces a NazaraAssert if the entity has no physics component and has no static body */ void CollisionComponent2D::SetGeom(Nz::Collider2DRef geom) { m_geom = std::move(geom); - if (m_entity->HasComponent()) - { - // We update the geometry of the PhysiscsObject linked to the PhysicsComponent2D - PhysicsComponent2D& physComponent = m_entity->GetComponent(); - physComponent.GetRigidBody()->SetGeom(m_geom); - } - else - { - NazaraAssert(m_staticBody, "An entity without physics component should have a static body"); - m_staticBody->SetGeom(m_geom); - } + GetRigidBody()->SetGeom(m_geom); + } + + void CollisionComponent2D::SetGeomOffset(const Nz::Vector2f& geomOffset) + { + GetRigidBody()->SetPositionOffset(geomOffset); } /*! @@ -47,7 +60,6 @@ namespace Ndk * \remark Produces a NazaraAssert if entity is invalid * \remark Produces a NazaraAssert if entity is not linked to a world, or the world has no physics system */ - void CollisionComponent2D::InitializeStaticBody() { NazaraAssert(m_entity, "Invalid entity"); @@ -67,7 +79,34 @@ namespace Ndk matrix.MakeIdentity(); m_staticBody->SetPosition(Nz::Vector2f(matrix.GetTranslation())); + } + Nz::RigidBody2D* CollisionComponent2D::GetRigidBody() + { + if (m_entity->HasComponent()) + { + PhysicsComponent2D& physComponent = m_entity->GetComponent(); + return physComponent.GetRigidBody(); + } + else + { + NazaraAssert(m_staticBody, "An entity without physics component should have a static body"); + return m_staticBody.get(); + } + } + + const Nz::RigidBody2D* CollisionComponent2D::GetRigidBody() const + { + if (m_entity->HasComponent()) + { + PhysicsComponent2D& physComponent = m_entity->GetComponent(); + return physComponent.GetRigidBody(); + } + else + { + NazaraAssert(m_staticBody, "An entity without physics component should have a static body"); + return m_staticBody.get(); + } } /*! diff --git a/include/Nazara/Physics2D/RigidBody2D.hpp b/include/Nazara/Physics2D/RigidBody2D.hpp index be90acc92..bc40ef9c0 100644 --- a/include/Nazara/Physics2D/RigidBody2D.hpp +++ b/include/Nazara/Physics2D/RigidBody2D.hpp @@ -32,7 +32,7 @@ namespace Nz RigidBody2D(PhysWorld2D* world, float mass); RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom); RigidBody2D(const RigidBody2D& object); - RigidBody2D(RigidBody2D&& object); + RigidBody2D(RigidBody2D&& object) noexcept; ~RigidBody2D(); void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys_Global); @@ -60,6 +60,7 @@ namespace Nz Vector2f GetMassCenter(CoordSys coordSys = CoordSys_Local) const; float GetMomentOfInertia() const; Vector2f GetPosition() const; + inline const Vector2f& GetPositionOffset() const; RadianAnglef GetRotation() const; inline std::size_t GetShapeCount() const; std::size_t GetShapeIndex(cpShape* shape) const; @@ -87,6 +88,7 @@ namespace Nz void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys_Local); void SetMomentOfInertia(float moment); void SetPosition(const Vector2f& position); + void SetPositionOffset(const Vector2f& offset); void SetRotation(const RadianAnglef& rotation); void SetSurfaceVelocity(const Vector2f& surfaceVelocity); void SetSurfaceVelocity(std::size_t shapeIndex, const Vector2f& surfaceVelocity); @@ -114,6 +116,7 @@ namespace Nz static void CopyBodyData(cpBody* from, cpBody* to); static void CopyShapeData(cpShape* from, cpShape* to); + Vector2f m_positionOffset; VelocityFunc m_velocityFunc; std::vector m_shapes; Collider2DRef m_geom; diff --git a/include/Nazara/Physics2D/RigidBody2D.inl b/include/Nazara/Physics2D/RigidBody2D.inl index a654c03e7..272c8fe30 100644 --- a/include/Nazara/Physics2D/RigidBody2D.inl +++ b/include/Nazara/Physics2D/RigidBody2D.inl @@ -17,6 +17,11 @@ namespace Nz return GetMassCenter(coordSys); } + inline const Vector2f& RigidBody2D::GetPositionOffset() const + { + return m_positionOffset; + } + inline std::size_t RigidBody2D::GetShapeCount() const { return m_shapes.size(); diff --git a/src/Nazara/Physics2D/RigidBody2D.cpp b/src/Nazara/Physics2D/RigidBody2D.cpp index cc181930f..a4876a1e6 100644 --- a/src/Nazara/Physics2D/RigidBody2D.cpp +++ b/src/Nazara/Physics2D/RigidBody2D.cpp @@ -19,6 +19,7 @@ namespace Nz } RigidBody2D::RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom) : + m_positionOffset(Vector2f::Zero()), m_geom(), m_userData(nullptr), m_world(world), @@ -35,6 +36,7 @@ namespace Nz } RigidBody2D::RigidBody2D(const RigidBody2D& object) : + m_positionOffset(object.m_positionOffset), m_geom(object.m_geom), m_userData(object.m_userData), m_world(object.m_world), @@ -59,9 +61,10 @@ namespace Nz } } - RigidBody2D::RigidBody2D(RigidBody2D&& object) : + RigidBody2D::RigidBody2D(RigidBody2D&& object) noexcept : OnRigidBody2DMove(std::move(object.OnRigidBody2DMove)), OnRigidBody2DRelease(std::move(object.OnRigidBody2DRelease)), + m_positionOffset(std::move(object.m_positionOffset)), m_shapes(std::move(object.m_shapes)), m_geom(std::move(object.m_geom)), m_handle(object.m_handle), @@ -260,7 +263,7 @@ namespace Nz Vector2f RigidBody2D::GetPosition() const { - cpVect pos = cpBodyGetPosition(m_handle); + cpVect pos = cpBodyLocalToWorld(m_handle, cpv(-m_positionOffset.x, -m_positionOffset.y)); return Vector2f(static_cast(pos.x), static_cast(pos.y)); } @@ -467,7 +470,9 @@ namespace Nz void RigidBody2D::SetPosition(const Vector2f& position) { - cpBodySetPosition(m_handle, cpv(position.x, position.y)); + cpVect oldPosition = cpBodyGetPosition(m_handle); + + cpBodySetPosition(m_handle, cpBodyLocalToWorld(m_handle, cpv(position.x - oldPosition.x + m_positionOffset.x, position.y - oldPosition.y + m_positionOffset.y))); if (m_isStatic) { m_world->RegisterPostStep(this, [](Nz::RigidBody2D* body) @@ -477,6 +482,13 @@ namespace Nz } } + void RigidBody2D::SetPositionOffset(const Vector2f& offset) + { + Nz::Vector2f position = GetPosition(); + m_positionOffset = offset; + SetPosition(position); + } + void RigidBody2D::SetRotation(const RadianAnglef& rotation) { cpBodySetAngle(m_handle, rotation.value); @@ -573,6 +585,7 @@ namespace Nz m_geom = std::move(object.m_geom); m_gravityFactor = object.m_gravityFactor; m_mass = object.m_mass; + m_positionOffset = object.m_positionOffset; m_shapes = std::move(object.m_shapes); m_userData = object.m_userData; m_velocityFunc = std::move(object.m_velocityFunc); @@ -653,9 +666,10 @@ namespace Nz void RigidBody2D::CopyBodyData(cpBody* from, cpBody* to) { + cpBodySetCenterOfGravity(to, cpBodyGetCenterOfGravity(from)); + cpBodySetAngle(to, cpBodyGetAngle(from)); cpBodySetAngularVelocity(to, cpBodyGetAngularVelocity(from)); - cpBodySetCenterOfGravity(to, cpBodyGetCenterOfGravity(from)); cpBodySetForce(to, cpBodyGetForce(from)); cpBodySetPosition(to, cpBodyGetPosition(from)); cpBodySetTorque(to, cpBodyGetTorque(from)); From 59dffe1a7bab7b2d2e818fc0adef78cca7c53f11 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 Mar 2019 21:02:31 +0100 Subject: [PATCH 2/5] CollisionComponent2D: Rename Align to Center (and make it take a vector) --- .../NDK/Components/CollisionComponent2D.hpp | 4 +-- .../NDK/Components/CollisionComponent2D.cpp | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/SDK/include/NDK/Components/CollisionComponent2D.hpp b/SDK/include/NDK/Components/CollisionComponent2D.hpp index 140846d62..ef8043629 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.hpp +++ b/SDK/include/NDK/Components/CollisionComponent2D.hpp @@ -28,12 +28,12 @@ namespace Ndk CollisionComponent2D(const CollisionComponent2D& collision); ~CollisionComponent2D() = default; - void Align(const Nz::Rectf& aabb); - Nz::Rectf GetAABB() const; const Nz::Collider2DRef& GetGeom() const; const Nz::Vector2f& GetGeomOffset() const; + void Recenter(const Nz::Vector2f& origin); + void SetGeom(Nz::Collider2DRef geom); void SetGeomOffset(const Nz::Vector2f& geomOffset); diff --git a/SDK/src/NDK/Components/CollisionComponent2D.cpp b/SDK/src/NDK/Components/CollisionComponent2D.cpp index 84582c261..fddbe8842 100644 --- a/SDK/src/NDK/Components/CollisionComponent2D.cpp +++ b/SDK/src/NDK/Components/CollisionComponent2D.cpp @@ -17,12 +17,6 @@ namespace Ndk * \brief NDK class that represents a two-dimensional collision geometry */ - void CollisionComponent2D::Align(const Nz::Rectf& aabb) - { - const Nz::RigidBody2D* rigidBody = GetRigidBody(); - SetGeomOffset(aabb.GetCenter() - rigidBody->GetAABB().GetCenter() + rigidBody->GetPositionOffset()); - } - /*! * \brief Gets the collision box representing the entity * \return The physics collision box @@ -32,11 +26,28 @@ namespace Ndk return GetRigidBody()->GetAABB(); } + /*! + * \brief Gets the position offset between the actual rigid body center of mass position and the origin of the geometry + * \return Position offset + */ const Nz::Vector2f& CollisionComponent2D::GetGeomOffset() const { return GetRigidBody()->GetPositionOffset(); } + /*! + * \brief Convenience function to align center of geometry to a specific point + * + * \param geomOffset Position offset + * + * \remark This does not change the center of mass + */ + void CollisionComponent2D::Recenter(const Nz::Vector2f& origin) + { + const Nz::RigidBody2D* rigidBody = GetRigidBody(); + SetGeomOffset(origin - rigidBody->GetAABB().GetCenter() + rigidBody->GetPositionOffset()); + } + /*! * \brief Sets geometry for the entity * @@ -49,6 +60,11 @@ namespace Ndk GetRigidBody()->SetGeom(m_geom); } + /*! + * \brief Sets the position offset between the actual rigid body center of mass position and the origin of the geometry + * + * \param geomOffset Position offset + */ void CollisionComponent2D::SetGeomOffset(const Nz::Vector2f& geomOffset) { GetRigidBody()->SetPositionOffset(geomOffset); From ae20ad6b65606c989977b209da7e82f6ec90857c Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 Mar 2019 21:02:50 +0100 Subject: [PATCH 3/5] Sdk/DebugSystem: Take position offset into account --- SDK/src/NDK/Systems/DebugSystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SDK/src/NDK/Systems/DebugSystem.cpp b/SDK/src/NDK/Systems/DebugSystem.cpp index 21a184981..df429dd1d 100644 --- a/SDK/src/NDK/Systems/DebugSystem.cpp +++ b/SDK/src/NDK/Systems/DebugSystem.cpp @@ -232,11 +232,12 @@ namespace Ndk case DebugDraw::Collider2D: { const Nz::Boxf& obb = entityGfx.GetAABB(); + CollisionComponent2D& entityCollision2D = entity->GetComponent(); Nz::Vector3f origin; Nz::InstancedRenderableRef renderable = GenerateCollision2DMesh(entity, &origin); if (renderable) - entityGfx.Attach(renderable, Nz::Matrix4f::Translate(origin - entityNode.GetPosition()), DebugDrawOrder); + entityGfx.Attach(renderable, Nz::Matrix4f::Translate(origin - entityNode.GetPosition() + entityCollision2D.GetGeomOffset()), DebugDrawOrder); entityDebug.UpdateDebugRenderable(option, std::move(renderable)); break; From 4821eb14a7e27710129dbbe1dc27255666b2e10f Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 Mar 2019 22:01:10 +0100 Subject: [PATCH 4/5] Physics2D: Fix some last stuffs --- ChangeLog.md | 2 ++ .../NDK/Components/CollisionComponent2D.hpp | 4 +++- .../NDK/Components/CollisionComponent2D.inl | 10 +++++----- SDK/include/NDK/Systems/DebugSystem.hpp | 2 +- SDK/src/NDK/Components/PhysicsComponent2D.cpp | 11 ++++++++++- SDK/src/NDK/Systems/DebugSystem.cpp | 15 +++++++++------ SDK/src/NDK/Systems/PhysicsSystem2D.cpp | 8 +++----- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 44ab35911..d2c5b2d83 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -176,6 +176,7 @@ Nazara Engine: - ENet DisconnectLater now reflects libenet behavior (and is waiting for unreliable commands to be sent before disconnecting for good) - ⚠ Collider3D::ForEachPolygon now takes a void(Vector3f\*, std::size_t) callback (instead of void(float\*, std::size_t)) - Added Collider2D::ForEachPolygon method +- Added RigidBody::[Get|Set]PositionOffset allowing set an offset between body logic position and body physics position (center of mass position) Nazara Development Kit: - Added ImageWidget (#139) @@ -248,6 +249,7 @@ Nazara Development Kit: - Add missing `recomputeMoment` parameter to PhysicsComponent2D::SetMass - Added possibility of disabling synchronization between PhysicsComponent2D and NodeComponent - Fixed GraphicsComponent not invalidating render queue on material change (causing crashes or visual errors) +- Added CollisionComponent2D::SetGeomOffset and CollisionComponent2D::Recenter # 0.4: diff --git a/SDK/include/NDK/Components/CollisionComponent2D.hpp b/SDK/include/NDK/Components/CollisionComponent2D.hpp index ef8043629..a5da3b8c2 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.hpp +++ b/SDK/include/NDK/Components/CollisionComponent2D.hpp @@ -20,8 +20,9 @@ namespace Ndk class NDK_API CollisionComponent2D : public Component { - friend class PhysicsSystem2D; friend class ConstraintComponent2D; + friend class PhysicsComponent2D; + friend class PhysicsSystem2D; public: CollisionComponent2D(Nz::Collider2DRef geom = Nz::Collider2DRef()); @@ -47,6 +48,7 @@ namespace Ndk Nz::RigidBody2D* GetRigidBody(); const Nz::RigidBody2D* GetRigidBody() const; Nz::RigidBody2D* GetStaticBody(); + const Nz::RigidBody2D* GetStaticBody() const; void OnAttached() override; void OnComponentAttached(BaseComponent& component) override; diff --git a/SDK/include/NDK/Components/CollisionComponent2D.inl b/SDK/include/NDK/Components/CollisionComponent2D.inl index 010780443..1bc9f0978 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.inl +++ b/SDK/include/NDK/Components/CollisionComponent2D.inl @@ -52,13 +52,13 @@ namespace Ndk return *this; } - /*! - * \brief Gets the static body used by the entity - * \return A pointer to the entity - */ - inline Nz::RigidBody2D* CollisionComponent2D::GetStaticBody() { return m_staticBody.get(); } + + inline const Nz::RigidBody2D* CollisionComponent2D::GetStaticBody() const + { + return m_staticBody.get(); + } } diff --git a/SDK/include/NDK/Systems/DebugSystem.hpp b/SDK/include/NDK/Systems/DebugSystem.hpp index 0cb4839b7..362b59f32 100644 --- a/SDK/include/NDK/Systems/DebugSystem.hpp +++ b/SDK/include/NDK/Systems/DebugSystem.hpp @@ -26,7 +26,7 @@ namespace Ndk private: Nz::InstancedRenderableRef GenerateBox(Nz::Boxf box); - Nz::InstancedRenderableRef GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* origin); + Nz::InstancedRenderableRef GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* offset); Nz::InstancedRenderableRef GenerateCollision3DMesh(Entity* entity); Nz::MaterialRef GetCollisionMaterial(); diff --git a/SDK/src/NDK/Components/PhysicsComponent2D.cpp b/SDK/src/NDK/Components/PhysicsComponent2D.cpp index 62cd922a4..f9feaff6e 100644 --- a/SDK/src/NDK/Components/PhysicsComponent2D.cpp +++ b/SDK/src/NDK/Components/PhysicsComponent2D.cpp @@ -31,9 +31,17 @@ namespace Ndk Nz::PhysWorld2D& world = entityWorld->GetSystem().GetPhysWorld(); + Nz::Vector2f positionOffset; + Nz::Collider2DRef geom; if (m_entity->HasComponent()) - geom = m_entity->GetComponent().GetGeom(); + { + const CollisionComponent2D& entityCollision = m_entity->GetComponent(); + geom = entityCollision.GetGeom(); + positionOffset = entityCollision.GetStaticBody()->GetPositionOffset(); //< Calling GetGeomOffset would retrieve current component which is not yet initialized + } + else + positionOffset = Nz::Vector2f::Zero(); Nz::Matrix4f matrix; if (m_entity->HasComponent()) @@ -42,6 +50,7 @@ namespace Ndk matrix.MakeIdentity(); m_object = std::make_unique(&world, 1.f, geom); + m_object->SetPositionOffset(positionOffset); m_object->SetPosition(Nz::Vector2f(matrix.GetTranslation())); m_object->SetUserdata(reinterpret_cast(static_cast(m_entity->GetId()))); } diff --git a/SDK/src/NDK/Systems/DebugSystem.cpp b/SDK/src/NDK/Systems/DebugSystem.cpp index df429dd1d..54295f611 100644 --- a/SDK/src/NDK/Systems/DebugSystem.cpp +++ b/SDK/src/NDK/Systems/DebugSystem.cpp @@ -234,10 +234,10 @@ namespace Ndk const Nz::Boxf& obb = entityGfx.GetAABB(); CollisionComponent2D& entityCollision2D = entity->GetComponent(); - Nz::Vector3f origin; - Nz::InstancedRenderableRef renderable = GenerateCollision2DMesh(entity, &origin); + Nz::Vector3f offset; + Nz::InstancedRenderableRef renderable = GenerateCollision2DMesh(entity, &offset); if (renderable) - entityGfx.Attach(renderable, Nz::Matrix4f::Translate(origin - entityNode.GetPosition() + entityCollision2D.GetGeomOffset()), DebugDrawOrder); + entityGfx.Attach(renderable, Nz::Matrix4f::Translate(offset), DebugDrawOrder); entityDebug.UpdateDebugRenderable(option, std::move(renderable)); break; @@ -318,7 +318,7 @@ namespace Ndk return model; } - Nz::InstancedRenderableRef DebugSystem::GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* origin) + Nz::InstancedRenderableRef DebugSystem::GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* offset) { if (entity->HasComponent()) { @@ -375,9 +375,12 @@ namespace Ndk // Find center of mass if (entity->HasComponent()) - *origin = entity->GetComponent().GetMassCenter(Nz::CoordSys_Global); + { + const PhysicsComponent2D& entityPhys = entity->GetComponent(); + *offset = entityPhys.GetMassCenter(Nz::CoordSys_Global) - entityPhys.GetPosition(); // GetPosition already takes GetGeomOffset into account + } else - *origin = entity->GetComponent().GetPosition(Nz::CoordSys_Global); + *offset = entityCollision.GetGeomOffset(); return model; } diff --git a/SDK/src/NDK/Systems/PhysicsSystem2D.cpp b/SDK/src/NDK/Systems/PhysicsSystem2D.cpp index 6579bb1fb..dac509128 100644 --- a/SDK/src/NDK/Systems/PhysicsSystem2D.cpp +++ b/SDK/src/NDK/Systems/PhysicsSystem2D.cpp @@ -213,7 +213,7 @@ namespace Ndk Nz::Vector2f newPosition = Nz::Vector2f(node.GetPosition(Nz::CoordSys_Global)); // To move static objects and ensure their collisions, we have to specify them a velocity - // (/!\: the physical motor does not apply the speed on static objects) + // (/!\: the physical engine does not apply the speed on static objects) if (newPosition != oldPosition) { body->SetPosition(newPosition); @@ -222,8 +222,7 @@ namespace Ndk else body->SetVelocity(Nz::Vector2f::Zero()); -/* - if (newRotation != oldRotation) + /*if (newRotation != oldRotation) { Nz::Quaternionf transition = newRotation * oldRotation.GetConjugate(); Nz::EulerAnglesf angles = transition.ToEulerAngles(); @@ -235,8 +234,7 @@ namespace Ndk physObj->SetAngularVelocity(angularVelocity); } else - physObj->SetAngularVelocity(Nz::Vector3f::Zero()); -*/ + physObj->SetAngularVelocity(Nz::Vector3f::Zero());*/ } } From 4ff43f2f72ccc211198a105f6652ceadb26becf1 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 27 Mar 2019 23:10:37 +0100 Subject: [PATCH 5/5] Sdk/DebugSystem: Fix collision 2D offset --- SDK/src/NDK/Systems/DebugSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDK/src/NDK/Systems/DebugSystem.cpp b/SDK/src/NDK/Systems/DebugSystem.cpp index 54295f611..f2175e559 100644 --- a/SDK/src/NDK/Systems/DebugSystem.cpp +++ b/SDK/src/NDK/Systems/DebugSystem.cpp @@ -377,7 +377,7 @@ namespace Ndk if (entity->HasComponent()) { const PhysicsComponent2D& entityPhys = entity->GetComponent(); - *offset = entityPhys.GetMassCenter(Nz::CoordSys_Global) - entityPhys.GetPosition(); // GetPosition already takes GetGeomOffset into account + *offset = entityPhys.GetMassCenter(Nz::CoordSys_Local) + entityCollision.GetGeomOffset(); } else *offset = entityCollision.GetGeomOffset();