JoltPhysics3D: Rework RigidBody wrapper
- Add a clear way to setup dynamic/kinematic or static bodies - Body registration to the world is batched (all bodies created before a physics step are added together, which is what Jolt is optimized for) - Added support for empty shapes (= rigid bodies without collision) using a very small shape and tagging the body as sensor
This commit is contained in:
committed by
Jérôme Leclercq
parent
67b1710adb
commit
d610baf920
@@ -19,6 +19,7 @@
|
||||
namespace JPH
|
||||
{
|
||||
class Body;
|
||||
class BodyCreationSettings;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
@@ -28,8 +29,11 @@ namespace Nz
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3D
|
||||
{
|
||||
public:
|
||||
JoltRigidBody3D(JoltPhysWorld3D* world, const Matrix4f& mat = Matrix4f::Identity());
|
||||
JoltRigidBody3D(JoltPhysWorld3D* world, std::shared_ptr<JoltCollider3D> geom, const Matrix4f& mat = Matrix4f::Identity());
|
||||
struct DynamicSettings;
|
||||
struct StaticSettings;
|
||||
|
||||
JoltRigidBody3D(JoltPhysWorld3D& world, const DynamicSettings& settings);
|
||||
JoltRigidBody3D(JoltPhysWorld3D& world, const StaticSettings& settings);
|
||||
JoltRigidBody3D(const JoltRigidBody3D& object) = delete;
|
||||
JoltRigidBody3D(JoltRigidBody3D&& object) noexcept;
|
||||
~JoltRigidBody3D();
|
||||
@@ -38,7 +42,9 @@ namespace Nz
|
||||
void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys::Global);
|
||||
void AddTorque(const Vector3f& torque, CoordSys coordSys = CoordSys::Global);
|
||||
|
||||
inline void DisableSimulation();
|
||||
inline void DisableSleeping();
|
||||
void EnableSimulation(bool enable);
|
||||
void EnableSleeping(bool enable);
|
||||
|
||||
void FallAsleep();
|
||||
@@ -53,16 +59,16 @@ namespace Nz
|
||||
float GetLinearDamping() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
float GetMass() const;
|
||||
Vector3f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
|
||||
Matrix4f GetMatrix() const;
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
inline JoltPhysWorld3D* GetWorld() const;
|
||||
inline JoltPhysWorld3D& GetWorld() const;
|
||||
|
||||
bool IsSimulationEnabled() const;
|
||||
inline bool IsSimulationEnabled() const;
|
||||
bool IsSleeping() const;
|
||||
bool IsSleepingEnabled() const;
|
||||
bool IsStatic() const;
|
||||
|
||||
void SetAngularDamping(float angularDamping);
|
||||
void SetAngularVelocity(const Vector3f& angularVelocity);
|
||||
@@ -70,7 +76,6 @@ namespace Nz
|
||||
void SetLinearDamping(float damping);
|
||||
void SetLinearVelocity(const Vector3f& velocity);
|
||||
void SetMass(float mass, bool recomputeInertia = true);
|
||||
void SetMassCenter(const Vector3f& center);
|
||||
void SetPosition(const Vector3f& position);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
|
||||
@@ -86,14 +91,53 @@ namespace Nz
|
||||
JoltRigidBody3D& operator=(const JoltRigidBody3D& object) = delete;
|
||||
JoltRigidBody3D& operator=(JoltRigidBody3D&& object) noexcept;
|
||||
|
||||
struct CommonSettings
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> geom;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
bool initiallySleeping = false;
|
||||
bool isSimulationEnabled = true;
|
||||
bool isTrigger = false;
|
||||
};
|
||||
|
||||
struct DynamicSettings : CommonSettings
|
||||
{
|
||||
// Default values from Jolt
|
||||
JoltMotionQuality motionQuality = JoltMotionQuality::Discrete;
|
||||
Vector3f angularVelocity = Vector3f::Zero();
|
||||
Vector3f linearVelocity = Vector3f::Zero();
|
||||
bool allowSleeping = true;
|
||||
float angularDamping = 0.05f;
|
||||
float friction = 0.2f;
|
||||
float gravityFactor = 1.f;
|
||||
float linearDamping = 0.05f;
|
||||
float mass = 1.f;
|
||||
float maxAngularVelocity = 0.25f * Pi<float> * 60.f;
|
||||
float maxLinearVelocity = 500.f;
|
||||
float restitution = 0.f;
|
||||
};
|
||||
|
||||
struct StaticSettings : CommonSettings
|
||||
{
|
||||
};
|
||||
|
||||
protected:
|
||||
void Destroy();
|
||||
void Destroy(bool worldDestruction = false);
|
||||
|
||||
private:
|
||||
void BuildSettings(const CommonSettings& settings, JPH::BodyCreationSettings& creationSettings);
|
||||
void BuildSettings(const DynamicSettings& settings, JPH::BodyCreationSettings& creationSettings);
|
||||
void BuildSettings(const StaticSettings& settings, JPH::BodyCreationSettings& creationSettings);
|
||||
|
||||
bool ShouldActivate() const;
|
||||
|
||||
std::shared_ptr<JoltCollider3D> m_geom;
|
||||
JPH::Body* m_body;
|
||||
JoltPhysWorld3D* m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
bool m_isSimulationEnabled;
|
||||
bool m_isTrigger;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user