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"
12 #include "selection.h"
13 #include "trackwrap.h"
19 TrackWrap::TrackWrap(Designer &d, Selection &s):
23 selection.signal_changed.connect(sigc::mem_fun(this, &TrackWrap::selection_changed));
26 TrackWrap::~TrackWrap()
28 for(map<const TrackType *, GL::Mesh *>::iterator i=meshes.begin(); i!=meshes.end(); ++i)
32 void TrackWrap::render(const GL::Tag &) const
34 for(list<Wrap>::const_iterator i=wraps.begin(); i!=wraps.end(); ++i)
36 GL::PushMatrix _pushm;
37 const Point &pos = i->track->get_position();
38 GL::translate(pos.x, pos.y, pos.z);
39 GL::rotate(i->track->get_rotation()*180/M_PI, 0, 0, 1);
44 void TrackWrap::selection_changed()
47 const set<Track *> &tracks = selection.get_tracks();
48 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
52 wrap.mesh = &get_mesh((*i)->get_type());
53 wraps.push_back(wrap);
57 GL::Mesh &TrackWrap::get_mesh(const TrackType &type)
59 map<const TrackType *, GL::Mesh *>::iterator j = meshes.find(&type);
63 const TrackType3D &type3d = designer.get_layout_3d().get_catalogue().get_track(type);
70 for(float a=0; a<M_PI; a+=0.01)
73 type3d.get_bounds(a, minp, maxp);
74 float area = (maxp.x-minp.x)*(maxp.y-minp.y);
75 if(area<min_area || min_area<0)
79 float x = (minp.x+maxp.x)/2;
80 float y = (minp.y+maxp.y)/2;
81 center = Point(c*x-s*y, s*x+c*y, minp.z);
83 width = maxp.x-minp.x+0.01;
84 height = maxp.y-minp.y+0.01;
90 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
91 GL::MeshBuilder bld(*mesh);
92 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
97 bld.begin(GL::LINE_LOOP);
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);
101 bld.vertex(center.x-c*width/2-s*height/2, center.y-s*width/2+c*height/2);
104 meshes[&type] = mesh;