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 ssnap.position = Vector(gx, gy, 0);
33 snap_to_tracks(ssnap);
52 void Measure::pointer_motion(float gx, float gy)
58 sn.position = Vector(gx, gy, 0);
60 pointer = sn.position;
64 Vector delta(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0);
65 float c = cos(ssnap.rotation);
66 float s = sin(ssnap.rotation);
68 par_dist = delta.x*c+delta.y*s;
69 perp_dist = delta.x*s-delta.y*c;
71 adiff = sn.rotation-ssnap.rotation+M_PI;
79 signal_changed.emit();
83 void Measure::render(GL::Renderer &renderer, const GL::Tag &) const
88 GL::Renderer::Push push(renderer);
89 const Vector &pos = (state==ACTIVE ? ssnap.position : pointer);
90 renderer.matrix_stack() *= GL::Matrix::translation(pos.x, pos.y, pos.z);
95 void Measure::update_mesh()
98 GL::MeshBuilder bld(mesh);
99 bld.color(1.0f, 1.0f, 1.0f, 1.0f);
100 bld.begin(GL::QUAD_STRIP);
101 for(unsigned i=0; i<=16; ++i)
103 float x = cos(i*M_PI/8)*0.005;
104 float y = sin(i*M_PI/8)*0.005;
106 bld.vertex(x, y, 0.01);
112 float c = cos(ssnap.rotation);
113 float s = sin(ssnap.rotation);
114 bld.begin(GL::QUAD_STRIP);
116 bld.vertex(0, 0, 0.01);
117 bld.vertex(c*par_dist, s*par_dist, 0);
118 bld.vertex(c*par_dist, s*par_dist, 0.01);
119 bld.vertex(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0);
120 bld.vertex(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0.01);
122 bld.vertex(0, 0, 0.01);
127 void Measure::snap_to_tracks(Snap &sn)
129 const set<Track *> <racks = designer.get_layout().get_tracks();
130 for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
131 if((*i)->snap(sn, 0.01, SNAP_NODE))