diff options
Diffstat (limited to 'src/View')
-rw-r--r-- | src/View/TopView.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
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<Data::Room*> &rooms = instance->getLevel()->getRooms(); for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) { const std::list<Data::Triangle*>& triangles = (*room)->getTriangles(); for(std::list<Data::Triangle*>::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); } } |