1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
3 #include "3d/tracktype.h"
11 TrackWrap::TrackWrap(Layout3D &l, Selection &s):
15 selection.signal_changed.connect(sigc::mem_fun(this, &TrackWrap::selection_changed));
18 TrackWrap::~TrackWrap()
20 for(map<const TrackType *, GL::Mesh *>::iterator i=meshes.begin(); i!=meshes.end(); ++i)
24 void TrackWrap::render(const GL::Tag &) const
26 for(list<Wrap>::const_iterator i=wraps.begin(); i!=wraps.end(); ++i)
28 GL::PushMatrix _pushm;
29 const Vector &pos = i->track->get_position();
30 GL::translate(pos.x, pos.y, pos.z);
31 GL::rotate(i->track->get_rotation()*180/M_PI, 0, 0, 1);
36 void TrackWrap::selection_changed()
39 const set<Track *> &tracks = selection.get_tracks();
40 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
44 wrap.mesh = &get_mesh((*i)->get_type());
45 wraps.push_back(wrap);
49 GL::Mesh &TrackWrap::get_mesh(const TrackType &type)
51 map<const TrackType *, GL::Mesh *>::iterator j = meshes.find(&type);
55 const TrackType3D &type3d = layout.get_catalogue().get_track(type);
62 for(float a=0; a<M_PI; a+=0.01)
65 type3d.get_bounds(a, minp, maxp);
66 float area = (maxp.x-minp.x)*(maxp.y-minp.y);
67 if(area<min_area || min_area<0)
71 float x = (minp.x+maxp.x)/2;
72 float y = (minp.y+maxp.y)/2;
73 center = Vector(c*x-s*y, s*x+c*y, minp.z);
75 width = maxp.x-minp.x+0.01;
76 height = maxp.y-minp.y+0.01;
82 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
83 GL::MeshBuilder bld(*mesh);
84 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
89 bld.begin(GL::LINE_LOOP);
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);
92 bld.vertex(center.x+c*width/2-s*height/2, center.y+s*width/2+c*height/2);
93 bld.vertex(center.x-c*width/2-s*height/2, center.y-s*width/2+c*height/2);