10 VStepper::VStepper() {
15 VStepper::VStepper(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 / (4*m_runaway);
22 VStepper::~VStepper() {
28 m_M_TO_PX = WINDOW_X_PX / (3*m_runaway);
29 printf(
"m_M_TO_PX: %f, \n", m_M_TO_PX);
35 BodyDef.position = b2Vec2(0, 0);
36 BodyDef.type = b2_staticBody;
37 m_groundBody = world->CreateBody(&BodyDef);
39 b2EdgeShape edgeShape;
42 edgeShape.Set( b2Vec2(0,m_posY), b2Vec2(m_runaway,m_posY) );
43 firstR.shape = &edgeShape;
44 m_groundBody->CreateFixture(&firstR);
46 b2FixtureDef firstSlope;
47 edgeShape.Set( b2Vec2(m_runaway,m_posY), b2Vec2(m_runaway-m_height/abs(tan(m_angle)),m_posY-m_height) );
48 firstSlope.shape = &edgeShape;
49 m_groundBody->CreateFixture(&firstSlope);
52 edgeShape.Set( b2Vec2(m_runaway-m_height/abs(tan(m_angle)),m_posY-m_height), b2Vec2(m_runaway-m_height/abs(tan(m_angle)),m_posY-1.2*m_height) );
53 corner.shape = &edgeShape;
54 m_groundBody->CreateFixture(&corner);
57 edgeShape.Set( b2Vec2(m_runaway-m_height/abs(tan(m_angle)),m_posY-1.2*m_height), b2Vec2(1.5*m_runaway+m_height/abs(tan(0.7*m_angle)),m_posY-1.2*m_height) );
58 flat.shape = &edgeShape;
59 m_groundBody->CreateFixture(&flat);
62 edgeShape.Set(b2Vec2(1.5*m_runaway+m_height/abs(tan(0.7*m_angle)),m_posY-1.2*m_height), b2Vec2(1.5*m_runaway+m_height/abs(tan(0.7*m_angle)),m_posY-m_height) );
63 corner2.shape = &edgeShape;
64 m_groundBody->CreateFixture(&corner2);
66 b2FixtureDef secondSlope;
67 edgeShape.Set( b2Vec2(1.5*m_runaway+m_height/abs(tan(0.7*m_angle)),m_posY-m_height), b2Vec2(1.5*m_runaway,m_posY) );
68 secondSlope.shape = &edgeShape;
69 m_groundBody->CreateFixture(&secondSlope);
72 edgeShape.Set( b2Vec2(1.5*m_runaway,m_posY), b2Vec2(3*m_runaway,m_posY) );
73 endR.shape = &edgeShape;
74 m_groundBody->CreateFixture(&endR);
79 sf::VertexArray lines(sf::LinesStrip, 8);
80 lines[0].position = sf::Vector2f(0, (m_posY)*m_M_TO_PX);
81 lines[1].position = sf::Vector2f(m_runaway*m_M_TO_PX, (m_posY)*m_M_TO_PX);
82 lines[2].position = sf::Vector2f((m_runaway-m_height/abs(tan(m_angle)))*m_M_TO_PX, (m_posY-m_height)*m_M_TO_PX);
83 lines[3].position = sf::Vector2f((m_runaway-m_height/abs(tan(m_angle)))*m_M_TO_PX, (m_posY-1.2*m_height)*m_M_TO_PX);
84 lines[4].position = sf::Vector2f((1.5*m_runaway+m_height/abs(tan(0.7*m_angle)))*m_M_TO_PX, (m_posY-1.2*m_height)*m_M_TO_PX);
85 lines[5].position = sf::Vector2f((1.5*m_runaway+m_height/abs(tan(0.7*m_angle)))*m_M_TO_PX, (m_posY-m_height)*m_M_TO_PX);
86 lines[6].position = sf::Vector2f((1.5*m_runaway)*m_M_TO_PX, (m_posY)*m_M_TO_PX);
87 lines[7].position = sf::Vector2f((3*m_runaway)*m_M_TO_PX, (m_posY)*m_M_TO_PX);
89 lines[0].color = sf::Color::Black;
90 lines[1].color = sf::Color::Black;
91 lines[2].color = sf::Color::Black;
92 lines[3].color = sf::Color::Black;
93 lines[4].color = sf::Color::Black;
94 lines[5].color = sf::Color::Black;
95 lines[6].color = sf::Color::Black;
96 lines[7].color = sf::Color::Black;
void createBody(b2World *world)
void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength=1)
void drawBody(sf::RenderWindow &window)
virtual void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)