mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-08-27 11:11:26 -04:00
64e6860718
Updated copyrights.
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
/**
|
|
|
|
GDevelop - Physics Automatism Extension
|
|
Copyright (c) 2010-2015 Florian Rival (Florian.Rival@gmail.com)
|
|
This project is released under the MIT License.
|
|
*/
|
|
|
|
#include "RuntimeScenePhysicsDatas.h"
|
|
#include "ScenePhysicsDatas.h"
|
|
#include "ContactListener.h"
|
|
#include "Box2D/Box2D.h"
|
|
#include <iostream>
|
|
|
|
RuntimeScenePhysicsDatas::RuntimeScenePhysicsDatas(const ScenePhysicsDatas & automatismSharedDatas) :
|
|
world(new b2World(b2Vec2(automatismSharedDatas.gravityX, -automatismSharedDatas.gravityY), true)),
|
|
contactListener(new ContactListener),
|
|
staticBody(NULL),
|
|
stepped(false),
|
|
scaleX(automatismSharedDatas.scaleX),
|
|
scaleY(automatismSharedDatas.scaleY),
|
|
invScaleX(1/scaleX),
|
|
invScaleY(1/scaleY),
|
|
fixedTimeStep(1.f / 60.f),
|
|
maxSteps(5),
|
|
totalTime (0)
|
|
{
|
|
world->SetContactListener(contactListener);
|
|
world->SetAutoClearForces(false);
|
|
|
|
b2BodyDef bodyWithoutFixture;
|
|
staticBody = world->CreateBody(&bodyWithoutFixture);
|
|
}
|
|
|
|
void RuntimeScenePhysicsDatas::StepWorld(float dt, int v, int p)
|
|
{
|
|
totalTime += dt;
|
|
|
|
if(totalTime > fixedTimeStep)
|
|
{
|
|
unsigned int numberOfSteps(std::floor(totalTime / fixedTimeStep));
|
|
totalTime -= numberOfSteps * fixedTimeStep;
|
|
|
|
unsigned int numberOfStepToProcess = std::min(numberOfSteps, maxSteps);
|
|
|
|
for(unsigned int a = 0; a < numberOfStepToProcess; a++)
|
|
{
|
|
world->Step(fixedTimeStep, v, p);
|
|
world->ClearForces();
|
|
}
|
|
}
|
|
|
|
//Old method
|
|
/*world->Step(dt, v, p);
|
|
world->ClearForces();*/
|
|
}
|
|
|
|
RuntimeScenePhysicsDatas::~RuntimeScenePhysicsDatas()
|
|
{
|
|
delete world;
|
|
delete contactListener;
|
|
}
|
|
|