3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gl/matrix.h>
9 #include <msp/gl/meshbuilder.h>
10 #include "3d/tracktype.h"
11 #include "selection.h"
12 #include "trackwrap.h"
18 TrackWrap::TrackWrap(Layout3D &l, Selection &s):
22 selection.signal_changed.connect(sigc::mem_fun(this, &TrackWrap::selection_changed));
25 TrackWrap::~TrackWrap()
27 for(map<const TrackType *, GL::Mesh *>::iterator i=meshes.begin(); i!=meshes.end(); ++i)
31 void TrackWrap::render(const GL::Tag &) const
33 for(list<Wrap>::const_iterator i=wraps.begin(); i!=wraps.end(); ++i)
35 GL::PushMatrix _pushm;
36 const Vector &pos = i->track->get_position();
37 GL::translate(pos.x, pos.y, pos.z);
38 GL::rotate(i->track->get_rotation()*180/M_PI, 0, 0, 1);
43 void TrackWrap::selection_changed()
46 const set<Track *> &tracks = selection.get_tracks();
47 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
51 wrap.mesh = &get_mesh((*i)->get_type());
52 wraps.push_back(wrap);
56 GL::Mesh &TrackWrap::get_mesh(const TrackType &type)
58 map<const TrackType *, GL::Mesh *>::iterator j = meshes.find(&type);
62 const TrackType3D &type3d = layout.get_catalogue().get_track(type);
69 for(float a=0; a<M_PI; a+=0.01)
72 type3d.get_bounds(a, minp, maxp);
73 float area = (maxp.x-minp.x)*(maxp.y-minp.y);
74 if(area<min_area || min_area<0)
78 float x = (minp.x+maxp.x)/2;
79 float y = (minp.y+maxp.y)/2;
80 center = Vector(c*x-s*y, s*x+c*y, minp.z);
82 width = maxp.x-minp.x+0.01;
83 height = maxp.y-minp.y+0.01;
89 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
90 GL::MeshBuilder bld(*mesh);
91 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
96 bld.begin(GL::LINE_LOOP);
97 bld.vertex(center.x-c*width/2+s*height/2, center.y-s*width/2-c*height/2);
98 bld.vertex(center.x+c*width/2+s*height/2, center.y+s*width/2-c*height/2);
99 bld.vertex(center.x+c*width/2-s*height/2, center.y+s*width/2+c*height/2);
100 bld.vertex(center.x-c*width/2-s*height/2, center.y-s*width/2+c*height/2);
103 meshes[&type] = mesh;