// -*- c++ -*- #pragma once #ifndef __REFLEX_WORLD_H__ #define __REFLEX_WORLD_H__ #include #include #include #include #include #include #include namespace Reflex { class View; class Body; class DebugDraw; class World : public boost::noncopyable, private b2ContactListener { public: World (View* owner, float pixels_per_meter = 100); ~World (); void step (float dt); Body* create_body (View* owner, const Point& position = 0, float degree = 0); void destroy_body (Body* body); void resize (coord width, coord height); void draw (Painter* painter); float meter2pixel (float meter = 1) const; void set_gravity (const Point& gravity); Point gravity () const; void set_debug (bool state = true); bool debugging () const; Body* wall (); const Body* wall () const; protected: void BeginContact (b2Contact* contact); void EndContact (b2Contact* contact); private: b2World world; float ppm, last_step; Body* wall_; DebugDraw* debug_draw; };// World template inline float32 to_b2coord (T t, float scale) { return t / scale; } template inline b2Vec2 to_b2vec2 (T x, T y, float scale) { return b2Vec2( to_b2coord(x, scale), to_b2coord(y, scale)); } template inline b2Vec2 to_b2vec2 (const VEC& v, float scale) { return b2Vec2( to_b2coord(v.x, scale), to_b2coord(v.y, scale)); } inline coord to_coord (float32 t, float scale) { return t * scale; } inline Coord2 to_coord2 (const b2Vec2& v, float scale) { Coord2 c; c.reset( to_coord(v.x, scale), to_coord(v.y, scale)); return c; } inline Coord3 to_coord3 (const b2Vec2& v, float scale) { Coord3 c; c.reset( to_coord(v.x, scale), to_coord(v.y, scale)); return c; } inline Point to_point (const b2Vec2& v, float scale) { return Point( to_coord(v.x, scale), to_coord(v.y, scale)); } }// Reflex #endif//EOH