Merge remote-tracking branch 'origin/Physics-module'
Former-commit-id: d4e2c3b0633ac7916b646e6fe33c75ed94e68bf1
This commit is contained in:
39
include/Nazara/Physics.hpp
Normal file
39
include/Nazara/Physics.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// This file was automatically generated on 21 May 2013 at 13:57:27
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics module
|
||||
|
||||
Copyright (C) 2013 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_PHYSICS_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS_HPP
|
||||
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics/Enums.hpp>
|
||||
#include <Nazara/Physics/Geom.hpp>
|
||||
#include <Nazara/Physics/Physics.hpp>
|
||||
#include <Nazara/Physics/PhysObject.hpp>
|
||||
#include <Nazara/Physics/PhysWorld.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS_HPP
|
||||
38
include/Nazara/Physics/Config.hpp
Normal file
38
include/Nazara/Physics/Config.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Nazara Engine - Physics module
|
||||
|
||||
Copyright (C) 2013 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_PHYSICS_HPP
|
||||
#define NAZARA_CONFIG_PHYSICS_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
|
||||
#define NAZARA_PHYSICS_MEMORYLEAKTRACKER 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_PHYSICS_SAFE 1
|
||||
|
||||
#endif // NAZARA_CONFIG_PHYSICS_HPP
|
||||
11
include/Nazara/Physics/Debug.hpp
Normal file
11
include/Nazara/Physics/Debug.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#if NAZARA_PHYSICS_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
|
||||
|
||||
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
|
||||
#define new new(__FILE__, __LINE__)
|
||||
#endif
|
||||
8
include/Nazara/Physics/DebugOff.hpp
Normal file
8
include/Nazara/Physics/DebugOff.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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
|
||||
|
||||
#if NAZARA_PHYSICS_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
27
include/Nazara/Physics/Enums.hpp
Normal file
27
include/Nazara/Physics/Enums.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_PHYSICS_HPP
|
||||
#define NAZARA_ENUMS_PHYSICS_HPP
|
||||
|
||||
enum nzGeomType
|
||||
{
|
||||
nzGeomType_Box,
|
||||
nzGeomType_Capsule,
|
||||
nzGeomType_Cone,
|
||||
nzGeomType_Compound,
|
||||
nzGeomType_ConvexHull,
|
||||
nzGeomType_Cylinder,
|
||||
nzGeomType_Heightfield,
|
||||
nzGeomType_Null,
|
||||
nzGeomType_Scene,
|
||||
nzGeomType_Sphere,
|
||||
nzGeomType_Tree,
|
||||
|
||||
nzGeomType_Max = nzGeomType_Tree
|
||||
};
|
||||
|
||||
#endif // NAZARA_ENUMS_PHYSICS_HPP
|
||||
137
include/Nazara/Physics/Geom.hpp
Normal file
137
include/Nazara/Physics/Geom.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GEOM_HPP
|
||||
#define NAZARA_GEOM_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics/Enums.hpp>
|
||||
|
||||
///TODO: CollisionModifier
|
||||
///TODO: HeightfieldGeom
|
||||
///TODO: SceneGeom
|
||||
///TODO: TreeGeom
|
||||
|
||||
class NzPhysWorld;
|
||||
struct NewtonCollision;
|
||||
|
||||
class NAZARA_API NzBaseGeom : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
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 void ComputeInertialMatrix(NzVector3f* inertia, NzVector3f* center) const;
|
||||
virtual float ComputeVolume() const;
|
||||
|
||||
NewtonCollision* GetHandle() const;
|
||||
virtual nzGeomType GetType() const = 0;
|
||||
|
||||
NzPhysWorld* GetWorld() const;
|
||||
|
||||
protected:
|
||||
NewtonCollision* m_collision;
|
||||
NzPhysWorld* m_world;
|
||||
};
|
||||
|
||||
class NAZARA_API NzBoxGeom : public NzBaseGeom
|
||||
{
|
||||
public:
|
||||
NzBoxGeom(NzPhysWorld* physWorld, const NzVector3f& lengths, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
|
||||
|
||||
NzVector3f GetLengths() const;
|
||||
nzGeomType GetType() const override;
|
||||
|
||||
private:
|
||||
NzVector3f m_lengths;
|
||||
};
|
||||
|
||||
class NAZARA_API NzCapsuleGeom : public NzBaseGeom
|
||||
{
|
||||
public:
|
||||
NzCapsuleGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
nzGeomType GetType() const override;
|
||||
|
||||
private:
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_API NzCompoundGeom : public NzBaseGeom
|
||||
{
|
||||
public:
|
||||
NzCompoundGeom(NzPhysWorld* physWorld, NzBaseGeom* geoms, unsigned int geomCount);
|
||||
|
||||
nzGeomType GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_API NzConeGeom : public NzBaseGeom
|
||||
{
|
||||
public:
|
||||
NzConeGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
nzGeomType GetType() const override;
|
||||
|
||||
private:
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
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());
|
||||
|
||||
nzGeomType GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_API NzCylinderGeom : public NzBaseGeom
|
||||
{
|
||||
public:
|
||||
NzCylinderGeom(NzPhysWorld* physWorld, float length, float radius, const NzVector3f& translation = NzVector3f::Zero(), const NzQuaternionf& rotation = NzQuaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
nzGeomType GetType() const override;
|
||||
|
||||
private:
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_API NzNullGeom : public NzBaseGeom
|
||||
{
|
||||
public:
|
||||
NzNullGeom(NzPhysWorld* physWorld);
|
||||
|
||||
nzGeomType GetType() const override;
|
||||
};
|
||||
|
||||
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());
|
||||
|
||||
NzVector3f GetRadius() const;
|
||||
nzGeomType GetType() const override;
|
||||
|
||||
private:
|
||||
NzVector3f m_radius;
|
||||
};
|
||||
|
||||
#endif // NAZARA_PHYSWORLD_HPP
|
||||
53
include/Nazara/Physics/PhysObject.hpp
Normal file
53
include/Nazara/Physics/PhysObject.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSOBJECT_HPP
|
||||
#define NAZARA_PHYSOBJECT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
class NzBaseGeom;
|
||||
class NzPhysWorld;
|
||||
struct NewtonBody;
|
||||
|
||||
class NAZARA_API NzPhysObject : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzPhysObject(NzPhysWorld* world, const NzMatrix4f& mat = NzMatrix4f::Identity());
|
||||
NzPhysObject(NzPhysWorld* world, const NzBaseGeom* geom, const NzMatrix4f& mat = NzMatrix4f::Identity());
|
||||
~NzPhysObject();
|
||||
|
||||
float GetGravityFactor() const;
|
||||
float GetMass() const;
|
||||
NzVector3f GetMassCenter() const;
|
||||
NzVector3f GetPosition() const;
|
||||
NzQuaternionf GetRotation() const;
|
||||
NzVector3f GetVelocity() const;
|
||||
|
||||
bool IsMoveable() const;
|
||||
|
||||
void SetMass(float mass);
|
||||
void SetMassCenter(NzVector3f center);
|
||||
|
||||
private:
|
||||
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;
|
||||
NewtonBody* m_body;
|
||||
const NzBaseGeom* m_geom;
|
||||
NzPhysWorld* m_world;
|
||||
bool m_ownsGeom;
|
||||
float m_gravityFactor;
|
||||
float m_mass;
|
||||
};
|
||||
|
||||
#endif // NAZARA_PHYSOBJECT_HPP
|
||||
39
include/Nazara/Physics/PhysWorld.hpp
Normal file
39
include/Nazara/Physics/PhysWorld.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSWORLD_HPP
|
||||
#define NAZARA_PHYSWORLD_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
struct NewtonWorld;
|
||||
|
||||
class NAZARA_API NzPhysWorld : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzPhysWorld();
|
||||
~NzPhysWorld();
|
||||
|
||||
NzVector3f GetGravity() const;
|
||||
NewtonWorld* GetHandle() const;
|
||||
unsigned int GetMemoryUsed() const;
|
||||
|
||||
void SetGravity(const NzVector3f& gravity);
|
||||
void SetSize(const NzCubef& cube);
|
||||
void SetSize(const NzVector3f& min, const NzVector3f& max);
|
||||
void SetSolverModel(unsigned int model);
|
||||
|
||||
void Update(float timestep);
|
||||
|
||||
private:
|
||||
NzVector3f m_gravity;
|
||||
NewtonWorld* m_world;
|
||||
};
|
||||
|
||||
#endif // NAZARA_PHYSWORLD_HPP
|
||||
31
include/Nazara/Physics/Physics.hpp
Normal file
31
include/Nazara/Physics/Physics.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS_HPP
|
||||
#define NAZARA_PHYSICS_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
|
||||
class NAZARA_API NzPhysics
|
||||
{
|
||||
public:
|
||||
NzPhysics() = delete;
|
||||
~NzPhysics() = delete;
|
||||
|
||||
static unsigned int GetMemoryUsed();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
|
||||
#endif // NAZARA_PHYSICS_HPP
|
||||
Reference in New Issue
Block a user