Push the current work on the Physics2D module

This commit is contained in:
Lynix
2016-10-14 17:07:13 +02:00
parent 080db76ac1
commit 9a7767867b
16 changed files with 883 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <chipmunk/chipmunk.h>
#include <Nazara/Physics2D/Debug.hpp>
namespace Nz
{
PhysWorld2D::PhysWorld2D() :
m_stepSize(0.005f),
m_timestepAccumulator(0.f)
{
m_handle = cpSpaceNew();
cpSpaceSetUserData(m_handle, this);
}
PhysWorld2D::~PhysWorld2D()
{
cpSpaceFree(m_handle);
}
Vector2f PhysWorld2D::GetGravity() const
{
cpVect gravity = cpSpaceGetGravity(m_handle);
return Vector2f(gravity.x, gravity.y);
}
cpSpace* PhysWorld2D::GetHandle() const
{
return m_handle;
}
float PhysWorld2D::GetStepSize() const
{
return m_stepSize;
}
void PhysWorld2D::SetGravity(const Vector2f& gravity)
{
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
}
void PhysWorld2D::SetStepSize(float stepSize)
{
m_stepSize = stepSize;
}
void PhysWorld2D::Step(float timestep)
{
m_timestepAccumulator += timestep;
while (m_timestepAccumulator >= m_stepSize)
{
cpSpaceStep(m_handle, m_stepSize);
m_timestepAccumulator -= m_stepSize;
}
}
}