Forgot to commit src files and Newton headers in previous commit
This commit is contained in:
57
src/Nazara/Physics/Physics.cpp
Normal file
57
src/Nazara/Physics/Physics.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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 <Nazara/Physics/Physics.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics/Debug.hpp>
|
||||
|
||||
NzPhysics::NzPhysics()
|
||||
{
|
||||
}
|
||||
|
||||
NzPhysics::~NzPhysics()
|
||||
{
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
bool NzPhysics::Initialize()
|
||||
{
|
||||
#if NAZARA_PHYSICS_SAFE
|
||||
if (s_initialized)
|
||||
{
|
||||
NazaraError("Physics already initialized");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzPhysics::Uninitialize()
|
||||
{
|
||||
#if NAZARA_PHYSICS_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("Physics not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Libération du module
|
||||
|
||||
s_initialized = false;
|
||||
}
|
||||
|
||||
bool NzPhysics::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
}
|
||||
|
||||
bool NzPhysics::s_initialized = false;
|
||||
46
src/Nazara/Physics/PhysicsSolver.cpp
Normal file
46
src/Nazara/Physics/PhysicsSolver.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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 "PhysicsSolver.hpp"
|
||||
//#include <Nazara/Physics/PhysicsSolver.hpp>
|
||||
#include <Newton/Newton.h>
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzPhysicsSolver::NzPhysicsSolver(nzSolverMode mode, unsigned int numberOfPassesLinearMode)
|
||||
{
|
||||
m_mode = mode;
|
||||
m_numberOfPassesLinearMode = numberOfPassesLinearMode;
|
||||
}
|
||||
|
||||
void NzPhysicsSolver::Configure(nzSolverMode mode, unsigned int numberOfPassesLinearMode)
|
||||
{
|
||||
m_mode = mode;
|
||||
m_numberOfPassesLinearMode = numberOfPassesLinearMode;
|
||||
}
|
||||
|
||||
void NzPhysicsSolver::Set(NzPhysicsWorld* world)
|
||||
{
|
||||
switch(m_mode)
|
||||
{
|
||||
case nzExact:
|
||||
NewtonSetSolverModel(world, 0);
|
||||
break;
|
||||
|
||||
case nzAdaptative:
|
||||
NewtonSetSolverModel(world, 1);
|
||||
break;
|
||||
|
||||
case nzLinear:
|
||||
NewtonSetSolverModel(world, m_numberOfPassesLinearMode);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
NzPhysicsSolver::~NzPhysicsSolver()
|
||||
{
|
||||
//dtor
|
||||
}
|
||||
60
src/Nazara/Physics/PhysicsWorld.cpp
Normal file
60
src/Nazara/Physics/PhysicsWorld.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// 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 "PhysicsSolver.hpp"
|
||||
//#include <Nazara/Physics/PhysicsSolver.hpp>
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzPhysicsWorld::NzPhysicsWorld()
|
||||
{
|
||||
m_world = NewtonCreate();
|
||||
m_solver.Configure(nzLinear,10);
|
||||
m_solver.Set(this);
|
||||
SetFrictionModel(nzAdaptative);
|
||||
}
|
||||
|
||||
NzPhysicsWorld::~NzPhysicsWorld()
|
||||
{
|
||||
NewtonDestroy(m_world);
|
||||
}
|
||||
|
||||
void NzPhysicsWorld::SetPhysicsSolverSolver(const NzPhysicsSolver& solver)
|
||||
{
|
||||
m_solver = solver;
|
||||
m_solver.Set(this);
|
||||
}
|
||||
|
||||
const nzSolverMode& NzPhysicsWorld::GetPhysicsSolver()
|
||||
{
|
||||
return m_solver;
|
||||
}
|
||||
|
||||
void NzPhysicsWorld::SetFrictionModel(nzFrictionModel model)
|
||||
{
|
||||
switch(model)
|
||||
{
|
||||
case nzExact:
|
||||
NewtonSetFrictionModel(this,0);
|
||||
break;
|
||||
|
||||
case nzAdaptative:
|
||||
NewtonSetFrictionModel(this,1);
|
||||
break;
|
||||
}
|
||||
|
||||
m_frictionModel = model;
|
||||
}
|
||||
|
||||
const nzFrictionModel& NzPhysicsWorld::GetFrictionModel()
|
||||
{
|
||||
return m_frictionModel;
|
||||
}
|
||||
|
||||
void NzPhysicsWorld::UpdatePhysics(nzUint64 timestep)
|
||||
{
|
||||
NewtonUpdate(m_world,static_cast<float>(timestep));//FLOAT WTF ?
|
||||
}
|
||||
Reference in New Issue
Block a user