Updated physics module (Still experimental)

Former-commit-id: 4852b7cf6eca5ba3177397586877fe3d3c39dbd9
This commit is contained in:
Lynix
2013-06-24 13:33:54 +02:00
parent 050f9c2eb7
commit 0e3a4fa90b
6 changed files with 296 additions and 74 deletions

View File

@@ -8,14 +8,16 @@
#define NAZARA_GEOM_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics/Enums.hpp>
///TODO: CollisionModifier
///TODO: HeightfieldGeom
///TODO: PlaneGeom ?
///TODO: SceneGeom
///TODO: TreeGeom
@@ -28,8 +30,8 @@ class NAZARA_API NzBaseGeom : NzNonCopyable
NzBaseGeom(NzPhysWorld* physWorld);
virtual ~NzBaseGeom();
virtual NzCubef ComputeAABB(const NzVector3f& translation, const NzQuaternionf& rotation, const NzVector3f& scale) const;
virtual NzCubef ComputeAABB(const NzMatrix4f& offsetMatrix = NzMatrix4f::Identity()) const;
virtual NzBoxf ComputeAABB(const NzVector3f& translation, const NzQuaternionf& rotation, const NzVector3f& scale) const;
virtual NzBoxf ComputeAABB(const NzMatrix4f& offsetMatrix = NzMatrix4f::Identity()) const;
virtual void ComputeInertialMatrix(NzVector3f* inertia, NzVector3f* center) const;
virtual float ComputeVolume() const;
@@ -38,6 +40,8 @@ class NAZARA_API NzBaseGeom : NzNonCopyable
NzPhysWorld* GetWorld() const;
static NzBaseGeom* Build(NzPhysWorld* physWorld, const NzPrimitiveList& list);
protected:
NewtonCollision* m_collision;
NzPhysWorld* m_world;
@@ -46,7 +50,8 @@ class NAZARA_API NzBaseGeom : NzNonCopyable
class NAZARA_API NzBoxGeom : public NzBaseGeom
{
public:
NzBoxGeom(NzPhysWorld* physWorld, const NzVector3f& lengths, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzBoxGeom(NzPhysWorld* physWorld, const NzVector3f& lengths, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzBoxGeom(NzPhysWorld* physWorld, const NzVector3f& lengths, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzVector3f GetLengths() const;
nzGeomType GetType() const override;
@@ -58,7 +63,8 @@ class NAZARA_API NzBoxGeom : public NzBaseGeom
class NAZARA_API NzCapsuleGeom : public NzBaseGeom
{
public:
NzCapsuleGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzCapsuleGeom(NzPhysWorld* physWorld, float length, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzCapsuleGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
float GetLength() const;
float GetRadius() const;
@@ -72,7 +78,7 @@ class NAZARA_API NzCapsuleGeom : public NzBaseGeom
class NAZARA_API NzCompoundGeom : public NzBaseGeom
{
public:
NzCompoundGeom(NzPhysWorld* physWorld, NzBaseGeom* geoms, unsigned int geomCount);
NzCompoundGeom(NzPhysWorld* physWorld, NzBaseGeom** geoms, unsigned int geomCount);
nzGeomType GetType() const override;
};
@@ -80,7 +86,8 @@ class NAZARA_API NzCompoundGeom : public NzBaseGeom
class NAZARA_API NzConeGeom : public NzBaseGeom
{
public:
NzConeGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzConeGeom(NzPhysWorld* physWorld, float length, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzConeGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
float GetLength() const;
float GetRadius() const;
@@ -94,7 +101,8 @@ class NAZARA_API NzConeGeom : public NzBaseGeom
class NAZARA_API NzConvexHullGeom : public NzBaseGeom
{
public:
NzConvexHullGeom(NzPhysWorld* physWorld, const NzVector3f* vertices, unsigned int vertexCount, unsigned int stride = sizeof(NzVector3f), float tolerance = 0.2f, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzConvexHullGeom(NzPhysWorld* physWorld, const void* vertices, unsigned int vertexCount, unsigned int stride = sizeof(NzVector3f), float tolerance = 0.002f, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzConvexHullGeom(NzPhysWorld* physWorld, const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
nzGeomType GetType() const override;
};
@@ -102,7 +110,8 @@ class NAZARA_API NzConvexHullGeom : public NzBaseGeom
class NAZARA_API NzCylinderGeom : public NzBaseGeom
{
public:
NzCylinderGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzCylinderGeom(NzPhysWorld* physWorld, float length, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzCylinderGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
float GetLength() const;
float GetRadius() const;
@@ -124,8 +133,8 @@ class NAZARA_API NzNullGeom : public NzBaseGeom
class NAZARA_API NzSphereGeom : public NzBaseGeom
{
public:
NzSphereGeom(NzPhysWorld* physWorld, const NzVector3f& radius, const NzVector3f& translation = NzVector3f::Zero());
NzSphereGeom(NzPhysWorld* physWorld, float radius, const NzVector3f& translation = NzVector3f::Zero());
NzSphereGeom(NzPhysWorld* physWorld, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzSphereGeom(NzPhysWorld* physWorld, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzVector3f GetRadius() const;
nzGeomType GetType() const override;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013 Jérôme Leclercq
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -8,6 +8,7 @@
#define NAZARA_PHYSOBJECT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
@@ -24,24 +25,40 @@ class NAZARA_API NzPhysObject : NzNonCopyable
NzPhysObject(NzPhysWorld* world, const NzBaseGeom* geom, const NzMatrix4f& mat = NzMatrix4f::Identity());
~NzPhysObject();
void AddForce(const NzVector3f& force, nzCoordSys coordSys = nzCoordSys_Global);
void AddForce(const NzVector3f& force, const NzVector3f& point, nzCoordSys coordSys = nzCoordSys_Global);
void AddTorque(const NzVector3f& torque, nzCoordSys coordSys = nzCoordSys_Global);
void EnableAutoSleep(bool autoSleep);
NzVector3f GetAngularVelocity() const;
float GetGravityFactor() const;
NewtonBody* GetHandle() const;
float GetMass() const;
NzVector3f GetMassCenter() const;
NzVector3f GetMassCenter(nzCoordSys coordSys = nzCoordSys_Local) const;
const NzMatrix4f& GetMatrix() const;
NzVector3f GetPosition() const;
NzQuaternionf GetRotation() const;
NzVector3f GetVelocity() const;
bool IsAutoSleepEnabled() const;
bool IsMoveable() const;
bool IsSleeping() const;
void SetGravityFactor(float gravityFactor);
void SetMass(float mass);
void SetMassCenter(NzVector3f center);
void SetMassCenter(const NzVector3f& center);
void SetPosition(const NzVector3f& position);
void SetRotation(const NzQuaternionf& rotation);
private:
void UpdateBody();
static void ForceAndTorqueCallback(const NewtonBody* body, float timeStep, int threadIndex);
static void TransformCallback(const NewtonBody* body, const float* matrix, int threadIndex);
NzMatrix4f m_matrix;
NzVector3f m_forceAccumulator;
NzVector3f m_torqueAccumulator;
NewtonBody* m_body;
const NzBaseGeom* m_geom;
NzPhysWorld* m_world;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013 Jérôme Leclercq
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -22,18 +22,19 @@ class NAZARA_API NzPhysWorld : NzNonCopyable
NzVector3f GetGravity() const;
NewtonWorld* GetHandle() const;
unsigned int GetMemoryUsed() const;
float GetStepSize() const;
void SetGravity(const NzVector3f& gravity);
void SetSize(const NzBoxf& box);
void SetSize(const NzVector3f& min, const NzVector3f& max);
void SetSolverModel(unsigned int model);
void SetStepSize(float stepSize);
void Update(float timestep);
void Step(float timestep);
private:
NzVector3f m_gravity;
NewtonWorld* m_world;
float m_stepSize;
float m_timestepAccumulator;
};
#endif // NAZARA_PHYSWORLD_HPP