1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
4 #include "3d/tracktype.h"
12 TrackWrap::TrackWrap(Layout3D &l, Selection &s):
16 selection.signal_changed.connect(sigc::mem_fun(this, &TrackWrap::selection_changed));
19 TrackWrap::~TrackWrap()
21 for(map<const TrackType *, GL::Mesh *>::iterator i=meshes.begin(); i!=meshes.end(); ++i)
25 void TrackWrap::render(GL::Renderer &renderer, const GL::Tag &) const
27 for(list<Wrap>::const_iterator i=wraps.begin(); i!=wraps.end(); ++i)
29 GL::MatrixStack::Push push(renderer.matrix_stack());
30 const Vector &pos = i->track->get_position();
31 renderer.matrix_stack() *= GL::Matrix::translation(pos);
32 renderer.matrix_stack() *= GL::Matrix::rotation(i->track->get_rotation(), 0, 0, 1);
33 i->mesh->draw(renderer);
37 void TrackWrap::selection_changed()
40 const set<Track *> &tracks = selection.get_objects<Track>();
41 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
45 wrap.mesh = &get_mesh((*i)->get_type());
46 wraps.push_back(wrap);
50 GL::Mesh &TrackWrap::get_mesh(const TrackType &type)
52 map<const TrackType *, GL::Mesh *>::iterator j = meshes.find(&type);
56 const TrackType3D &type3d = layout.get_catalogue().get_track(type);
63 for(Angle a; a<Angle::half_turn(); a+=Angle::from_radians(0.01))
66 type3d.get_bounds(a, minp, maxp);
67 float area = (maxp.x-minp.x)*(maxp.y-minp.y);
68 if(area<min_area || min_area<0)
70 center = rotated_vector((minp+maxp)/2.0f, a);
73 width = maxp.x-minp.x+0.01;
74 height = maxp.y-minp.y+0.01;
80 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
81 GL::MeshBuilder bld(*mesh);
82 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
87 bld.begin(GL::LINE_LOOP);
88 bld.vertex(center.x-c*width/2+s*height/2, center.y-s*width/2-c*height/2);
89 bld.vertex(center.x+c*width/2+s*height/2, center.y+s*width/2-c*height/2);
90 bld.vertex(center.x+c*width/2-s*height/2, center.y+s*width/2+c*height/2);
91 bld.vertex(center.x-c*width/2-s*height/2, center.y-s*width/2+c*height/2);