From e8601b35b601b0ee1486dfaa12385e71b7f2b300 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Mon, 21 Oct 2024 15:37:31 +0200 Subject: WIP quadtree visualization scaffolding --- ViewController.cpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'ViewController.cpp') diff --git a/ViewController.cpp b/ViewController.cpp index d64ec35..d336b9c 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -1,4 +1,7 @@ +#include + #include "ViewController.h" +#include "QuadTree.h" #include "ToggleArtistVisibilityCommand.h" #include "Exception.h" #include "KeyboardCode.h" @@ -10,6 +13,8 @@ #include "View.h" #include "Museum.h" +using namespace std; + ViewController::ViewController(Museum & m, View & v) : museum(m), view(v) { } @@ -36,10 +41,10 @@ void ViewController::update_tiles() { for (unsigned x = 0; x < this->museum.canvas.data.columns; x++) { Tile & tile = this->museum.canvas.get_tile(x, y); Rectangle rect = { - .x = x * scale, - .y = y * scale, - .width = scale - line_width, - .height = scale - line_width, + .x = static_cast(x * scale), + .y = static_cast(y * scale), + .width = static_cast(scale - line_width), + .height = static_cast(scale - line_width), }; this->view.fill_rect(rect, tile.color); } @@ -50,10 +55,10 @@ void ViewController::update_artists() { People & people = this->museum.people; for (Artist * artist : people.get_artists()) { Rectangle rect = { - .x = static_cast(artist->data.x * scale), - .y = static_cast(artist->data.y * scale), - .width = artist_size, - .height = artist_size, + .x = static_cast(artist->data.x * scale), + .y = static_cast(artist->data.y * scale), + .width = static_cast(artist_size), + .height = static_cast(artist_size), }; this->view.fill_rect(rect, artist->color); } @@ -62,7 +67,26 @@ void ViewController::update_artists() { void ViewController::update_pathfinding() { } +void ViewController::update_quadtree_recursive(QuadTree * tree) { + if (tree == nullptr) return; + + Rectangle rect = { + .x = tree->boundary.x * scale, + .y = tree->boundary.y * scale, + .width = tree->boundary.width * scale, + .height = tree->boundary.height * scale, + }; + this->view.draw_rect(rect, { .red = 0xff, .green = 0x00, .blue = 0xff, }, 2); + + this->update_quadtree_recursive(tree->subtree[0].get()); + this->update_quadtree_recursive(tree->subtree[1].get()); + this->update_quadtree_recursive(tree->subtree[2].get()); + this->update_quadtree_recursive(tree->subtree[3].get()); +} + void ViewController::update_quadtree() { + shared_ptr tree = this->museum.collision.get_quadtree(); + this->update_quadtree_recursive(tree.get()); } void ViewController::ev_keydown(KeyboardCode key) { -- cgit v1.2.3