Army ant simulation
Ramp.cpp
1 /*
2  * Ramp.cpp
3  *
4  * Created on: 12 Feb 2019
5  * Author: lucie
6  */
7 
8 #include "Ramp.h"
9 
10 Ramp::Ramp() {
11  // TODO Auto-generated constructor stub
12 
13 }
14 
15 Ramp::Ramp(b2World* world, sf::RenderWindow& window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)
16 : Terrain(world, window, terrainParam, WINDOW_X_PX, bodyLength){
17  m_M_TO_PX = WINDOW_X_PX / (2*m_runaway);
18 }
19 
20 Ramp::~Ramp() {
21  // TODO Auto-generated destructor stub
22 }
23 
24 void Ramp::create(b2World* world, sf::RenderWindow& window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength){
25  Terrain::create(world, window, terrainParam, WINDOW_X_PX, bodyLength);
26  m_M_TO_PX = WINDOW_X_PX / (2*m_runaway);
27  printf("m_M_TO_PX: %f, \n", m_M_TO_PX);
28 }
29 
30 void Ramp::createBody(b2World* world){
31 
32  b2BodyDef BodyDef;
33  BodyDef.position = b2Vec2(0, 0);
34  BodyDef.type = b2_staticBody;
35  m_groundBody = world->CreateBody(&BodyDef);
36 
37  b2EdgeShape edgeShape;
38 
39  b2FixtureDef firstR;
40  edgeShape.Set( b2Vec2(0,m_posY), b2Vec2(m_runaway,m_posY) );
41  firstR.shape = &edgeShape;
42  m_groundBody->CreateFixture(&firstR);
43 
44  b2FixtureDef slope;
45  edgeShape.Set( b2Vec2(m_runaway,m_posY), b2Vec2(m_runaway,m_posY+m_height) );
46  slope.shape = &edgeShape;
47  m_groundBody->CreateFixture(&slope);
48 
49  b2FixtureDef endR;
50  edgeShape.Set( b2Vec2(m_runaway,m_posY+m_height), b2Vec2(3*m_runaway,m_posY+m_height) );
51  endR.shape = &edgeShape;
52  m_groundBody->CreateFixture(&endR);
53 
54 }
55 
56 void Ramp::drawBody(sf::RenderWindow& window){
57  sf::VertexArray lines(sf::LinesStrip, 4);
58  lines[0].position = sf::Vector2f(0, m_posY*m_M_TO_PX);
59  lines[1].position = sf::Vector2f(m_runaway*m_M_TO_PX, m_posY*m_M_TO_PX);
60  lines[2].position = sf::Vector2f(m_runaway*m_M_TO_PX, (m_posY+m_height)*m_M_TO_PX);
61  lines[3].position = sf::Vector2f(2*m_runaway*m_M_TO_PX, (m_posY+m_height)*m_M_TO_PX);
62 
63 
64  lines[0].color = sf::Color::Black;
65  lines[1].color = sf::Color::Black;
66  lines[2].color = sf::Color::Black;
67  lines[3].color = sf::Color::Black;
68 
69  window.draw(lines);
70 }
71 
74  return b2Vec2(m_runaway, m_posY);
75 }
78  return b2Vec2(m_runaway, m_posY);
79 }
81 b2Vec2 Ramp::getBottom(){
82  return b2Vec2((m_runaway), (m_posY+m_height));
83 }
84 
86  return RAMP;
87 }
88 
89 
void createBody(b2World *world)
Definition: Ramp.cpp:30
b2Vec2 getTopLeftCorner()
Definition: Ramp.cpp:73
b2Vec2 getBottom()
Definition: Ramp.cpp:81
void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength=1)
Definition: Ramp.cpp:24
b2Vec2 getTopRightCorner()
Definition: Ramp.cpp:77
Implementation of the Ramp class which inherit from the Terrain class.
e_terrain_type
Definition: Terrain.h:23
void drawBody(sf::RenderWindow &window)
Definition: Ramp.cpp:56
e_terrain_type getType()
Definition: Ramp.cpp:85
virtual void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)
Definition: Terrain.cpp:38