11 V2BLTerrain::V2BLTerrain() {
16 V2BLTerrain::V2BLTerrain(b2World* world, sf::RenderWindow& window,
config::sTerrain terrainParam,
int WINDOW_X_PX,
double bodyLength)
17 :
Terrain(world, window, terrainParam, WINDOW_X_PX, bodyLength){
18 m_M_TO_PX = WINDOW_X_PX / (2*m_runaway+m_width);
19 m_bottom = m_bodyLength/tan(m_angle);
22 V2BLTerrain::~V2BLTerrain() {
28 m_M_TO_PX = WINDOW_X_PX / (2*m_runaway+m_width);
29 printf(
"m_M_TO_PX: %f, \n", m_M_TO_PX);
30 m_bottom = m_bodyLength/tan(m_angle);
35 m_bottom = m_bodyLength/tan(m_angle);
37 BodyDef.position = b2Vec2(0, 0);
38 BodyDef.type = b2_staticBody;
39 m_groundBody = world->CreateBody(&BodyDef);
41 b2EdgeShape edgeShape;
44 edgeShape.Set( b2Vec2(0,m_posY), b2Vec2(m_runaway,m_posY) );
45 firstR.shape = &edgeShape;
46 m_groundBody->CreateFixture(&firstR);
48 b2FixtureDef firstSlope;
49 edgeShape.Set( b2Vec2(m_runaway,m_posY), b2Vec2(m_runaway+m_width/2-m_bodyLength,m_posY+m_height-m_bottom) );
50 firstSlope.shape = &edgeShape;
51 m_groundBody->CreateFixture(&firstSlope);
54 edgeShape.Set( b2Vec2(m_runaway+m_width/2-m_bodyLength,m_posY+m_height-m_bottom), b2Vec2(m_runaway+m_width/2+m_bodyLength,m_posY+m_height-m_bottom) );
55 bottom.shape = &edgeShape;
56 m_groundBody->CreateFixture(&bottom);
58 b2FixtureDef secondSlope;
59 edgeShape.Set( b2Vec2(m_runaway+m_width/2+m_bodyLength,m_posY+m_height-m_bottom), b2Vec2(m_runaway+m_width,m_posY) );
60 secondSlope.shape = &edgeShape;
61 m_groundBody->CreateFixture(&secondSlope);
64 edgeShape.Set( b2Vec2(m_runaway+m_width,m_posY), b2Vec2(4*m_runaway+m_width,m_posY) );
65 endR.shape = &edgeShape;
66 m_groundBody->CreateFixture(&endR);
68 printf(
"bottom =%f, \n ", m_bottom);
69 printf(
"bodylength =%f, \n ", m_bodyLength);
74 sf::VertexArray lines(sf::LinesStrip, 6);
75 lines[0].position = sf::Vector2f(0, m_posY*m_M_TO_PX);
76 lines[1].position = sf::Vector2f(m_runaway*m_M_TO_PX, m_posY*m_M_TO_PX);
77 lines[2].position = sf::Vector2f((m_runaway+m_width/2-m_bodyLength)*m_M_TO_PX, (m_posY+m_height-m_bottom)*m_M_TO_PX);
78 lines[3].position = sf::Vector2f((m_runaway+m_width/2+m_bodyLength)*m_M_TO_PX, (m_posY+m_height-m_bottom)*m_M_TO_PX);
79 lines[4].position = sf::Vector2f((m_runaway+m_width)*m_M_TO_PX, m_posY*m_M_TO_PX);
80 lines[5].position = sf::Vector2f((2*m_runaway+m_width)*m_M_TO_PX, m_posY*m_M_TO_PX);
82 lines[0].color = sf::Color::Black;
83 lines[1].color = sf::Color::Black;
84 lines[2].color = sf::Color::Black;
85 lines[3].color = sf::Color::Black;
86 lines[4].color = sf::Color::Black;
87 lines[5].color = sf::Color::Black;
94 return b2Vec2(m_runaway, m_posY);
98 return b2Vec2((m_runaway+m_width), m_posY);
102 return b2Vec2((m_runaway+m_width/2), (m_posY+m_height));
b2Vec2 getTopRightCorner()
void createBody(b2World *world)
b2Vec2 getTopLeftCorner()
void drawBody(sf::RenderWindow &window)
void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength=1)
virtual void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)
Implementation of the V2BLTerrain class which inherit from the Terrain class.