Army ant simulation
Terrain.h
Go to the documentation of this file.
1 
11 #ifndef TERRAIN_H_
12 #define TERRAIN_H_
13 
14 #include "Box2D/Box2D.h"
15 #include "SFML/Graphics.hpp"
16 #include "SFML/Window.hpp"
17 
18 #include "Config.h"
19 
23 enum e_terrain_type {DEFAULT, V_TERRAIN, V2BL_TERRAIN, RAMP, BOX, V_STEPPER};
24 
25 class Terrain {
26 public:
27  Terrain();
28  Terrain(b2World* world, sf::RenderWindow& window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength=1);
29  virtual ~Terrain();
30 
31  /*Default terrain is linear ground of width 2*m_runaway located at m_posY from the top of the window*/
39  //TODO remove WINDOW_X_PX parameters and deduce it from window with window.getSize().x
40  virtual void create(b2World* world, sf::RenderWindow& window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength);
41 
46  virtual void createBody(b2World* world);
47 
52  virtual void drawBody(sf::RenderWindow& window);
53 
57  virtual e_terrain_type getType();
58 
60  virtual b2Vec2 getTopLeftCorner();
62  virtual b2Vec2 getTopRightCorner();
64  virtual b2Vec2 getBottom();
65 
67  double getVLength(){return 0;};
68 
70  b2Body* getBody();
71 
76  const double getScale();
77 
78 protected:
79  b2Body* m_groundBody; //Pointer on the Box2D body of the terrain
80  double m_bodyLength; //Copy of the body length unit. Used to convert the body length units given by the user to real ones (in m)
81  double m_M_TO_PX; //Scale to do the conversion from real dimensions (m) to simulated ones (pixels)
82  double m_width; //Width of the terrain when it makes sense. In the case of the default terrain it doesn't represent an actual dimension
83  double m_height; //Height of the terrain. In the case of the default terrain it doesn't represent an actual dimension.
84  double m_runaway; //Runaway of the terrain. In the case of the default terrain the length of the ground is of 3*m_runaway (with the width of the window of 2*m_runaway)
85  double m_angle; //Angle of the obstacle in the terrain. In the case of the default terrain it doesn't make sense and is set to 0
86  double m_posY=2.5; //In the case of the default terrain it represents the distance from the top of the window/world to the ground.
87 
88  config::sTerrain m_terrainParam; //Terrain configuration parameters described in Config.h file
89 };
90 
91 #endif /* TERRAIN_H_ */
virtual e_terrain_type getType()
Definition: Terrain.cpp:92
virtual b2Vec2 getTopRightCorner()
Definition: Terrain.cpp:97
virtual void drawBody(sf::RenderWindow &window)
Definition: Terrain.cpp:73
virtual void createBody(b2World *world)
Definition: Terrain.cpp:57
const double getScale()
Definition: Terrain.cpp:88
e_terrain_type
Definition: Terrain.h:23
virtual b2Vec2 getBottom()
Definition: Terrain.cpp:98
virtual b2Vec2 getTopLeftCorner()
Definition: Terrain.cpp:96
Implementation of the Configuration class used to parse the configuration file and the sConfig struct...
b2Body * getBody()
Definition: Terrain.cpp:84
virtual void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)
Definition: Terrain.cpp:38
double getVLength()
Definition: Terrain.h:67