Former-commit-id: 6e7a2cff46d6e077a3ee4434dd9f1a4a7fd00bb5
This commit is contained in:
Lynix
2015-05-04 11:02:08 +02:00
34 changed files with 1569 additions and 192 deletions

View File

@@ -63,9 +63,9 @@ class NzBitset
void Swap(NzBitset& bitset);
bool Test(unsigned int bit) const;
bool TestAll();
bool TestAny();
bool TestNone();
bool TestAll() const;
bool TestAny() const;
bool TestNone() const;
template<typename T> T To() const;
NzString ToString() const;

View File

@@ -309,7 +309,7 @@ bool NzBitset<Block, Allocator>::Test(unsigned int bit) const
}
template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::TestAll()
bool NzBitset<Block, Allocator>::TestAll() const
{
// Cas particulier du dernier bloc
Block lastBlockMask = GetLastBlockMask();
@@ -325,7 +325,7 @@ bool NzBitset<Block, Allocator>::TestAll()
}
template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::TestAny()
bool NzBitset<Block, Allocator>::TestAny() const
{
if (m_blocks.empty())
return false;
@@ -340,7 +340,7 @@ bool NzBitset<Block, Allocator>::TestAny()
}
template<typename Block, class Allocator>
bool NzBitset<Block, Allocator>::TestNone()
bool NzBitset<Block, Allocator>::TestNone() const
{
return !TestAny();
}

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2015 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,12 +8,17 @@
#define NAZARA_GEOM_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics/Enums.hpp>
#include <unordered_map>
///TODO: CollisionModifier
///TODO: HeightfieldGeom
@@ -21,126 +26,246 @@
///TODO: SceneGeom
///TODO: TreeGeom
class NzPhysGeom;
class NzPhysWorld;
struct NewtonCollision;
class NAZARA_API NzBaseGeom : NzNonCopyable
using NzPhysGeomConstListener = NzObjectListenerWrapper<const NzPhysGeom>;
using NzPhysGeomConstRef = NzObjectRef<const NzPhysGeom>;
using NzPhysGeomLibrary = NzObjectLibrary<NzPhysGeom>;
using NzPhysGeomListener = NzObjectListenerWrapper<NzPhysGeom>;
using NzPhysGeomRef = NzObjectRef<NzPhysGeom>;
class NAZARA_API NzPhysGeom : public NzRefCounted, NzNonCopyable
{
public:
NzBaseGeom(NzPhysWorld* physWorld);
virtual ~NzBaseGeom();
NzPhysGeom() = default;
virtual ~NzPhysGeom();
virtual NzBoxf ComputeAABB(const NzVector3f& translation, const NzQuaternionf& rotation, const NzVector3f& scale) const;
virtual NzBoxf ComputeAABB(const NzMatrix4f& offsetMatrix = NzMatrix4f::Identity()) const;
NzBoxf ComputeAABB(const NzVector3f& translation, const NzQuaternionf& rotation, const NzVector3f& scale) const;
virtual NzBoxf ComputeAABB(const NzMatrix4f& offsetMatrix = NzMatrix4f::Identity(), const NzVector3f& scale = NzVector3f::Unit()) const;
virtual void ComputeInertialMatrix(NzVector3f* inertia, NzVector3f* center) const;
virtual float ComputeVolume() const;
NewtonCollision* GetHandle() const;
NewtonCollision* GetHandle(NzPhysWorld* world) const;
virtual nzGeomType GetType() const = 0;
NzPhysWorld* GetWorld() const;
static NzBaseGeom* Build(NzPhysWorld* physWorld, const NzPrimitiveList& list);
static NzPhysGeomRef Build(const NzPrimitiveList& list);
protected:
NewtonCollision* m_collision;
NzPhysWorld* m_world;
virtual NewtonCollision* CreateHandle(NzPhysWorld* world) const = 0;
mutable std::unordered_map<NzPhysWorld*, NewtonCollision*> m_handles;
static NzPhysGeomLibrary::LibraryMap s_library;
};
class NAZARA_API NzBoxGeom : public NzBaseGeom
class NzBoxGeom;
using NzBoxGeomConstListener = NzObjectListenerWrapper<const NzBoxGeom>;
using NzBoxGeomConstRef = NzObjectRef<const NzBoxGeom>;
using NzBoxGeomListener = NzObjectListenerWrapper<NzBoxGeom>;
using NzBoxGeomRef = NzObjectRef<NzBoxGeom>;
class NAZARA_API NzBoxGeom : public NzPhysGeom
{
public:
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());
NzBoxGeom(const NzVector3f& lengths, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzBoxGeom(const NzVector3f& lengths, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzBoxf ComputeAABB(const NzMatrix4f& offsetMatrix = NzMatrix4f::Identity(), const NzVector3f& scale = NzVector3f::Unit()) const override;
float ComputeVolume() const override;
NzVector3f GetLengths() const;
nzGeomType GetType() const override;
template<typename... Args> static NzBoxGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
NzMatrix4f m_matrix;
NzVector3f m_lengths;
};
class NAZARA_API NzCapsuleGeom : public NzBaseGeom
class NzCapsuleGeom;
using NzCapsuleGeomConstListener = NzObjectListenerWrapper<const NzCapsuleGeom>;
using NzCapsuleGeomConstRef = NzObjectRef<const NzCapsuleGeom>;
using NzCapsuleGeomListener = NzObjectListenerWrapper<NzCapsuleGeom>;
using NzCapsuleGeomRef = NzObjectRef<NzCapsuleGeom>;
class NAZARA_API NzCapsuleGeom : public NzPhysGeom
{
public:
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());
NzCapsuleGeom(float length, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzCapsuleGeom(float length, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
float GetLength() const;
float GetRadius() const;
nzGeomType GetType() const override;
template<typename... Args> static NzCapsuleGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
NzMatrix4f m_matrix;
float m_length;
float m_radius;
};
class NAZARA_API NzCompoundGeom : public NzBaseGeom
class NzCompoundGeom;
using NzCompoundGeomConstListener = NzObjectListenerWrapper<const NzCompoundGeom>;
using NzCompoundGeomConstRef = NzObjectRef<const NzCompoundGeom>;
using NzCompoundGeomListener = NzObjectListenerWrapper<NzCompoundGeom>;
using NzCompoundGeomRef = NzObjectRef<NzCompoundGeom>;
class NAZARA_API NzCompoundGeom : public NzPhysGeom
{
public:
NzCompoundGeom(NzPhysWorld* physWorld, NzBaseGeom** geoms, unsigned int geomCount);
NzCompoundGeom(NzPhysGeom** geoms, unsigned int geomCount);
const std::vector<NzPhysGeomRef>& GetGeoms() const;
nzGeomType GetType() const override;
template<typename... Args> static NzCompoundGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
std::vector<NzPhysGeomRef> m_geoms;
};
class NAZARA_API NzConeGeom : public NzBaseGeom
class NzConeGeom;
using NzConeGeomConstListener = NzObjectListenerWrapper<const NzConeGeom>;
using NzConeGeomConstRef = NzObjectRef<const NzConeGeom>;
using NzConeGeomListener = NzObjectListenerWrapper<NzConeGeom>;
using NzConeGeomRef = NzObjectRef<NzConeGeom>;
class NAZARA_API NzConeGeom : public NzPhysGeom
{
public:
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());
NzConeGeom(float length, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzConeGeom(float length, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
float GetLength() const;
float GetRadius() const;
nzGeomType GetType() const override;
template<typename... Args> static NzConeGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
NzMatrix4f m_matrix;
float m_length;
float m_radius;
};
class NAZARA_API NzConvexHullGeom : public NzBaseGeom
class NzConvexHullGeom;
using NzConvexHullGeomConstListener = NzObjectListenerWrapper<const NzConvexHullGeom>;
using NzConvexHullGeomConstRef = NzObjectRef<const NzConvexHullGeom>;
using NzConvexHullGeomListener = NzObjectListenerWrapper<NzConvexHullGeom>;
using NzConvexHullGeomRef = NzObjectRef<NzConvexHullGeom>;
class NAZARA_API NzConvexHullGeom : public NzPhysGeom
{
public:
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());
NzConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride = sizeof(NzVector3f), float tolerance = 0.002f, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
nzGeomType GetType() const override;
template<typename... Args> static NzConvexHullGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
std::vector<NzVector3f> m_vertices;
NzMatrix4f m_matrix;
float m_tolerance;
unsigned int m_vertexStride;
};
class NAZARA_API NzCylinderGeom : public NzBaseGeom
class NzCylinderGeom;
using NzCylinderGeomConstListener = NzObjectListenerWrapper<const NzCylinderGeom>;
using NzCylinderGeomConstRef = NzObjectRef<const NzCylinderGeom>;
using NzCylinderGeomListener = NzObjectListenerWrapper<NzCylinderGeom>;
using NzCylinderGeomRef = NzObjectRef<NzCylinderGeom>;
class NAZARA_API NzCylinderGeom : public NzPhysGeom
{
public:
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());
NzCylinderGeom(float length, float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzCylinderGeom(float length, float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
float GetLength() const;
float GetRadius() const;
nzGeomType GetType() const override;
template<typename... Args> static NzCylinderGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
NzMatrix4f m_matrix;
float m_length;
float m_radius;
};
class NAZARA_API NzNullGeom : public NzBaseGeom
class NzNullGeom;
using NzNullGeomConstListener = NzObjectListenerWrapper<const NzNullGeom>;
using NzNullGeomConstRef = NzObjectRef<const NzNullGeom>;
using NzNullGeomListener = NzObjectListenerWrapper<NzNullGeom>;
using NzNullGeomRef = NzObjectRef<NzNullGeom>;
class NAZARA_API NzNullGeom : public NzPhysGeom
{
public:
NzNullGeom(NzPhysWorld* physWorld);
NzNullGeom();
nzGeomType GetType() const override;
};
class NAZARA_API NzSphereGeom : public NzBaseGeom
{
public:
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;
template<typename... Args> static NzNullGeomRef New(Args&&... args);
private:
NzVector3f m_radius;
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
};
class NzSphereGeom;
using NzSphereGeomConstListener = NzObjectListenerWrapper<const NzSphereGeom>;
using NzSphereGeomConstRef = NzObjectRef<const NzSphereGeom>;
using NzSphereGeomListener = NzObjectListenerWrapper<NzSphereGeom>;
using NzSphereGeomRef = NzObjectRef<NzSphereGeom>;
class NAZARA_API NzSphereGeom : public NzPhysGeom
{
public:
NzSphereGeom(float radius, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity());
NzSphereGeom(float radius, const NzVector3f& translation, const NzQuaternionf& rotation = NzQuaternionf::Identity());
NzBoxf ComputeAABB(const NzMatrix4f& offsetMatrix = NzMatrix4f::Identity(), const NzVector3f& scale = NzVector3f::Unit()) const override;
float ComputeVolume() const override;
float GetRadius() const;
nzGeomType GetType() const override;
template<typename... Args> static NzSphereGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(NzPhysWorld* world) const override;
NzVector3f m_position;
float m_radius;
};
#include <Nazara/Physics/Geom.inl>
#endif // NAZARA_PHYSWORLD_HPP

View File

@@ -0,0 +1,80 @@
// Copyright (C) 2015 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
#include <memory>
#include <Nazara/Physics/Debug.hpp>
template<typename... Args>
NzBoxGeomRef NzBoxGeom::New(Args&&... args)
{
std::unique_ptr<NzBoxGeom> object(new NzBoxGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzCapsuleGeomRef NzCapsuleGeom::New(Args&&... args)
{
std::unique_ptr<NzCapsuleGeom> object(new NzCapsuleGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzCompoundGeomRef NzCompoundGeom::New(Args&&... args)
{
std::unique_ptr<NzCompoundGeom> object(new NzCompoundGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzConeGeomRef NzConeGeom::New(Args&&... args)
{
std::unique_ptr<NzConeGeom> object(new NzConeGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzConvexHullGeomRef NzConvexHullGeom::New(Args&&... args)
{
std::unique_ptr<NzConvexHullGeom> object(new NzConvexHullGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzCylinderGeomRef NzCylinderGeom::New(Args&&... args)
{
std::unique_ptr<NzCylinderGeom> object(new NzCylinderGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzNullGeomRef NzNullGeom::New(Args&&... args)
{
std::unique_ptr<NzNullGeom> object(new NzNullGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NzSphereGeomRef NzSphereGeom::New(Args&&... args)
{
std::unique_ptr<NzSphereGeom> object(new NzSphereGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Physics/DebugOff.hpp>

View File

@@ -13,16 +13,18 @@
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics/Geom.hpp>
class NzBaseGeom;
class NzPhysWorld;
struct NewtonBody;
class NAZARA_API NzPhysObject : NzNonCopyable
class NAZARA_API NzPhysObject
{
public:
NzPhysObject(NzPhysWorld* world, const NzMatrix4f& mat = NzMatrix4f::Identity());
NzPhysObject(NzPhysWorld* world, const NzBaseGeom* geom, const NzMatrix4f& mat = NzMatrix4f::Identity());
NzPhysObject(NzPhysWorld* world, NzPhysGeomRef geom, const NzMatrix4f& mat = NzMatrix4f::Identity());
NzPhysObject(const NzPhysObject& object);
NzPhysObject(NzPhysObject&& object);
~NzPhysObject();
void AddForce(const NzVector3f& force, nzCoordSys coordSys = nzCoordSys_Global);
@@ -31,7 +33,9 @@ class NAZARA_API NzPhysObject : NzNonCopyable
void EnableAutoSleep(bool autoSleep);
NzBoxf GetAABB() const;
NzVector3f GetAngularVelocity() const;
const NzPhysGeomRef& GetGeom() const;
float GetGravityFactor() const;
NewtonBody* GetHandle() const;
float GetMass() const;
@@ -45,11 +49,17 @@ class NAZARA_API NzPhysObject : NzNonCopyable
bool IsMoveable() const;
bool IsSleeping() const;
void SetAngularVelocity(const NzVector3f& angularVelocity);
void SetGeom(NzPhysGeomRef geom);
void SetGravityFactor(float gravityFactor);
void SetMass(float mass);
void SetMassCenter(const NzVector3f& center);
void SetPosition(const NzVector3f& position);
void SetRotation(const NzQuaternionf& rotation);
void SetVelocity(const NzVector3f& velocity);
NzPhysObject& operator=(const NzPhysObject& object);
NzPhysObject& operator=(NzPhysObject&& object);
private:
void UpdateBody();
@@ -57,12 +67,11 @@ class NAZARA_API NzPhysObject : NzNonCopyable
static void TransformCallback(const NewtonBody* body, const float* matrix, int threadIndex);
NzMatrix4f m_matrix;
NzPhysGeomRef m_geom;
NzVector3f m_forceAccumulator;
NzVector3f m_torqueAccumulator;
NewtonBody* m_body;
const NzBaseGeom* m_geom;
NzPhysWorld* m_world;
bool m_ownsGeom;
float m_gravityFactor;
float m_mass;
};

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/BufferMapper.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
class NzIndexBuffer;
class NzIndexIterator;