#include <cmath>
-#include <GL/gl.h>
+#include <msp/gl/meshbuilder.h>
+#include <msp/gl/renderer.h>
#include "designer.h"
#include "3d/layout.h"
#include "measure.h"
Measure::Measure(Designer &d):
designer(d),
- state(NONE)
+ state(NONE),
+ mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
{ }
void Measure::start()
{
state = STARTING;
-}
-
-void Measure::snap_to_tracks(Vector &pt, float &dir)
-{
- const set<Track *> <racks = designer.get_layout().get_tracks();
- for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
- if((*i)->snap(pt, dir))
- return;
+ update_mesh();
}
void Measure::button_press(float gx, float gy, unsigned btn)
else if(btn==3)
{
if(state==ACTIVE)
+ {
state = STARTING;
+ update_mesh();
+ }
else
{
state = NONE;
while(adiff>M_PI)
adiff -= M_PI*2;
+ update_mesh();
+
signal_changed.emit();
}
}
-void Measure::render()
+void Measure::render(GL::Renderer &renderer, const GL::Tag &) const
{
- glPushMatrix();
- if(state==ACTIVE)
- glTranslatef(spoint.x, spoint.y, spoint.z);
- else if(state==STARTING)
- glTranslatef(pointer.x, pointer.y, pointer.z);
+ if(state==NONE)
+ return;
+
+ GL::Renderer::Push push(renderer);
+ const Vector &pos = (state==ACTIVE ? spoint : pointer);
+ renderer.matrix_stack() *= GL::Matrix::translation(pos.x, pos.y, pos.z);
+
+ mesh.draw(renderer);
+}
- glDisable(GL_CULL_FACE);
- glColor4f(1, 1, 1, 1);
- glBegin(GL_QUAD_STRIP);
+void Measure::update_mesh()
+{
+ mesh.clear();
+ GL::MeshBuilder bld(mesh);
+ bld.color(1.0f, 1.0f, 1.0f, 1.0f);
+ bld.begin(GL::QUAD_STRIP);
for(unsigned i=0; i<=16; ++i)
{
float x = cos(i*M_PI/8)*0.005;
float y = sin(i*M_PI/8)*0.005;
- glVertex3f(x, y, 0);
- glVertex3f(x, y, 0.01);
+ bld.vertex(x, y, 0);
+ bld.vertex(x, y, 0.01);
}
- glEnd();
+ bld.end();
if(state==ACTIVE)
{
float c = cos(sdir);
float s = sin(sdir);
- glBegin(GL_QUAD_STRIP);
- glVertex3f(0, 0, 0);
- glVertex3f(0, 0, 0.01);
- glVertex3f(c*par_dist, s*par_dist, 0);
- glVertex3f(c*par_dist, s*par_dist, 0.01);
- glVertex3f(pointer.x-spoint.x, pointer.y-spoint.y, 0);
- glVertex3f(pointer.x-spoint.x, pointer.y-spoint.y, 0.01);
- /*glVertex3f(s*perp_dist, -c*perp_dist, 0);
- glVertex3f(s*perp_dist, -c*perp_dist, 0.01);*/
- glVertex3f(0, 0, 0);
- glVertex3f(0, 0, 0.01);
- glEnd();
+ bld.begin(GL::QUAD_STRIP);
+ bld.vertex(0, 0, 0);
+ bld.vertex(0, 0, 0.01);
+ bld.vertex(c*par_dist, s*par_dist, 0);
+ bld.vertex(c*par_dist, s*par_dist, 0.01);
+ bld.vertex(pointer.x-spoint.x, pointer.y-spoint.y, 0);
+ bld.vertex(pointer.x-spoint.x, pointer.y-spoint.y, 0.01);
+ bld.vertex(0, 0, 0);
+ bld.vertex(0, 0, 0.01);
+ bld.end();
}
+}
- glPopMatrix();
+void Measure::snap_to_tracks(Vector &pt, float &dir)
+{
+ const set<Track *> <racks = designer.get_layout().get_tracks();
+ for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
+ if((*i)->snap(pt, dir))
+ return;
}