2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
4 #include <msp/strings/format.h>
13 Measure::Measure(Designer &d, Input::Mouse &m, const set<Object *> &):
16 mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
20 designer.get_layout_3d().get_scene().add(*this);
25 designer.get_layout_3d().get_scene().remove(*this);
28 void Measure::button_press(unsigned btn)
32 start.position = ground_pointer;
33 start.rotation = Angle::zero();
34 snap_to_tracks(start);
50 void Measure::pointer_motion()
53 sn.position = ground_pointer;
55 ground_pointer = sn.position;
59 Vector delta = rotated_vector(ground_pointer-start.position, -start.rotation);
64 adiff = wrap_balanced(sn.rotation-start.rotation+Angle::half_turn());
68 string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", par_dist*1000, perp_dist*1000, delta.norm()*1000, adiff.degrees());
69 signal_status.emit(info);
73 void Measure::render(GL::Renderer &renderer, const GL::Tag &) const
75 GL::Renderer::Push push(renderer);
76 const Vector &pos = (start_pinned ? start.position : ground_pointer);
77 renderer.matrix_stack() *= GL::Matrix::translation(pos);
82 void Measure::update_mesh()
85 GL::MeshBuilder bld(mesh);
86 bld.color(1.0f, 1.0f, 1.0f, 1.0f);
87 bld.begin(GL::QUAD_STRIP);
88 for(unsigned i=0; i<=16; ++i)
90 float x = cos(i*M_PI/8)*0.005;
91 float y = sin(i*M_PI/8)*0.005;
93 bld.vertex(x, y, 0.01);
99 float c = cos(start.rotation);
100 float s = sin(start.rotation);
101 bld.begin(GL::QUAD_STRIP);
103 bld.vertex(0, 0, 0.01);
104 bld.vertex(c*par_dist, s*par_dist, 0);
105 bld.vertex(c*par_dist, s*par_dist, 0.01);
106 bld.vertex(ground_pointer.x-start.position.x, ground_pointer.y-start.position.y, 0);
107 bld.vertex(ground_pointer.x-start.position.x, ground_pointer.y-start.position.y, 0.01);
109 bld.vertex(0, 0, 0.01);
114 void Measure::snap_to_tracks(Snap &sn)
116 const set<Track *> <racks = designer.get_layout().get_all<Track>();
117 for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
118 if((*i)->snap(sn, 0.01, SNAP_NODE))