2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
4 #include <msp/input/keys.h>
5 #include <msp/strings/format.h>
14 Measure::Measure(Designer &d, Input::Keyboard &k, Input::Mouse &m):
17 mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
21 designer.get_layout_3d().get_scene().add(*this);
26 designer.get_layout_3d().get_scene().remove(*this);
40 void Measure::key_press(unsigned key)
42 if(key==Input::KEY_ESC)
48 void Measure::button_press(unsigned btn)
52 start.position = ground_pointer;
53 start.rotation = Angle::zero();
54 snap_to_tracks(start);
62 void Measure::pointer_motion()
65 sn.position = ground_pointer;
67 ground_pointer = sn.position;
71 Vector delta = rotated_vector(ground_pointer-start.position, -start.rotation);
76 adiff = wrap_balanced(sn.rotation-start.rotation+Angle::half_turn());
80 string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", par_dist*1000, perp_dist*1000, delta.norm()*1000, adiff.degrees());
81 signal_status.emit(info);
85 void Measure::render(GL::Renderer &renderer, const GL::Tag &) const
87 GL::Renderer::Push push(renderer);
88 const Vector &pos = (start_pinned ? start.position : ground_pointer);
89 renderer.matrix_stack() *= GL::Matrix::translation(pos);
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);
111 float c = cos(start.rotation);
112 float s = sin(start.rotation);
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(ground_pointer.x-start.position.x, ground_pointer.y-start.position.y, 0);
119 bld.vertex(ground_pointer.x-start.position.x, ground_pointer.y-start.position.y, 0.01);
121 bld.vertex(0, 0, 0.01);
126 void Measure::snap_to_tracks(Snap &sn)
128 const set<Track *> <racks = designer.get_layout().get_all<Track>();
129 for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
130 if((*i)->snap(sn, 0.01, SNAP_NODE))