Merge branch 'master' into physics3d-material
This commit is contained in:
@@ -17,5 +17,6 @@
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Components/ConstraintComponent2D.hpp>
|
||||
|
||||
#endif // NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Ndk
|
||||
class NDK_API CollisionComponent2D : public Component<CollisionComponent2D>
|
||||
{
|
||||
friend class PhysicsSystem2D;
|
||||
friend class ConstraintComponent2D;
|
||||
|
||||
public:
|
||||
CollisionComponent2D(Nz::Collider2DRef geom = Nz::Collider2DRef());
|
||||
|
||||
34
SDK/include/NDK/Components/ConstraintComponent2D.hpp
Normal file
34
SDK/include/NDK/Components/ConstraintComponent2D.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
|
||||
#define NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
|
||||
|
||||
#include <NDK/Component.hpp>
|
||||
#include <Nazara/Physics2D/Constraint2D.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API ConstraintComponent2D : public Component<ConstraintComponent2D>
|
||||
{
|
||||
public:
|
||||
ConstraintComponent2D() = default;
|
||||
ConstraintComponent2D(const ConstraintComponent2D& joint) = default;
|
||||
ConstraintComponent2D(ConstraintComponent2D&& joint) = default;
|
||||
|
||||
template<typename T, typename... Args> inline Nz::ObjectRef<T> CreateConstraint(const Ndk::EntityHandle& first, const Ndk::EntityHandle& second, Args&&... args);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Nz::Constraint2DRef> m_constraints;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <NDK/Components/ConstraintComponent2D.inl>
|
||||
|
||||
#endif// NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
|
||||
31
SDK/include/NDK/Components/ConstraintComponent2D.inl
Normal file
31
SDK/include/NDK/Components/ConstraintComponent2D.inl
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <NDK/Components/ConstraintComponent2D.hpp>
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
#include <NDK/Components/CollisionComponent2D.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
template<typename T, typename ...Args>
|
||||
Nz::ObjectRef<T> ConstraintComponent2D::CreateConstraint(const Ndk::EntityHandle& first, const Ndk::EntityHandle& second, Args && ...args)
|
||||
{
|
||||
auto FetchBody = [](const Ndk::EntityHandle& entity) -> Nz::RigidBody2D*
|
||||
{
|
||||
if (entity->HasComponent<Ndk::PhysicsComponent2D>())
|
||||
return entity->GetComponent<Ndk::PhysicsComponent2D>().GetRigidBody();
|
||||
else if (entity->HasComponent<Ndk::CollisionComponent2D>())
|
||||
return entity->GetComponent<Ndk::CollisionComponent2D>().GetStaticBody();
|
||||
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
Nz::RigidBody2D* firstBody = FetchBody(first);
|
||||
NazaraAssert(firstBody, "First entity has no CollisionComponent2D nor PhysicsComponent2D component");
|
||||
|
||||
Nz::RigidBody2D* secondBody = FetchBody(second);
|
||||
NazaraAssert(secondBody, "Second entity has no CollisionComponent2D nor PhysicsComponent2D component");
|
||||
|
||||
Nz::ObjectRef<T> constraint = T::New(*firstBody, *secondBody, std::forward<Args>(args)...);
|
||||
m_constraints.push_back(constraint);
|
||||
|
||||
return constraint;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace Ndk
|
||||
{
|
||||
friend class CollisionComponent2D;
|
||||
friend class PhysicsSystem2D;
|
||||
friend class ConstraintComponent2D;
|
||||
|
||||
public:
|
||||
PhysicsComponent2D() = default;
|
||||
@@ -49,7 +50,7 @@ namespace Ndk
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
Nz::RigidBody2D& GetRigidBody();
|
||||
Nz::RigidBody2D* GetRigidBody();
|
||||
|
||||
void OnAttached() override;
|
||||
void OnComponentAttached(BaseComponent& component) override;
|
||||
|
||||
@@ -307,8 +307,8 @@ namespace Ndk
|
||||
* \return A reference to the physics object
|
||||
*/
|
||||
|
||||
inline Nz::RigidBody2D& PhysicsComponent2D::GetRigidBody()
|
||||
inline Nz::RigidBody2D* PhysicsComponent2D::GetRigidBody()
|
||||
{
|
||||
return *m_object.get();
|
||||
return m_object.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Ndk
|
||||
private:
|
||||
void ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const;
|
||||
void CopyPhysicsState(const Nz::RigidBody3D& rigidBody);
|
||||
Nz::RigidBody3D& GetRigidBody();
|
||||
Nz::RigidBody3D* GetRigidBody();
|
||||
const Nz::RigidBody3D& GetRigidBody() const;
|
||||
|
||||
void OnAttached() override;
|
||||
|
||||
@@ -488,9 +488,9 @@ namespace Ndk
|
||||
* \brief Gets the underlying physics object
|
||||
* \return A reference to the physics object
|
||||
*/
|
||||
inline Nz::RigidBody3D& PhysicsComponent3D::GetRigidBody()
|
||||
inline Nz::RigidBody3D* PhysicsComponent3D::GetRigidBody()
|
||||
{
|
||||
return *m_object.get();
|
||||
return m_object.get();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Ndk
|
||||
{
|
||||
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent2D
|
||||
PhysicsComponent2D& physComponent = m_entity->GetComponent<PhysicsComponent2D>();
|
||||
physComponent.GetRigidBody().SetGeom(m_geom);
|
||||
physComponent.GetRigidBody()->SetGeom(m_geom);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Ndk
|
||||
{
|
||||
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent3D
|
||||
PhysicsComponent3D& physComponent = m_entity->GetComponent<PhysicsComponent3D>();
|
||||
physComponent.GetRigidBody().SetGeom(m_geom);
|
||||
physComponent.GetRigidBody()->SetGeom(m_geom);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
6
SDK/src/NDK/Components/ConstraintComponent2D.cpp
Normal file
6
SDK/src/NDK/Components/ConstraintComponent2D.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <NDK/Components/ConstraintComponent2D.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex ConstraintComponent2D::componentIndex;
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Components/ConstraintComponent2D.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem2D.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem3D.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
@@ -89,6 +90,7 @@ namespace Ndk
|
||||
InitializeComponent<PhysicsComponent2D>("NdkPhys2");
|
||||
InitializeComponent<PhysicsComponent3D>("NdkPhys3");
|
||||
InitializeComponent<VelocityComponent>("NdkVeloc");
|
||||
InitializeComponent<VelocityComponent>("NdkCons2");
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Client components
|
||||
|
||||
@@ -80,9 +80,9 @@ namespace Ndk
|
||||
NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
PhysicsComponent2D& phys = entity->GetComponent<PhysicsComponent2D>();
|
||||
|
||||
Nz::RigidBody2D& body = phys.GetRigidBody();
|
||||
node.SetRotation(Nz::EulerAnglesf(0.f, 0.f, body.GetRotation()), Nz::CoordSys_Global);
|
||||
node.SetPosition(Nz::Vector3f(body.GetPosition(), node.GetPosition(Nz::CoordSys_Global).z), Nz::CoordSys_Global);
|
||||
Nz::RigidBody2D* body = phys.GetRigidBody();
|
||||
node.SetRotation(Nz::EulerAnglesf(0.f, 0.f, body->GetRotation()), Nz::CoordSys_Global);
|
||||
node.SetPosition(Nz::Vector3f(body->GetPosition(), node.GetPosition(Nz::CoordSys_Global).z), Nz::CoordSys_Global);
|
||||
}
|
||||
|
||||
float invElapsedTime = 1.f / elapsedTime;
|
||||
|
||||
@@ -84,9 +84,9 @@ namespace Ndk
|
||||
NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
PhysicsComponent3D& phys = entity->GetComponent<PhysicsComponent3D>();
|
||||
|
||||
Nz::RigidBody3D& physObj = phys.GetRigidBody();
|
||||
node.SetRotation(physObj.GetRotation(), Nz::CoordSys_Global);
|
||||
node.SetPosition(physObj.GetPosition(), Nz::CoordSys_Global);
|
||||
Nz::RigidBody3D* physObj = phys.GetRigidBody();
|
||||
node.SetRotation(physObj->GetRotation(), Nz::CoordSys_Global);
|
||||
node.SetPosition(physObj->GetPosition(), Nz::CoordSys_Global);
|
||||
}
|
||||
|
||||
float invElapsedTime = 1.f / elapsedTime;
|
||||
|
||||
Reference in New Issue
Block a user