From: Mikko Rasa Date: Sun, 20 Jan 2013 11:57:44 +0000 (+0200) Subject: Convert Measure to a Renderable X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c4a5973cff25a0dcdce11c0cbdf8e0fdc1ef4659;p=r2c2.git Convert Measure to a Renderable --- diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index ba7e669..5811b84 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -138,6 +138,7 @@ Designer::Designer(int argc, char **argv): pipeline->add_renderable_for_pass(*track_wrap, "unlit"); overlay = new Overlay3D(ui_res.get_default_font()); pipeline->add_renderable_for_pass(*overlay, "overlay"); + pipeline->add_renderable_for_pass(measure, "unlit"); camera_ctl = new CameraController(*main_view, keyboard, mouse); cat_view->get_camera().set_look_direction(GL::Vector3(0, 0.13053, -0.99144)); @@ -508,11 +509,6 @@ void Designer::render() View3D *view = (mode==CATALOGUE ? cat_view : main_view); view->render(); - if(mode==MEASURE) - { - GL::Bind bind_depth(GL::DepthTest::lequal()); - measure.render(); - } root.render(); // XXX Should fix GLtk so this would not be needed diff --git a/source/designer/measure.cpp b/source/designer/measure.cpp index c4280c8..f115f9d 100644 --- a/source/designer/measure.cpp +++ b/source/designer/measure.cpp @@ -1,5 +1,6 @@ #include -#include +#include +#include #include "designer.h" #include "3d/layout.h" #include "measure.h" @@ -10,20 +11,14 @@ using namespace Msp; 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 <racks = designer.get_layout().get_tracks(); - for(set::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) @@ -42,7 +37,10 @@ void Measure::button_press(float gx, float gy, unsigned btn) else if(btn==3) { if(state==ACTIVE) + { state = STARTING; + update_mesh(); + } else { state = NONE; @@ -75,47 +73,60 @@ void Measure::pointer_motion(float gx, float gy) 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 <racks = designer.get_layout().get_tracks(); + for(set::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) + if((*i)->snap(pt, dir)) + return; } diff --git a/source/designer/measure.h b/source/designer/measure.h index b991d42..84b1c83 100644 --- a/source/designer/measure.h +++ b/source/designer/measure.h @@ -2,10 +2,11 @@ #define MEASURE_H_ #include +#include class Designer; -class Measure +class Measure: public Msp::GL::Renderable { private: enum State @@ -28,6 +29,7 @@ private: float perp_dist; float adiff; State state; + Msp::GL::Mesh mesh; public: Measure(Designer &); @@ -37,8 +39,9 @@ public: void start(); void button_press(float, float, unsigned); void pointer_motion(float, float); - void render(); + virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const; private: + void update_mesh(); void snap_to_tracks(R2C2::Vector &, float &); };