1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
5 #include "selectionwrap.h"
11 SelectionWrap::SelectionWrap(Selection &s):
14 selection.signal_changed.connect(sigc::mem_fun(this, &SelectionWrap::selection_changed));
17 SelectionWrap::~SelectionWrap()
19 for(map<const ObjectType *, GL::Mesh *>::iterator i=meshes.begin(); i!=meshes.end(); ++i)
23 void SelectionWrap::render(GL::Renderer &renderer, const GL::Tag &) const
25 for(list<Wrap>::const_iterator i=wraps.begin(); i!=wraps.end(); ++i)
27 GL::MatrixStack::Push push(renderer.matrix_stack());
28 const Vector &pos = i->object->get_position();
29 renderer.matrix_stack() *= GL::Matrix::translation(pos);
30 renderer.matrix_stack() *= GL::Matrix::rotation(i->object->get_rotation(), 0, 0, 1);
31 i->mesh->draw(renderer);
35 void SelectionWrap::selection_changed()
38 const set<Object *> &objects = selection.get_objects();
39 for(set<Object *>::iterator i=objects.begin(); i!=objects.end(); ++i)
43 wrap.mesh = &get_mesh((*i)->get_type());
44 wraps.push_back(wrap);
48 GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type)
50 map<const ObjectType *, GL::Mesh *>::iterator j = meshes.find(&type);
54 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
55 GL::MeshBuilder bld(*mesh);
56 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
58 const Shape *shape = type.get_shape();
60 throw logic_error("No shape");
62 Geometry::BoundingBox<float, 3> bbox = shape->get_axis_aligned_bounding_box();
63 const Vector &min_pt = bbox.get_minimum_point();
64 const Vector &max_pt = bbox.get_maximum_point();
66 bld.begin(GL::LINE_LOOP);
67 bld.vertex(min_pt.x-0.005, min_pt.y-0.005);
68 bld.vertex(max_pt.x+0.005, min_pt.y-0.005);
69 bld.vertex(max_pt.x+0.005, max_pt.y+0.005);
70 bld.vertex(min_pt.x-0.005, max_pt.y+0.005);