2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
12 Measure::Measure(Designer &d):
15 mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
24 void Measure::button_press(float gx, float gy, unsigned btn)
31 spoint = Vector(gx, gy, 0);
33 snap_to_tracks(spoint, sdir);
52 void Measure::pointer_motion(float gx, float gy)
57 pointer = Vector(gx, gy, 0);
59 snap_to_tracks(pointer, dir);
63 Vector delta(pointer.x-spoint.x, pointer.y-spoint.y, 0);
67 par_dist = delta.x*c+delta.y*s;
68 perp_dist = delta.x*s-delta.y*c;
70 adiff = dir-sdir+M_PI;
78 signal_changed.emit();
82 void Measure::render(GL::Renderer &renderer, const GL::Tag &) const
87 GL::Renderer::Push push(renderer);
88 const Vector &pos = (state==ACTIVE ? spoint : pointer);
89 renderer.matrix_stack() *= GL::Matrix::translation(pos.x, pos.y, pos.z);
94 void Measure::update_mesh()
97 GL::MeshBuilder bld(mesh);
98 bld.color(1.0f, 1.0f, 1.0f, 1.0f);
99 bld.begin(GL::QUAD_STRIP);
100 for(unsigned i=0; i<=16; ++i)
102 float x = cos(i*M_PI/8)*0.005;
103 float y = sin(i*M_PI/8)*0.005;
105 bld.vertex(x, y, 0.01);
113 bld.begin(GL::QUAD_STRIP);
115 bld.vertex(0, 0, 0.01);
116 bld.vertex(c*par_dist, s*par_dist, 0);
117 bld.vertex(c*par_dist, s*par_dist, 0.01);
118 bld.vertex(pointer.x-spoint.x, pointer.y-spoint.y, 0);
119 bld.vertex(pointer.x-spoint.x, pointer.y-spoint.y, 0.01);
121 bld.vertex(0, 0, 0.01);
126 void Measure::snap_to_tracks(Vector &pt, float &dir)
128 const set<Track *> <racks = designer.get_layout().get_tracks();
129 for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
130 if((*i)->snap(pt, dir))