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.x, pos.y, pos.z);
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(float a=0; a<M_PI; a+=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)
72 float x = (minp.x+maxp.x)/2;
73 float y = (minp.y+maxp.y)/2;
74 center = Vector(c*x-s*y, s*x+c*y, minp.z);
76 width = maxp.x-minp.x+0.01;
77 height = maxp.y-minp.y+0.01;
83 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
84 GL::MeshBuilder bld(*mesh);
85 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
90 bld.begin(GL::LINE_LOOP);
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);
94 bld.vertex(center.x-c*width/2-s*height/2, center.y-s*width/2+c*height/2);