15 Vterrain::Vterrain(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+m_width);
21 Vterrain::~Vterrain() {
27 m_M_TO_PX = WINDOW_X_PX / (2*m_runaway+m_width);
28 printf(
"m_M_TO_PX: %f, \n", m_M_TO_PX);
34 BodyDef.position = b2Vec2(0, 0);
35 BodyDef.type = b2_staticBody;
36 m_groundBody = world->CreateBody(&BodyDef);
38 b2EdgeShape edgeShape;
41 edgeShape.Set( b2Vec2(0,m_posY), b2Vec2(m_runaway,m_posY) );
42 firstR.shape = &edgeShape;
43 m_groundBody->CreateFixture(&firstR);
45 b2FixtureDef firstSlope;
46 edgeShape.Set( b2Vec2(m_runaway,m_posY), b2Vec2(m_runaway+m_width/2,m_posY+m_height) );
47 firstSlope.shape = &edgeShape;
48 m_groundBody->CreateFixture(&firstSlope);
50 b2FixtureDef secondSlope;
51 edgeShape.Set( b2Vec2(m_runaway+m_width/2,m_posY+m_height), b2Vec2(m_runaway+m_width,m_posY) );
52 secondSlope.shape = &edgeShape;
53 m_groundBody->CreateFixture(&secondSlope);
56 edgeShape.Set( b2Vec2(m_runaway+m_width,m_posY), b2Vec2(4*m_runaway+m_width,m_posY) );
57 endR.shape = &edgeShape;
58 m_groundBody->CreateFixture(&endR);
90 sf::VertexArray lines(sf::LinesStrip, 5);
91 lines[0].position = sf::Vector2f(0, m_posY*m_M_TO_PX);
92 lines[1].position = sf::Vector2f(m_runaway*m_M_TO_PX, m_posY*m_M_TO_PX);
93 lines[2].position = sf::Vector2f((m_runaway+m_width/2)*m_M_TO_PX, (m_posY+m_height)*m_M_TO_PX);
94 lines[3].position = sf::Vector2f((m_runaway+m_width)*m_M_TO_PX, m_posY*m_M_TO_PX);
95 lines[4].position = sf::Vector2f((2*m_runaway+m_width)*m_M_TO_PX, m_posY*m_M_TO_PX);
103 lines[0].color = sf::Color::Black;
104 lines[1].color = sf::Color::Black;
105 lines[2].color = sf::Color::Black;
106 lines[3].color = sf::Color::Black;
107 lines[4].color = sf::Color::Black;
114 return b2Vec2(m_runaway, m_posY);
118 return b2Vec2((m_runaway+m_width), m_posY);
122 return b2Vec2((m_runaway+m_width/2), (m_posY+m_height));
125 double Vterrain::getVLength(){
126 double l = distance(m_runaway, m_posY, m_runaway+m_width/2, m_posY+m_height);
127 l += distance(m_runaway+m_width, m_posY, m_runaway+m_width/2, m_posY+m_height);
void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength=1)
void createBody(b2World *world)
void drawBody(sf::RenderWindow &window)
b2Vec2 getTopRightCorner()
virtual void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)
Implementation of the Vterrain class which inherit from the Terrain class.
b2Vec2 getTopLeftCorner()