From 02d3608a8b853a009dfc437dbbfbff72a2393ef2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 10 Jan 2010 12:40:10 +0100 Subject: Only respect floor triangles when picking room --- src/Gui/Renderer/RoomListRenderer.cpp | 2 +- src/View/TopView.cpp | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Gui/Renderer/RoomListRenderer.cpp b/src/Gui/Renderer/RoomListRenderer.cpp index 83b0402..8291c4e 100644 --- a/src/Gui/Renderer/RoomListRenderer.cpp +++ b/src/Gui/Renderer/RoomListRenderer.cpp @@ -38,7 +38,7 @@ void RoomListRenderer::render_vfunc(const Glib::RefPtr &window, G const Gdk::Rectangle &/*background_area*/, const Gdk::Rectangle &cell_area, const Gdk::Rectangle &/*expose_area*/, Gtk::CellRendererState /*flags*/) { - Data::Room *room = reinterpret_cast(value.get_value()); + Data::Room *room = static_cast(value.get_value()); int xpad, ypad; get_padding(xpad, ypad); diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp index 7e649cc..fa894ca 100644 --- a/src/View/TopView.cpp +++ b/src/View/TopView.cpp @@ -236,30 +236,32 @@ void TopView::click(float x, float y, unsigned int button) { vmml::vec2f v(xCenter + x/scale, yCenter + y/scale); - Data::Room *selectedRoom = 0; - const std::list &rooms = instance->getLevel()->getRooms(); for(std::list::const_iterator room = rooms.begin(); room != rooms.end(); ++room) { const std::list& triangles = (*room)->getTriangles(); for(std::list::const_iterator t = triangles.begin(); t != triangles.end(); ++t) { + vmml::vec3f edge1 = (*t)->getVertex(1) - (*t)->getVertex(0); + vmml::vec3f edge2 = (*t)->getVertex(2) - (*t)->getVertex(0); + + vmml::vec3f normal = edge1.cross(edge2); + + if(normal.y() <= 0) + continue; + vmml::vec2f v1((*t)->getVertex(0).x(), (*t)->getVertex(0).z()); vmml::vec2f v2((*t)->getVertex(1).x(), (*t)->getVertex(1).z()); vmml::vec2f v3((*t)->getVertex(2).x(), (*t)->getVertex(2).z()); if(Math::Triangle2D(v1, v2, v3).contains(v)) { - selectedRoom = *room; - break; + instance->setSelectedRoom(*room); + return; } } - - if(selectedRoom) - break; } - - instance->setSelectedRoom(selectedRoom); - signalUpdate().emit(); + + instance->setSelectedRoom(0); } } -- cgit v1.2.3