]> git.tdb.fi Git - r2c2.git/commitdiff
Convert Measure to a Renderable
authorMikko Rasa <tdb@tdb.fi>
Sun, 20 Jan 2013 11:57:44 +0000 (13:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 20 Jan 2013 11:57:44 +0000 (13:57 +0200)
source/designer/designer.cpp
source/designer/measure.cpp
source/designer/measure.h

index ba7e669134766ace8b7bc93ce5c2331e9684fad0..5811b84d195a7afc82853e22bea6ee0570319d64 100644 (file)
@@ -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
index c4280c8a9c058b637492625f8da7d21d902e1150..f115f9ddd5a287f9f7a14df8f170fc8ef1e346f4 100644 (file)
@@ -1,5 +1,6 @@
 #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"
@@ -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<Track *> &ltracks = 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)
@@ -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<Track *> &ltracks = designer.get_layout().get_tracks();
+       for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
+               if((*i)->snap(pt, dir))
+                       return;
 }
index b991d42be50b30eddc4c39697150565b4b0d9046..84b1c832ea21a646052b05c432e07cdeb0c3da5f 100644 (file)
@@ -2,10 +2,11 @@
 #define MEASURE_H_
 
 #include <sigc++/sigc++.h>
+#include <msp/gl/renderable.h>
 
 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 &);
 };