Sligthly changed interface & added functionnalities
NzPhysicsWorld has now a public pointer to NewtonWorld NzCollisionShape added, can be constructed from a NzCube for now NzPhysicsEntity added Minor fix + typo
This commit is contained in:
parent
092ccd0302
commit
f1865e5030
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq / Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef COLLISIONSHAPE_HPP
|
||||
#define COLLISIONSHAPE_HPP
|
||||
|
||||
#include <Newton/Newton.h>
|
||||
#include "PhysicsWorld.hpp"
|
||||
//#include <Nazara/Physics/PhysicsWorld.hpp>
|
||||
|
||||
class NzCollisionShape
|
||||
{
|
||||
public:
|
||||
NzCollisionShape(NzPhysicsWorld* world);
|
||||
~NzCollisionShape();
|
||||
|
||||
void Create(const NzVector3f& cubeSize);
|
||||
//void Create(const NzSpheref& sphere);
|
||||
//void Create(const NzConef& cone);
|
||||
//void Create(const NzMesh& customMesh);
|
||||
void Release();
|
||||
|
||||
bool IsValid();
|
||||
|
||||
NewtonCollision* newtonCollisionShape;
|
||||
|
||||
protected:
|
||||
private:
|
||||
NzPhysicsWorld* m_world;
|
||||
bool m_isCreated;
|
||||
};
|
||||
|
||||
#endif // COLLISIONSHAPE_HPP
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ModuleName/Config.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#if NAZARA_PHYSICS_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq / Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PHYSICSENTITY_HPP
|
||||
#define PHYSICSENTITY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Newton/Newton.h>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
//#include <Nazara/Physics/CollisionShape.hpp>
|
||||
#include "CollisionShape.hpp"
|
||||
|
||||
class NzPhysicsWorld;
|
||||
|
||||
class NzPhysicsEntity
|
||||
{
|
||||
public:
|
||||
NzPhysicsEntity(NzPhysicsWorld* world, const NzCollisionShape& shape, const NzVector3f& position, float mass);
|
||||
virtual void Init();
|
||||
virtual ~NzPhysicsEntity();
|
||||
protected:
|
||||
NzPhysicsWorld* m_world;
|
||||
NewtonBody* m_body;
|
||||
float m_mass;
|
||||
NzMatrix4f m_entityMatrix;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // PHYSICSENTITY_HPP
|
||||
|
|
@ -9,34 +9,43 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Newton/Newton.h>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include "PhysicsSolver.hpp"
|
||||
//#include <Nazara/Physics/PhysicsSolver.hpp>
|
||||
|
||||
enum nzFrictionModel
|
||||
{
|
||||
nzExact,
|
||||
nzAdaptative
|
||||
};
|
||||
|
||||
class NzPhysicsSolver;
|
||||
//TODO : ajouter Axis Aligned Bounding Box
|
||||
|
||||
class NzPhysicsWorld
|
||||
{
|
||||
enum nzFrictionModel
|
||||
{
|
||||
nzExact,
|
||||
nzAdaptative
|
||||
};
|
||||
|
||||
public:
|
||||
NzPhysicsWorld();
|
||||
~NzPhysicsWorld();
|
||||
|
||||
void SetSize(const NzCubef& size);
|
||||
const NzCubef& GetSize() const;
|
||||
|
||||
void SetPhysicsSolver(const NzPhysicsSolver& solver);
|
||||
const NzPhysicsSolver& GetPhysicsSolver() const;
|
||||
|
||||
void SetFrictionModel(nzFrictionModel model);
|
||||
const nzFrictionModel& GetFrictionModel();
|
||||
const nzFrictionModel& GetFrictionModel() const;
|
||||
|
||||
void UpdatePhysics(nzUint64 timestep);
|
||||
void UpdatePhysics(float timestep);
|
||||
|
||||
NewtonWorld* newtonWorld;
|
||||
|
||||
protected:
|
||||
private:
|
||||
NewtonWorld* m_world;
|
||||
NzPhysicsSolver m_solver;
|
||||
nzFrictionModel m_frictionModel;
|
||||
NzCubef m_size;
|
||||
};
|
||||
|
||||
#endif // PHYSICSWORLD_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq / Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef STATICBODY_HPP
|
||||
#define STATICBODY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
//#include <Nazara/Physics/PhysicsEntity.hpp>
|
||||
#include "PhysicsEntity.hpp"
|
||||
|
||||
class NzStaticBody : public NzPhysicsEntity
|
||||
{
|
||||
public:
|
||||
NzStaticBody(NzPhysicsWorld* world, const NzCollisionShape& shape, const NzVector3f& position, float mass);
|
||||
~NzStaticBody();
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // STATICBODY_HPP
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq / Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include "CollisionShape.hpp"
|
||||
//#include <Nazara/Physics/CollisionShape.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzCollisionShape::NzCollisionShape(NzPhysicsWorld* world)
|
||||
{
|
||||
m_world = world;
|
||||
m_isCreated = false;
|
||||
newtonCollisionShape = nullptr;
|
||||
}
|
||||
|
||||
NzCollisionShape::~NzCollisionShape()
|
||||
{
|
||||
if(m_isCreated)
|
||||
NewtonReleaseCollision(m_world->newtonWorld, newtonCollisionShape);
|
||||
}
|
||||
|
||||
void NzCollisionShape::Create(const NzVector3f& cubeSize)
|
||||
{
|
||||
newtonCollisionShape = NewtonCreateBox(m_world->newtonWorld, static_cast<dFloat>(cubeSize.x),
|
||||
static_cast<dFloat>(cubeSize.y),
|
||||
static_cast<dFloat>(cubeSize.z), 0, NULL);
|
||||
}
|
||||
|
||||
void NzCollisionShape::Release()
|
||||
{
|
||||
if(m_isCreated)
|
||||
NewtonReleaseCollision(m_world->newtonWorld, newtonCollisionShape);
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq / Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include "PhysicsWorld.hpp"
|
||||
//#include <Nazara/Physics/PhysicsWorld.hpp>
|
||||
#include "PhysicsEntity.hpp"
|
||||
//#include <Nazara/Physics/PhysicsEntity.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzPhysicsEntity::NzPhysicsEntity(NzPhysicsWorld* world, const NzCollisionShape& shape, const NzVector3f& position, float mass) : m_world(world), m_mass(mass)
|
||||
{
|
||||
m_entityMatrix.SetIdentity();
|
||||
m_entityMatrix.SetTranslation(position);
|
||||
|
||||
m_body = NewtonCreateBody(world->newtonWorld, shape.newtonCollisionShape,NULL);
|
||||
|
||||
//NewtonBodySetMatrix(m_pBody, /*&m_entityMatrix.matrice [0][0]*/);//Passage dgMatrix a NzMatrix4 ??
|
||||
|
||||
//Pour rigid bodies uniquement
|
||||
/*
|
||||
// On calcul l'inertie du corps, en passant par une petite formule
|
||||
CVector inertie;
|
||||
|
||||
inertie.x = 0.7f * m_masse * (m_taille.y * m_taille.y + m_taille.z * m_taille.z) / 12;
|
||||
inertie.y = 0.7f * m_masse * (m_taille.x * m_taille.x + m_taille.z * m_taille.z) / 12;
|
||||
inertie.z = 0.7f * m_masse * (m_taille.x * m_taille.x + m_taille.y * m_taille.y) / 12;
|
||||
|
||||
// On définit ensuite la masse et l'inertie pour ce corps
|
||||
NewtonBodySetMassMatrix (m_pBody, m_masse, inertie.x, inertie.y, inertie.z);
|
||||
|
||||
// On règle enfin le Callback, qui sera nécessaire pour que le corps bouge
|
||||
NewtonBodySetForceAndTorqueCallback (m_pBody, ApplyForceAndTorqueCallback);*/
|
||||
}
|
||||
|
||||
void NzPhysicsEntity::Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NzPhysicsEntity::~NzPhysicsEntity()
|
||||
{
|
||||
NewtonDestroyBody(m_world->newtonWorld,m_body);
|
||||
}
|
||||
|
|
@ -27,15 +27,15 @@ void NzPhysicsSolver::Set(NzPhysicsWorld* world)
|
|||
switch(m_mode)
|
||||
{
|
||||
case nzExact:
|
||||
NewtonSetSolverModel(world, 0);
|
||||
NewtonSetSolverModel(world->newtonWorld, 0);
|
||||
break;
|
||||
|
||||
case nzAdaptative:
|
||||
NewtonSetSolverModel(world, 1);
|
||||
NewtonSetSolverModel(world->newtonWorld, 1);
|
||||
break;
|
||||
|
||||
case nzLinear:
|
||||
NewtonSetSolverModel(world, m_numberOfPassesLinearMode);
|
||||
NewtonSetSolverModel(world->newtonWorld, m_numberOfPassesLinearMode);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,12 @@
|
|||
|
||||
#include "PhysicsWorld.hpp"
|
||||
//#include <Nazara/Physics/PhysicsWorld.hpp>
|
||||
#include "PhysicsSolver.hpp"
|
||||
//#include <Nazara/Physics/PhysicsSolver.hpp>
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzPhysicsWorld::NzPhysicsWorld()
|
||||
{
|
||||
m_world = NewtonCreate();
|
||||
newtonWorld = NewtonCreate();
|
||||
m_solver.Configure(nzLinear,10);
|
||||
m_solver.Set(this);
|
||||
SetFrictionModel(nzAdaptative);
|
||||
|
|
@ -19,16 +17,37 @@ NzPhysicsWorld::NzPhysicsWorld()
|
|||
|
||||
NzPhysicsWorld::~NzPhysicsWorld()
|
||||
{
|
||||
NewtonDestroy(m_world);
|
||||
NewtonDestroy(newtonWorld);
|
||||
}
|
||||
|
||||
void NzPhysicsWorld::SetPhysicsSolverSolver(const NzPhysicsSolver& solver)
|
||||
void NzPhysicsWorld::SetSize(const NzCubef& size)
|
||||
{
|
||||
m_size = size;
|
||||
float bottom[3];
|
||||
bottom[0] = m_size.x;
|
||||
bottom[1] = m_size.y;
|
||||
bottom[2] = m_size.z;
|
||||
float top[3];
|
||||
top[0] = m_size.x + m_size.width;
|
||||
top[1] = m_size.y + m_size.height;
|
||||
top[2] = m_size.z + m_size.depth;
|
||||
|
||||
NewtonSetWorldSize(newtonWorld, static_cast<dFloat*>(bottom),
|
||||
static_cast<dFloat*>(top));
|
||||
}
|
||||
|
||||
const NzCubef& NzPhysicsWorld::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
void NzPhysicsWorld::SetPhysicsSolver(const NzPhysicsSolver& solver)
|
||||
{
|
||||
m_solver = solver;
|
||||
m_solver.Set(this);
|
||||
}
|
||||
|
||||
const nzSolverMode& NzPhysicsWorld::GetPhysicsSolver()
|
||||
const NzPhysicsSolver& NzPhysicsWorld::GetPhysicsSolver() const
|
||||
{
|
||||
return m_solver;
|
||||
}
|
||||
|
|
@ -38,23 +57,23 @@ void NzPhysicsWorld::SetFrictionModel(nzFrictionModel model)
|
|||
switch(model)
|
||||
{
|
||||
case nzExact:
|
||||
NewtonSetFrictionModel(this,0);
|
||||
NewtonSetFrictionModel(newtonWorld,0);
|
||||
break;
|
||||
|
||||
case nzAdaptative:
|
||||
NewtonSetFrictionModel(this,1);
|
||||
NewtonSetFrictionModel(newtonWorld,1);
|
||||
break;
|
||||
}
|
||||
|
||||
m_frictionModel = model;
|
||||
}
|
||||
|
||||
const nzFrictionModel& NzPhysicsWorld::GetFrictionModel()
|
||||
const NzPhysicsWorld::nzFrictionModel& NzPhysicsWorld::GetFrictionModel() const
|
||||
{
|
||||
return m_frictionModel;
|
||||
}
|
||||
|
||||
void NzPhysicsWorld::UpdatePhysics(nzUint64 timestep)
|
||||
void NzPhysicsWorld::UpdatePhysics(float timestep)
|
||||
{
|
||||
NewtonUpdate(m_world,static_cast<float>(timestep));//FLOAT WTF ?
|
||||
NewtonUpdate(newtonWorld,timestep);//FLOAT WTF ?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq / Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include "StaticBody.hpp"
|
||||
//#include <Nazara/Physics/StaticBody.hpp>
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzStaticBody::NzStaticBody(NzPhysicsWorld* world, const NzCollisionShape& shape, const NzVector3f& position, float mass) : NzPhysicsEntity(world,shape,position,mass)
|
||||
{
|
||||
//ctor
|
||||
}
|
||||
|
||||
NzStaticBody::~NzStaticBody()
|
||||
{
|
||||
//dtor
|
||||
}
|
||||
Loading…
Reference in New Issue