Physics3D: Rename all *Geom to Collider3D
This commit is contained in:
parent
8781a628e0
commit
b7a383d68c
|
|
@ -7,7 +7,7 @@
|
||||||
#ifndef NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
|
#ifndef NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
|
||||||
#define NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
|
#define NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
|
||||||
|
|
||||||
#include <Nazara/Physics3D/Geom.hpp>
|
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||||
#include <NDK/Component.hpp>
|
#include <NDK/Component.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
@ -26,15 +26,15 @@ namespace Ndk
|
||||||
friend class StaticCollisionSystem;
|
friend class StaticCollisionSystem;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CollisionComponent(Nz::PhysGeomRef geom = Nz::PhysGeomRef());
|
CollisionComponent(Nz::Collider3DRef geom = Nz::Collider3DRef());
|
||||||
CollisionComponent(const CollisionComponent& collision);
|
CollisionComponent(const CollisionComponent& collision);
|
||||||
~CollisionComponent() = default;
|
~CollisionComponent() = default;
|
||||||
|
|
||||||
const Nz::PhysGeomRef& GetGeom() const;
|
const Nz::Collider3DRef& GetGeom() const;
|
||||||
|
|
||||||
void SetGeom(Nz::PhysGeomRef geom);
|
void SetGeom(Nz::Collider3DRef geom);
|
||||||
|
|
||||||
CollisionComponent& operator=(Nz::PhysGeomRef geom);
|
CollisionComponent& operator=(Nz::Collider3DRef geom);
|
||||||
CollisionComponent& operator=(CollisionComponent&& collision) = default;
|
CollisionComponent& operator=(CollisionComponent&& collision) = default;
|
||||||
|
|
||||||
static ComponentIndex componentIndex;
|
static ComponentIndex componentIndex;
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Ndk
|
||||||
void OnDetached() override;
|
void OnDetached() override;
|
||||||
|
|
||||||
std::unique_ptr<Nz::PhysObject> m_staticBody;
|
std::unique_ptr<Nz::PhysObject> m_staticBody;
|
||||||
Nz::PhysGeomRef m_geom;
|
Nz::Collider3DRef m_geom;
|
||||||
bool m_bodyUpdated;
|
bool m_bodyUpdated;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Ndk
|
||||||
* \param geom Reference to a geometry symbolizing the entity
|
* \param geom Reference to a geometry symbolizing the entity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline CollisionComponent::CollisionComponent(Nz::PhysGeomRef geom) :
|
inline CollisionComponent::CollisionComponent(Nz::Collider3DRef geom) :
|
||||||
m_geom(std::move(geom)),
|
m_geom(std::move(geom)),
|
||||||
m_bodyUpdated(false)
|
m_bodyUpdated(false)
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Ndk
|
||||||
* \return A constant reference to the physics geometry
|
* \return A constant reference to the physics geometry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline const Nz::PhysGeomRef& CollisionComponent::GetGeom() const
|
inline const Nz::Collider3DRef& CollisionComponent::GetGeom() const
|
||||||
{
|
{
|
||||||
return m_geom;
|
return m_geom;
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,7 @@ namespace Ndk
|
||||||
* \param geom Reference to a geometry symbolizing the entity
|
* \param geom Reference to a geometry symbolizing the entity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline CollisionComponent& CollisionComponent::operator=(Nz::PhysGeomRef geom)
|
inline CollisionComponent& CollisionComponent::operator=(Nz::Collider3DRef geom)
|
||||||
{
|
{
|
||||||
SetGeom(geom);
|
SetGeom(geom);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Ndk
|
||||||
* \remark Produces a NazaraAssert if the entity has no physics component and has no static body
|
* \remark Produces a NazaraAssert if the entity has no physics component and has no static body
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void CollisionComponent::SetGeom(Nz::PhysGeomRef geom)
|
void CollisionComponent::SetGeom(Nz::Collider3DRef geom)
|
||||||
{
|
{
|
||||||
m_geom = std::move(geom);
|
m_geom = std::move(geom);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Ndk
|
||||||
|
|
||||||
Nz::PhysWorld& world = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
|
Nz::PhysWorld& world = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
|
||||||
|
|
||||||
Nz::PhysGeomRef geom;
|
Nz::Collider3DRef geom;
|
||||||
if (m_entity->HasComponent<CollisionComponent>())
|
if (m_entity->HasComponent<CollisionComponent>())
|
||||||
geom = m_entity->GetComponent<CollisionComponent>().GetGeom();
|
geom = m_entity->GetComponent<CollisionComponent>().GetGeom();
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ namespace Ndk
|
||||||
if (IsComponent<CollisionComponent>(component))
|
if (IsComponent<CollisionComponent>(component))
|
||||||
{
|
{
|
||||||
NazaraAssert(m_object, "Invalid object");
|
NazaraAssert(m_object, "Invalid object");
|
||||||
m_object->SetGeom(Nz::NullGeom::New());
|
m_object->SetGeom(Nz::NullCollider3D::New());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,16 +75,16 @@ namespace Nz
|
||||||
static Collider3DLibrary::LibraryMap s_library;
|
static Collider3DLibrary::LibraryMap s_library;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BoxGeom;
|
class BoxCollider3D;
|
||||||
|
|
||||||
using BoxGeomConstRef = ObjectRef<const BoxGeom>;
|
using BoxCollider3DConstRef = ObjectRef<const BoxCollider3D>;
|
||||||
using BoxGeomRef = ObjectRef<BoxGeom>;
|
using BoxCollider3DRef = ObjectRef<BoxCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API BoxGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API BoxCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoxGeom(const Vector3f& lengths, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
BoxCollider3D(const Vector3f& lengths, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||||
BoxGeom(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
BoxCollider3D(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||||
|
|
||||||
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
||||||
float ComputeVolume() const override;
|
float ComputeVolume() const override;
|
||||||
|
|
@ -92,7 +92,7 @@ namespace Nz
|
||||||
Vector3f GetLengths() const;
|
Vector3f GetLengths() const;
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static BoxGeomRef New(Args&&... args);
|
template<typename... Args> static BoxCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
@ -101,22 +101,22 @@ namespace Nz
|
||||||
Vector3f m_lengths;
|
Vector3f m_lengths;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CapsuleGeom;
|
class CapsuleCollider3D;
|
||||||
|
|
||||||
using CapsuleGeomConstRef = ObjectRef<const CapsuleGeom>;
|
using CapsuleCollider3DConstRef = ObjectRef<const CapsuleCollider3D>;
|
||||||
using CapsuleGeomRef = ObjectRef<CapsuleGeom>;
|
using CapsuleCollider3DRef = ObjectRef<CapsuleCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API CapsuleGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API CapsuleCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CapsuleGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
CapsuleCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||||
CapsuleGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
CapsuleCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||||
|
|
||||||
float GetLength() const;
|
float GetLength() const;
|
||||||
float GetRadius() const;
|
float GetRadius() const;
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static CapsuleGeomRef New(Args&&... args);
|
template<typename... Args> static CapsuleCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
@ -126,20 +126,20 @@ namespace Nz
|
||||||
float m_radius;
|
float m_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompoundGeom;
|
class CompoundCollider3D;
|
||||||
|
|
||||||
using CompoundGeomConstRef = ObjectRef<const CompoundGeom>;
|
using CompoundCollider3DConstRef = ObjectRef<const CompoundCollider3D>;
|
||||||
using CompoundGeomRef = ObjectRef<CompoundGeom>;
|
using CompoundCollider3DRef = ObjectRef<CompoundCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API CompoundGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API CompoundCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompoundGeom(Collider3D** geoms, std::size_t geomCount);
|
CompoundCollider3D(Collider3D** geoms, std::size_t geomCount);
|
||||||
|
|
||||||
const std::vector<Collider3DRef>& GetGeoms() const;
|
const std::vector<Collider3DRef>& GetGeoms() const;
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static CompoundGeomRef New(Args&&... args);
|
template<typename... Args> static CompoundCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
@ -147,22 +147,22 @@ namespace Nz
|
||||||
std::vector<Collider3DRef> m_geoms;
|
std::vector<Collider3DRef> m_geoms;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConeGeom;
|
class ConeCollider3D;
|
||||||
|
|
||||||
using ConeGeomConstRef = ObjectRef<const ConeGeom>;
|
using ConeCollider3DConstRef = ObjectRef<const ConeCollider3D>;
|
||||||
using ConeGeomRef = ObjectRef<ConeGeom>;
|
using ConeCollider3DRef = ObjectRef<ConeCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API ConeGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API ConeCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConeGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
ConeCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||||
ConeGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
ConeCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||||
|
|
||||||
float GetLength() const;
|
float GetLength() const;
|
||||||
float GetRadius() const;
|
float GetRadius() const;
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static ConeGeomRef New(Args&&... args);
|
template<typename... Args> static ConeCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
@ -172,20 +172,20 @@ namespace Nz
|
||||||
float m_radius;
|
float m_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConvexHullGeom;
|
class ConvexCollider3D;
|
||||||
|
|
||||||
using ConvexHullGeomConstRef = ObjectRef<const ConvexHullGeom>;
|
using ConvexCollider3DConstRef = ObjectRef<const ConvexCollider3D>;
|
||||||
using ConvexHullGeomRef = ObjectRef<ConvexHullGeom>;
|
using ConvexCollider3DRef = ObjectRef<ConvexCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API ConvexHullGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API ConvexCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride = sizeof(Vector3f), float tolerance = 0.002f, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
ConvexCollider3D(const void* vertices, unsigned int vertexCount, unsigned int stride = sizeof(Vector3f), float tolerance = 0.002f, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||||
ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
ConvexCollider3D(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||||
|
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static ConvexHullGeomRef New(Args&&... args);
|
template<typename... Args> static ConvexCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
@ -196,22 +196,22 @@ namespace Nz
|
||||||
unsigned int m_vertexStride;
|
unsigned int m_vertexStride;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CylinderGeom;
|
class CylinderCollider3D;
|
||||||
|
|
||||||
using CylinderGeomConstRef = ObjectRef<const CylinderGeom>;
|
using CylinderCollider3DConstRef = ObjectRef<const CylinderCollider3D>;
|
||||||
using CylinderGeomRef = ObjectRef<CylinderGeom>;
|
using CylinderCollider3DRef = ObjectRef<CylinderCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API CylinderGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API CylinderCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CylinderGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
CylinderCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||||
CylinderGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
CylinderCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||||
|
|
||||||
float GetLength() const;
|
float GetLength() const;
|
||||||
float GetRadius() const;
|
float GetRadius() const;
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static CylinderGeomRef New(Args&&... args);
|
template<typename... Args> static CylinderCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
@ -221,36 +221,36 @@ namespace Nz
|
||||||
float m_radius;
|
float m_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NullGeom;
|
class NullCollider3D;
|
||||||
|
|
||||||
using NullGeomConstRef = ObjectRef<const NullGeom>;
|
using NullCollider3DConstRef = ObjectRef<const NullCollider3D>;
|
||||||
using NullGeomRef = ObjectRef<NullGeom>;
|
using NullCollider3DRef = ObjectRef<NullCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API NullGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API NullCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NullGeom();
|
NullCollider3D();
|
||||||
|
|
||||||
void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const override;
|
void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const override;
|
||||||
|
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static NullGeomRef New(Args&&... args);
|
template<typename... Args> static NullCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SphereGeom;
|
class SphereCollider3D;
|
||||||
|
|
||||||
using SphereGeomConstRef = ObjectRef<const SphereGeom>;
|
using SphereCollider3DConstRef = ObjectRef<const SphereCollider3D>;
|
||||||
using SphereGeomRef = ObjectRef<SphereGeom>;
|
using SphereCollider3DRef = ObjectRef<SphereCollider3D>;
|
||||||
|
|
||||||
class NAZARA_PHYSICS3D_API SphereGeom : public Collider3D
|
class NAZARA_PHYSICS3D_API SphereCollider3D : public Collider3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SphereGeom(float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
SphereCollider3D(float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||||
SphereGeom(float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
SphereCollider3D(float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||||
|
|
||||||
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
||||||
float ComputeVolume() const override;
|
float ComputeVolume() const override;
|
||||||
|
|
@ -258,7 +258,7 @@ namespace Nz
|
||||||
float GetRadius() const;
|
float GetRadius() const;
|
||||||
GeomType GetType() const override;
|
GeomType GetType() const override;
|
||||||
|
|
||||||
template<typename... Args> static SphereGeomRef New(Args&&... args);
|
template<typename... Args> static SphereCollider3DRef New(Args&&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||||
|
|
|
||||||
|
|
@ -8,72 +8,72 @@
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BoxGeomRef BoxGeom::New(Args&&... args)
|
BoxCollider3DRef BoxCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<BoxGeom> object(new BoxGeom(std::forward<Args>(args)...));
|
std::unique_ptr<BoxCollider3D> object(new BoxCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
CapsuleGeomRef CapsuleGeom::New(Args&&... args)
|
CapsuleCollider3DRef CapsuleCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CapsuleGeom> object(new CapsuleGeom(std::forward<Args>(args)...));
|
std::unique_ptr<CapsuleCollider3D> object(new CapsuleCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
CompoundGeomRef CompoundGeom::New(Args&&... args)
|
CompoundCollider3DRef CompoundCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CompoundGeom> object(new CompoundGeom(std::forward<Args>(args)...));
|
std::unique_ptr<CompoundCollider3D> object(new CompoundCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
ConeGeomRef ConeGeom::New(Args&&... args)
|
ConeCollider3DRef ConeCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<ConeGeom> object(new ConeGeom(std::forward<Args>(args)...));
|
std::unique_ptr<ConeCollider3D> object(new ConeCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
ConvexHullGeomRef ConvexHullGeom::New(Args&&... args)
|
ConvexCollider3DRef ConvexCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<ConvexHullGeom> object(new ConvexHullGeom(std::forward<Args>(args)...));
|
std::unique_ptr<ConvexCollider3D> object(new ConvexCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
CylinderGeomRef CylinderGeom::New(Args&&... args)
|
CylinderCollider3DRef CylinderCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CylinderGeom> object(new CylinderGeom(std::forward<Args>(args)...));
|
std::unique_ptr<CylinderCollider3D> object(new CylinderCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
NullGeomRef NullGeom::New(Args&&... args)
|
NullCollider3DRef NullCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<NullGeom> object(new NullGeom(std::forward<Args>(args)...));
|
std::unique_ptr<NullCollider3D> object(new NullCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
SphereGeomRef SphereGeom::New(Args&&... args)
|
SphereCollider3DRef SphereCollider3D::New(Args&&... args)
|
||||||
{
|
{
|
||||||
std::unique_ptr<SphereGeom> object(new SphereGeom(std::forward<Args>(args)...));
|
std::unique_ptr<SphereCollider3D> object(new SphereCollider3D(std::forward<Args>(args)...));
|
||||||
object->SetPersistent(false);
|
object->SetPersistent(false);
|
||||||
|
|
||||||
return object.release();
|
return object.release();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
#include <Nazara/Math/Quaternion.hpp>
|
#include <Nazara/Math/Quaternion.hpp>
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
#include <Nazara/Physics3D/Config.hpp>
|
#include <Nazara/Physics3D/Config.hpp>
|
||||||
#include <Nazara/Physics3D/Geom.hpp>
|
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||||
|
|
||||||
class NewtonBody;
|
class NewtonBody;
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PhysObject(PhysWorld* world, const Matrix4f& mat = Matrix4f::Identity());
|
PhysObject(PhysWorld* world, const Matrix4f& mat = Matrix4f::Identity());
|
||||||
PhysObject(PhysWorld* world, PhysGeomRef geom, const Matrix4f& mat = Matrix4f::Identity());
|
PhysObject(PhysWorld* world, Collider3DRef geom, const Matrix4f& mat = Matrix4f::Identity());
|
||||||
PhysObject(const PhysObject& object);
|
PhysObject(const PhysObject& object);
|
||||||
PhysObject(PhysObject&& object);
|
PhysObject(PhysObject&& object);
|
||||||
~PhysObject();
|
~PhysObject();
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Nz
|
||||||
|
|
||||||
Boxf GetAABB() const;
|
Boxf GetAABB() const;
|
||||||
Vector3f GetAngularVelocity() const;
|
Vector3f GetAngularVelocity() const;
|
||||||
const PhysGeomRef& GetGeom() const;
|
const Collider3DRef& GetGeom() const;
|
||||||
float GetGravityFactor() const;
|
float GetGravityFactor() const;
|
||||||
NewtonBody* GetHandle() const;
|
NewtonBody* GetHandle() const;
|
||||||
float GetMass() const;
|
float GetMass() const;
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Nz
|
||||||
bool IsSleeping() const;
|
bool IsSleeping() const;
|
||||||
|
|
||||||
void SetAngularVelocity(const Vector3f& angularVelocity);
|
void SetAngularVelocity(const Vector3f& angularVelocity);
|
||||||
void SetGeom(PhysGeomRef geom);
|
void SetGeom(Collider3DRef geom);
|
||||||
void SetGravityFactor(float gravityFactor);
|
void SetGravityFactor(float gravityFactor);
|
||||||
void SetMass(float mass);
|
void SetMass(float mass);
|
||||||
void SetMassCenter(const Vector3f& center);
|
void SetMassCenter(const Vector3f& center);
|
||||||
|
|
@ -70,7 +70,7 @@ namespace Nz
|
||||||
static void TransformCallback(const NewtonBody* body, const float* matrix, int threadIndex);
|
static void TransformCallback(const NewtonBody* body, const float* matrix, int threadIndex);
|
||||||
|
|
||||||
Matrix4f m_matrix;
|
Matrix4f m_matrix;
|
||||||
PhysGeomRef m_geom;
|
Collider3DRef m_geom;
|
||||||
Vector3f m_forceAccumulator;
|
Vector3f m_forceAccumulator;
|
||||||
Vector3f m_torqueAccumulator;
|
Vector3f m_torqueAccumulator;
|
||||||
NewtonBody* m_body;
|
NewtonBody* m_body;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// This file is part of the "Nazara Engine - Physics module"
|
// This file is part of the "Nazara Engine - Physics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Physics3D/Geom.hpp>
|
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||||
#include <Nazara/Physics3D/PhysWorld.hpp>
|
#include <Nazara/Physics3D/PhysWorld.hpp>
|
||||||
#include <Newton/Newton.h>
|
#include <Newton/Newton.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -12,26 +12,26 @@ namespace Nz
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
PhysGeomRef CreateGeomFromPrimitive(const Primitive& primitive)
|
Collider3DRef CreateGeomFromPrimitive(const Primitive& primitive)
|
||||||
{
|
{
|
||||||
switch (primitive.type)
|
switch (primitive.type)
|
||||||
{
|
{
|
||||||
case PrimitiveType_Box:
|
case PrimitiveType_Box:
|
||||||
return BoxGeom::New(primitive.box.lengths, primitive.matrix);
|
return BoxCollider3D::New(primitive.box.lengths, primitive.matrix);
|
||||||
|
|
||||||
case PrimitiveType_Cone:
|
case PrimitiveType_Cone:
|
||||||
return ConeGeom::New(primitive.cone.length, primitive.cone.radius, primitive.matrix);
|
return ConeCollider3D::New(primitive.cone.length, primitive.cone.radius, primitive.matrix);
|
||||||
|
|
||||||
case PrimitiveType_Plane:
|
case PrimitiveType_Plane:
|
||||||
return BoxGeom::New(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y), primitive.matrix);
|
return BoxCollider3D::New(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y), primitive.matrix);
|
||||||
///TODO: PlaneGeom?
|
///TODO: PlaneGeom?
|
||||||
|
|
||||||
case PrimitiveType_Sphere:
|
case PrimitiveType_Sphere:
|
||||||
return SphereGeom::New(primitive.sphere.size, primitive.matrix.GetTranslation());
|
return SphereCollider3D::New(primitive.sphere.size, primitive.matrix.GetTranslation());
|
||||||
}
|
}
|
||||||
|
|
||||||
NazaraError("Primitive type not handled (0x" + String::Number(primitive.type, 16) + ')');
|
NazaraError("Primitive type not handled (0x" + String::Number(primitive.type, 16) + ')');
|
||||||
return PhysGeomRef();
|
return Collider3DRef();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ namespace Nz
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysGeomRef Collider3D::Build(const PrimitiveList& list)
|
Collider3DRef Collider3D::Build(const PrimitiveList& list)
|
||||||
{
|
{
|
||||||
std::size_t primitiveCount = list.GetSize();
|
std::size_t primitiveCount = list.GetSize();
|
||||||
if (primitiveCount > 1)
|
if (primitiveCount > 1)
|
||||||
|
|
@ -133,17 +133,17 @@ namespace Nz
|
||||||
for (unsigned int i = 0; i < primitiveCount; ++i)
|
for (unsigned int i = 0; i < primitiveCount; ++i)
|
||||||
geoms[i] = CreateGeomFromPrimitive(list.GetPrimitive(i));
|
geoms[i] = CreateGeomFromPrimitive(list.GetPrimitive(i));
|
||||||
|
|
||||||
return CompoundGeom::New(&geoms[0], primitiveCount);
|
return CompoundCollider3D::New(&geoms[0], primitiveCount);
|
||||||
}
|
}
|
||||||
else if (primitiveCount > 0)
|
else if (primitiveCount > 0)
|
||||||
return CreateGeomFromPrimitive(list.GetPrimitive(0));
|
return CreateGeomFromPrimitive(list.GetPrimitive(0));
|
||||||
else
|
else
|
||||||
return NullGeom::New();
|
return NullCollider3D::New();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Collider3D::Initialize()
|
bool Collider3D::Initialize()
|
||||||
{
|
{
|
||||||
if (!PhysGeomLibrary::Initialize())
|
if (!Collider3DLibrary::Initialize())
|
||||||
{
|
{
|
||||||
NazaraError("Failed to initialise library");
|
NazaraError("Failed to initialise library");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -154,25 +154,25 @@ namespace Nz
|
||||||
|
|
||||||
void Collider3D::Uninitialize()
|
void Collider3D::Uninitialize()
|
||||||
{
|
{
|
||||||
PhysGeomLibrary::Uninitialize();
|
Collider3DLibrary::Uninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysGeomLibrary::LibraryMap Collider3D::s_library;
|
Collider3DLibrary::LibraryMap Collider3D::s_library;
|
||||||
|
|
||||||
/********************************** BoxGeom **********************************/
|
/********************************** BoxCollider3D **********************************/
|
||||||
|
|
||||||
BoxGeom::BoxGeom(const Vector3f& lengths, const Matrix4f& transformMatrix) :
|
BoxCollider3D::BoxCollider3D(const Vector3f& lengths, const Matrix4f& transformMatrix) :
|
||||||
m_matrix(transformMatrix),
|
m_matrix(transformMatrix),
|
||||||
m_lengths(lengths)
|
m_lengths(lengths)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxGeom::BoxGeom(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation) :
|
BoxCollider3D::BoxCollider3D(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation) :
|
||||||
BoxGeom(lengths, Matrix4f::Transform(translation, rotation))
|
BoxCollider3D(lengths, Matrix4f::Transform(translation, rotation))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxf BoxGeom::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
|
Boxf BoxCollider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
|
||||||
{
|
{
|
||||||
Vector3f halfLengths(m_lengths * 0.5f);
|
Vector3f halfLengths(m_lengths * 0.5f);
|
||||||
|
|
||||||
|
|
@ -183,90 +183,90 @@ namespace Nz
|
||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BoxGeom::ComputeVolume() const
|
float BoxCollider3D::ComputeVolume() const
|
||||||
{
|
{
|
||||||
return m_lengths.x * m_lengths.y * m_lengths.z;
|
return m_lengths.x * m_lengths.y * m_lengths.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f BoxGeom::GetLengths() const
|
Vector3f BoxCollider3D::GetLengths() const
|
||||||
{
|
{
|
||||||
return m_lengths;
|
return m_lengths;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType BoxGeom::GetType() const
|
GeomType BoxCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Box;
|
return GeomType_Box;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* BoxGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* BoxCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateBox(world->GetHandle(), m_lengths.x, m_lengths.y, m_lengths.z, 0, m_matrix);
|
return NewtonCreateBox(world->GetHandle(), m_lengths.x, m_lengths.y, m_lengths.z, 0, m_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************** CapsuleGeom ********************************/
|
/******************************** CapsuleCollider3D ********************************/
|
||||||
|
|
||||||
CapsuleGeom::CapsuleGeom(float length, float radius, const Matrix4f& transformMatrix) :
|
CapsuleCollider3D::CapsuleCollider3D(float length, float radius, const Matrix4f& transformMatrix) :
|
||||||
m_matrix(transformMatrix),
|
m_matrix(transformMatrix),
|
||||||
m_length(length),
|
m_length(length),
|
||||||
m_radius(radius)
|
m_radius(radius)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CapsuleGeom::CapsuleGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
CapsuleCollider3D::CapsuleCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
||||||
CapsuleGeom(length, radius, Matrix4f::Transform(translation, rotation))
|
CapsuleCollider3D(length, radius, Matrix4f::Transform(translation, rotation))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
float CapsuleGeom::GetLength() const
|
float CapsuleCollider3D::GetLength() const
|
||||||
{
|
{
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CapsuleGeom::GetRadius() const
|
float CapsuleCollider3D::GetRadius() const
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType CapsuleGeom::GetType() const
|
GeomType CapsuleCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Capsule;
|
return GeomType_Capsule;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* CapsuleGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* CapsuleCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateCapsule(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
return NewtonCreateCapsule(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************* CompoundGeom ********************************/
|
/******************************* CompoundCollider3D ********************************/
|
||||||
|
|
||||||
CompoundGeom::CompoundGeom(Collider3D** geoms, std::size_t geomCount)
|
CompoundCollider3D::CompoundCollider3D(Collider3D** geoms, std::size_t geomCount)
|
||||||
{
|
{
|
||||||
m_geoms.reserve(geomCount);
|
m_geoms.reserve(geomCount);
|
||||||
for (std::size_t i = 0; i < geomCount; ++i)
|
for (std::size_t i = 0; i < geomCount; ++i)
|
||||||
m_geoms.emplace_back(geoms[i]);
|
m_geoms.emplace_back(geoms[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<PhysGeomRef>& CompoundGeom::GetGeoms() const
|
const std::vector<Collider3DRef>& CompoundCollider3D::GetGeoms() const
|
||||||
{
|
{
|
||||||
return m_geoms;
|
return m_geoms;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType CompoundGeom::GetType() const
|
GeomType CompoundCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Compound;
|
return GeomType_Compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* CompoundGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* CompoundCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
NewtonCollision* compoundCollision = NewtonCreateCompoundCollision(world->GetHandle(), 0);
|
NewtonCollision* compoundCollision = NewtonCreateCompoundCollision(world->GetHandle(), 0);
|
||||||
|
|
||||||
NewtonCompoundCollisionBeginAddRemove(compoundCollision);
|
NewtonCompoundCollisionBeginAddRemove(compoundCollision);
|
||||||
for (const PhysGeomRef& geom : m_geoms)
|
for (const Collider3DRef& geom : m_geoms)
|
||||||
{
|
{
|
||||||
if (geom->GetType() == GeomType_Compound)
|
if (geom->GetType() == GeomType_Compound)
|
||||||
{
|
{
|
||||||
CompoundGeom* compoundGeom = static_cast<CompoundGeom*>(geom.Get());
|
CompoundCollider3D* compoundGeom = static_cast<CompoundCollider3D*>(geom.Get());
|
||||||
for (const PhysGeomRef& piece : compoundGeom->GetGeoms())
|
for (const Collider3DRef& piece : compoundGeom->GetGeoms())
|
||||||
NewtonCompoundCollisionAddSubCollision(compoundCollision, piece->GetHandle(world));
|
NewtonCompoundCollisionAddSubCollision(compoundCollision, piece->GetHandle(world));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -277,43 +277,43 @@ namespace Nz
|
||||||
return compoundCollision;
|
return compoundCollision;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************* ConeGeom **********************************/
|
/********************************* ConeCollider3D **********************************/
|
||||||
|
|
||||||
ConeGeom::ConeGeom(float length, float radius, const Matrix4f& transformMatrix) :
|
ConeCollider3D::ConeCollider3D(float length, float radius, const Matrix4f& transformMatrix) :
|
||||||
m_matrix(transformMatrix),
|
m_matrix(transformMatrix),
|
||||||
m_length(length),
|
m_length(length),
|
||||||
m_radius(radius)
|
m_radius(radius)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ConeGeom::ConeGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
ConeCollider3D::ConeCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
||||||
ConeGeom(length, radius, Matrix4f::Transform(translation, rotation))
|
ConeCollider3D(length, radius, Matrix4f::Transform(translation, rotation))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
float ConeGeom::GetLength() const
|
float ConeCollider3D::GetLength() const
|
||||||
{
|
{
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ConeGeom::GetRadius() const
|
float ConeCollider3D::GetRadius() const
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType ConeGeom::GetType() const
|
GeomType ConeCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Cone;
|
return GeomType_Cone;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* ConeGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* ConeCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateCone(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
return NewtonCreateCone(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************** ConvexHullGeom *******************************/
|
/****************************** ConvexCollider3D *******************************/
|
||||||
|
|
||||||
ConvexHullGeom::ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Matrix4f& transformMatrix) :
|
ConvexCollider3D::ConvexCollider3D(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Matrix4f& transformMatrix) :
|
||||||
m_matrix(transformMatrix),
|
m_matrix(transformMatrix),
|
||||||
m_tolerance(tolerance),
|
m_tolerance(tolerance),
|
||||||
m_vertexStride(stride)
|
m_vertexStride(stride)
|
||||||
|
|
@ -330,67 +330,67 @@ namespace Nz
|
||||||
std::memcpy(m_vertices.data(), vertices, vertexCount*sizeof(Vector3f));
|
std::memcpy(m_vertices.data(), vertices, vertexCount*sizeof(Vector3f));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConvexHullGeom::ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation) :
|
ConvexCollider3D::ConvexCollider3D(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation) :
|
||||||
ConvexHullGeom(vertices, vertexCount, stride, tolerance, Matrix4f::Transform(translation, rotation))
|
ConvexCollider3D(vertices, vertexCount, stride, tolerance, Matrix4f::Transform(translation, rotation))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType ConvexHullGeom::GetType() const
|
GeomType ConvexCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Compound;
|
return GeomType_Compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* ConvexHullGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* ConvexCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateConvexHull(world->GetHandle(), static_cast<int>(m_vertices.size()), reinterpret_cast<const float*>(m_vertices.data()), sizeof(Vector3f), m_tolerance, 0, m_matrix);
|
return NewtonCreateConvexHull(world->GetHandle(), static_cast<int>(m_vertices.size()), reinterpret_cast<const float*>(m_vertices.data()), sizeof(Vector3f), m_tolerance, 0, m_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************* CylinderGeom ********************************/
|
/******************************* CylinderCollider3D ********************************/
|
||||||
|
|
||||||
CylinderGeom::CylinderGeom(float length, float radius, const Matrix4f& transformMatrix) :
|
CylinderCollider3D::CylinderCollider3D(float length, float radius, const Matrix4f& transformMatrix) :
|
||||||
m_matrix(transformMatrix),
|
m_matrix(transformMatrix),
|
||||||
m_length(length),
|
m_length(length),
|
||||||
m_radius(radius)
|
m_radius(radius)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CylinderGeom::CylinderGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
CylinderCollider3D::CylinderCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
||||||
CylinderGeom(length, radius, Matrix4f::Transform(translation, rotation))
|
CylinderCollider3D(length, radius, Matrix4f::Transform(translation, rotation))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
float CylinderGeom::GetLength() const
|
float CylinderCollider3D::GetLength() const
|
||||||
{
|
{
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CylinderGeom::GetRadius() const
|
float CylinderCollider3D::GetRadius() const
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType CylinderGeom::GetType() const
|
GeomType CylinderCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Cylinder;
|
return GeomType_Cylinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* CylinderGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* CylinderCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateCylinder(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
return NewtonCreateCylinder(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************* NullGeom **********************************/
|
/********************************* NullCollider3D **********************************/
|
||||||
|
|
||||||
NullGeom::NullGeom()
|
NullCollider3D::NullCollider3D()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType NullGeom::GetType() const
|
GeomType NullCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Null;
|
return GeomType_Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NullGeom::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
|
void NullCollider3D::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
|
||||||
{
|
{
|
||||||
if (inertia)
|
if (inertia)
|
||||||
inertia->MakeUnit();
|
inertia->MakeUnit();
|
||||||
|
|
@ -399,26 +399,26 @@ namespace Nz
|
||||||
center->MakeZero();
|
center->MakeZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* NullGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* NullCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateNull(world->GetHandle());
|
return NewtonCreateNull(world->GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************** SphereGeom *********************************/
|
/******************************** SphereCollider3D *********************************/
|
||||||
|
|
||||||
SphereGeom::SphereGeom(float radius, const Matrix4f& transformMatrix) :
|
SphereCollider3D::SphereCollider3D(float radius, const Matrix4f& transformMatrix) :
|
||||||
SphereGeom(radius, transformMatrix.GetTranslation())
|
SphereCollider3D(radius, transformMatrix.GetTranslation())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SphereGeom::SphereGeom(float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
SphereCollider3D::SphereCollider3D(float radius, const Vector3f& translation, const Quaternionf& rotation) :
|
||||||
m_position(translation),
|
m_position(translation),
|
||||||
m_radius(radius)
|
m_radius(radius)
|
||||||
{
|
{
|
||||||
NazaraUnused(rotation);
|
NazaraUnused(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxf SphereGeom::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
|
Boxf SphereCollider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
|
||||||
{
|
{
|
||||||
Vector3f size(m_radius * NazaraSuffixMacro(M_SQRT3, f) * scale);
|
Vector3f size(m_radius * NazaraSuffixMacro(M_SQRT3, f) * scale);
|
||||||
Vector3f position(offsetMatrix.GetTranslation());
|
Vector3f position(offsetMatrix.GetTranslation());
|
||||||
|
|
@ -426,22 +426,22 @@ namespace Nz
|
||||||
return Boxf(position - size, position + size);
|
return Boxf(position - size, position + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
float SphereGeom::ComputeVolume() const
|
float SphereCollider3D::ComputeVolume() const
|
||||||
{
|
{
|
||||||
return float(M_PI) * m_radius * m_radius * m_radius / 3.f;
|
return float(M_PI) * m_radius * m_radius * m_radius / 3.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float SphereGeom::GetRadius() const
|
float SphereCollider3D::GetRadius() const
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomType SphereGeom::GetType() const
|
GeomType SphereCollider3D::GetType() const
|
||||||
{
|
{
|
||||||
return GeomType_Sphere;
|
return GeomType_Sphere;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewtonCollision* SphereGeom::CreateHandle(PhysWorld* world) const
|
NewtonCollision* SphereCollider3D::CreateHandle(PhysWorld* world) const
|
||||||
{
|
{
|
||||||
return NewtonCreateSphere(world->GetHandle(), m_radius, 0, Matrix4f::Translate(m_position));
|
return NewtonCreateSphere(world->GetHandle(), m_radius, 0, Matrix4f::Translate(m_position));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
PhysObject::PhysObject(PhysWorld* world, const Matrix4f& mat) :
|
PhysObject::PhysObject(PhysWorld* world, const Matrix4f& mat) :
|
||||||
PhysObject(world, NullGeom::New(), mat)
|
PhysObject(world, NullCollider3D::New(), mat)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysObject::PhysObject(PhysWorld* world, PhysGeomRef geom, const Matrix4f& mat) :
|
PhysObject::PhysObject(PhysWorld* world, Collider3DRef geom, const Matrix4f& mat) :
|
||||||
m_matrix(mat),
|
m_matrix(mat),
|
||||||
m_geom(std::move(geom)),
|
m_geom(std::move(geom)),
|
||||||
m_forceAccumulator(Vector3f::Zero()),
|
m_forceAccumulator(Vector3f::Zero()),
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
||||||
NazaraAssert(m_world, "Invalid world");
|
NazaraAssert(m_world, "Invalid world");
|
||||||
|
|
||||||
if (!m_geom)
|
if (!m_geom)
|
||||||
m_geom = NullGeom::New();
|
m_geom = NullCollider3D::New();
|
||||||
|
|
||||||
m_body = NewtonCreateDynamicBody(m_world->GetHandle(), m_geom->GetHandle(m_world), m_matrix);
|
m_body = NewtonCreateDynamicBody(m_world->GetHandle(), m_geom->GetHandle(m_world), m_matrix);
|
||||||
NewtonBodySetUserData(m_body, this);
|
NewtonBodySetUserData(m_body, this);
|
||||||
|
|
@ -143,7 +143,7 @@ namespace Nz
|
||||||
return angularVelocity;
|
return angularVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PhysGeomRef& PhysObject::GetGeom() const
|
const Collider3DRef& PhysObject::GetGeom() const
|
||||||
{
|
{
|
||||||
return m_geom;
|
return m_geom;
|
||||||
}
|
}
|
||||||
|
|
@ -224,14 +224,14 @@ namespace Nz
|
||||||
NewtonBodySetOmega(m_body, angularVelocity);
|
NewtonBodySetOmega(m_body, angularVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysObject::SetGeom(PhysGeomRef geom)
|
void PhysObject::SetGeom(Collider3DRef geom)
|
||||||
{
|
{
|
||||||
if (m_geom.Get() != geom)
|
if (m_geom.Get() != geom)
|
||||||
{
|
{
|
||||||
if (geom)
|
if (geom)
|
||||||
m_geom = geom;
|
m_geom = geom;
|
||||||
else
|
else
|
||||||
m_geom = NullGeom::New();
|
m_geom = NullCollider3D::New();
|
||||||
|
|
||||||
NewtonBodySetCollision(m_body, m_geom->GetHandle(m_world));
|
NewtonBodySetCollision(m_body, m_geom->GetHandle(m_world));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/Log.hpp>
|
#include <Nazara/Core/Log.hpp>
|
||||||
#include <Nazara/Physics3D/Config.hpp>
|
#include <Nazara/Physics3D/Config.hpp>
|
||||||
#include <Nazara/Physics3D/Geom.hpp>
|
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||||
#include <Newton/Newton.h>
|
#include <Newton/Newton.h>
|
||||||
#include <Nazara/Physics3D/Debug.hpp>
|
#include <Nazara/Physics3D/Debug.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue