From 3d9865f1b74321baa2161b0e240bb538a3b0f7c5 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 21 Aug 2010 15:21:26 +0100 Subject: [PATCH] Implement get_covers for GenTrack --- src/Game.cpp | 8 ++++---- src/GenTrack.cpp | 16 ++++++++++++++++ src/Map.cpp | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index ab93759..14c92e7 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -56,7 +56,7 @@ private: void near_station(IStationPtr s); void left_station(); Vector camera_position(float a_radius) const; - void switch_to_birdCamera(); + void switch_to_bird_camera(); void stopped_at_station(); enum TrackStateReq { NEXT, PREV }; @@ -103,7 +103,7 @@ Game::Game(IMapPtr a_map) render_stats = make_render_stats(layout, "/fps/fps_label"); // Intial camera state is floating but in the bird position - switch_to_birdCamera(); + switch_to_bird_camera(); camera_mode = CAMERA_FLOATING; } @@ -125,7 +125,7 @@ Vector Game::camera_position(float a_radius) const return position; } -void Game::switch_to_birdCamera() +void Game::switch_to_bird_camera() { camera_mode = CAMERA_BIRD; @@ -353,7 +353,7 @@ void Game::on_key_down(SDLKey a_key) break; case SDLK_TAB: if (camera_mode == CAMERA_FLOATING) - switch_to_birdCamera(); + switch_to_bird_camera(); else camera_mode = CAMERA_FLOATING; break; diff --git a/src/GenTrack.cpp b/src/GenTrack.cpp index 6845064..604c63e 100644 --- a/src/GenTrack.cpp +++ b/src/GenTrack.cpp @@ -178,6 +178,8 @@ void GenTrack::merge(IMeshBufferPtr buf) const void GenTrack::render() const { +#if 0 + // Draw the bounding polygon glPushMatrix(); glTranslatef(origin.x, 0.0f, origin.y); @@ -191,6 +193,7 @@ void GenTrack::render() const glEnd(); glPopMatrix(); +#endif } void GenTrack::set_origin(int x, int y, float h) @@ -246,7 +249,20 @@ void GenTrack::get_endpoints(vector >& output) const void GenTrack::get_covers(vector >& output) const { + const Point off = make_point(0.5f, 0.5f); + for (int x = min(0, delta.x); x <= max(0, delta.x) + 1; x++) { + for (int y = min(0, delta.y); y <= max(0, delta.y) + 1; y++) { + Point p = make_point(x, y); + + const bool is_origin = p == make_point(0, 0); + const bool is_delta = p == make_point(delta.x, delta.y); + + if (point_in_polygon(bounds, point_cast(p) + off) + && !(is_origin || is_delta)) + output.push_back(p + origin); + } + } } bool GenTrack::point_in_polygon(const Polygon& poly, Point p) diff --git a/src/Map.cpp b/src/Map.cpp index 19a70a0..713c6e3 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -884,7 +884,7 @@ void Map::render_sector(IGraphicsPtr a_context, int id, make_colour(0.4f, 0.7f, 0.1f))); #endif -#if 1 +#if 0 // Draw vertices covered by track vector > vertices; tile.track->get()->get_height_locked(vertices); -- 2.39.2