3 This file is part of the MSP Märklin suite
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"
17 using namespace Marklin;
19 TrackWrap::TrackWrap(Designer &d, Selection &s):
23 selection.signal_changed.connect(sigc::mem_fun(this, &TrackWrap::selection_changed));
26 void TrackWrap::render(const GL::Tag &) const
28 for(list<Wrap>::const_iterator i=wraps.begin(); i!=wraps.end(); ++i)
30 GL::PushMatrix _pushm;
31 const Point &pos = i->track->get_position();
32 GL::translate(pos.x, pos.y, pos.z);
33 GL::rotate(i->track->get_rotation()*180/M_PI, 0, 0, 1);
38 void TrackWrap::selection_changed()
41 const set<Track *> &tracks = selection.get_tracks();
42 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
46 wrap.mesh = &get_mesh((*i)->get_type());
47 wraps.push_back(wrap);
51 GL::Mesh &TrackWrap::get_mesh(const TrackType &type)
53 map<const TrackType *, GL::Mesh *>::iterator j = meshes.find(&type);
57 const TrackType3D &type3d = designer.get_layout_3d().get_catalogue().get_track(type);
64 for(float a=0; a<M_PI; a+=0.01)
67 type3d.get_bounds(a, minp, maxp);
68 float area = (maxp.x-minp.x)*(maxp.y-minp.y);
69 if(area<min_area || min_area<0)
73 float x = (minp.x+maxp.x)/2;
74 float y = (minp.y+maxp.y)/2;
75 center = Point(c*x-s*y, s*x+c*y, minp.z);
77 width = maxp.x-minp.x+0.01;
78 height = maxp.y-minp.y+0.01;
84 GL::Mesh *mesh = new GL::Mesh((GL::COLOR4_UBYTE, GL::VERTEX2));
85 GL::MeshBuilder bld(*mesh);
86 bld.color(0.0f, 1.0f, 0.0f, 1.0f);
91 bld.begin(GL::LINE_LOOP);
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);
95 bld.vertex(center.x-c*width/2-s*height/2, center.y-s*width/2+c*height/2);