diff --git a/include/simul/element.h b/include/simul/element.h index 200d84086c379be9cdc4b10d256698b3adfe0462..c6f63feec4776794ff1e74ea7235193bc989797e 100644 --- a/include/simul/element.h +++ b/include/simul/element.h @@ -3,7 +3,7 @@ #include "Position.h" #include <QPainter> -#include "Box2D/Box2D.h" +#include "Box2D.h" class Element { diff --git a/include/simul/robot.h b/include/simul/robot.h index ebeaaf53f99696fd3d79ff499ba6721ad8351bec..ff9a99cddbd0681a1ec28c70585504a4cf47ef0b 100644 --- a/include/simul/robot.h +++ b/include/simul/robot.h @@ -5,7 +5,7 @@ #include <QKeyEvent> #include <boost/circular_buffer.hpp> #include "PositionPlusAngle.h" -#include <Box2D/Box2D.h> +#include <Box2D.h> class Robot { diff --git a/include/simul/table.h b/include/simul/table.h index 65b4a4a672e5f823e2c7197c3ee314cd21443a7c..47fc1ff6484feb7ce10f4e3a8d937be76519f01d 100644 --- a/include/simul/table.h +++ b/include/simul/table.h @@ -3,7 +3,7 @@ #include <QWidget> #include "element.h" -#include <Box2D/Box2D.h> +#include <Box2D.h> class Table : public QWidget { @@ -20,6 +20,7 @@ public: static const int tableWidth = 3000; static const int tableHeight = 2100; + static b2AABB getWorldAABB(); //static const int tableWidth = 2100; //static const int tableHeight = 3000; diff --git a/simulation/configure.ac b/simulation/configure.ac index f352465ec447ed6cbfbff815b40aff7762380d33..91daaf0b4ee8e233f39a8e39443d79232d05e86d 100644 --- a/simulation/configure.ac +++ b/simulation/configure.ac @@ -23,7 +23,7 @@ AX_BOOST_BASE([1.40], [AC_MSG_RESULT(yes) ] , [AC_MSG_RESULT(no) ] ) CXXFLAGS= -AX_DEP_CHECK(Box2D, [/usr/lib /usr/local/lib], libBox2D.so,[/usr/include /usr/local/include],Box2D/Box2D.h, -lBox2D) +AX_DEP_CHECK(Box2D, [/usr/lib /usr/local/lib], libbox2d.so,[/usr/include /usr/local/include],Box2D.h, -lbox2d) AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug],[Turn on debugging]), [enable_debug=$enableval],[enable_debug="no"]) AC_MSG_CHECKING(debug) diff --git a/src/simul/element.cpp b/src/simul/element.cpp index 951d0abf40e2c39d4b63e69bafb8a7bae3e7b4b4..26b6b13bf8116f4f210c201b4903a674c5a6f4da 100644 --- a/src/simul/element.cpp +++ b/src/simul/element.cpp @@ -7,20 +7,18 @@ Element::Element(b2World & world, Position p, Type t) multiplier = 0; b2BodyDef bodyDef; - bodyDef.type = b2_dynamicBody; + //bodyDef.type = b2_dynamicBody; bodyDef.position.Set(p.x/100., p.y/100.); body = world.CreateBody(&bodyDef); - b2CircleShape circle; - circle.m_p.Set(0.,0.); - circle.m_radius = 1.0f; + b2CircleDef circleDef; + circleDef.radius = 1.0f; + circleDef.localPosition.Set(0.,0.); - b2FixtureDef fixtureDef; - fixtureDef.shape = &circle; - fixtureDef.density = 1.0f; - fixtureDef.friction = 0.4f; - body->CreateFixture(&fixtureDef); + circleDef.density = 1.0f; + circleDef.friction = 0.4f; + body->CreateShape(&circleDef); } void Element::updatePos() diff --git a/src/simul/robot.cpp b/src/simul/robot.cpp index b14c6e8f0f0637ae0f841a7806d9fa952f54cde5..8cf705f9cddd2c21d6f2f3946454613939efbb49 100644 --- a/src/simul/robot.cpp +++ b/src/simul/robot.cpp @@ -60,20 +60,17 @@ Robot::Robot(b2World & world) : olds(10000) asservissement->strategie = strategie; b2BodyDef bodyDef; - bodyDef.type = b2_dynamicBody; bodyDef.position.Set(pos.position.x/100., pos.position.y/100.); bodyDef.angle = pos.angle.getValueInRadian(); body = world.CreateBody(&bodyDef); - b2PolygonShape box; + b2PolygonDef box; box.SetAsBox(1.,1., b2Vec2(1,1),0); - b2FixtureDef fixtureDef; - fixtureDef.shape = &box; - fixtureDef.density = 10.0f; - fixtureDef.friction = 1.0f; - body->CreateFixture(&fixtureDef); + box.density = 10.0f; + box.friction = 1.0f; + body->CreateShape(&box); } void Robot::updateForces(int dt) diff --git a/src/simul/table.cpp b/src/simul/table.cpp index a9a8450e81cf6291d5ea055252cf856dfbd8ce05..4911400e50cdd74a73a66a5c91412587ac73b89c 100644 --- a/src/simul/table.cpp +++ b/src/simul/table.cpp @@ -13,7 +13,15 @@ Position getCaseCenter(unsigned int i, unsigned int j) return Position(625 + i*350, 175 + j*350); } -Table::Table(QWidget* parent) : QWidget(parent), world(b2Vec2(0.f,0.f), false) +b2AABB Table::getWorldAABB() +{ + b2AABB a; + a.lowerBound.Set(-100,-100); + a.upperBound.Set(tableWidth+100, tableHeight+100); + return a; +} + +Table::Table(QWidget* parent) : QWidget(parent), world(getWorldAABB(),b2Vec2(0.f,0.f), false) { dt=0; setAutoFillBackground(true); @@ -31,45 +39,43 @@ Table::Table(QWidget* parent) : QWidget(parent), world(b2Vec2(0.f,0.f), false) tableBody = world.CreateBody(&bodyDef); - b2PolygonShape box; - b2FixtureDef fixtureDef; - fixtureDef.shape = &box; - fixtureDef.friction = 0.5; - fixtureDef.density = 0; + b2PolygonDef box; + box.friction = 0.5; + box.density = 0; box.SetAsBox(30,1, b2Vec2(0,-1),0); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(1,21, b2Vec2(-1,0),0); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(1,21, b2Vec2(31,0),0); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(30.,1., b2Vec2(0,22),0); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); //Starting zones borders box.SetAsBox(4.00,.11, b2Vec2(0.,4.), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(4.00,.11, b2Vec2(30.,4.), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); //Blocked zones box.SetAsBox(3.50,1.20, b2Vec2(8,21), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(3.50,1.20, b2Vec2(22,21), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(.11,0.65, b2Vec2(4.61,19.15), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(.11,0.65, b2Vec2(18.61,19.15), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(.11,0.65, b2Vec2(11.39,19.15), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); box.SetAsBox(.11,0.64, b2Vec2(25.39,19.15), 0.); - tableBody->CreateFixture(&fixtureDef); + tableBody->CreateShape(&box); //Init position of elements int l1 = rand() % 20; @@ -96,8 +102,8 @@ void Table::update(int dt) for(unsigned int i=0; i < robots.size(); i++) robots[i]->updateForces(dt); - world.Step((float)dt/1000., 10, 10); - world.ClearForces(); + world.Step((float)dt/1000., 10); + //world.ClearForces(); for(unsigned int i=0; i < elements.size(); i++) elements[i]->updatePos(); repaint();