diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2013-01-06 15:51:44 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2013-01-06 15:51:44 +0000 |
commit | 34d2404010821f92296b15eb9dca6f8fd1bcafdf (patch) | |
tree | a42d220710ecafbdabc85015b19e78a9fe13431e /src | |
parent | 66a35d2b466e75604eeaa42b6ff0dfd0e19d2c3b (diff) | |
download | 2013-gpudataviz-34d2404010821f92296b15eb9dca6f8fd1bcafdf.tar.gz 2013-gpudataviz-34d2404010821f92296b15eb9dca6f8fd1bcafdf.tar.bz2 2013-gpudataviz-34d2404010821f92296b15eb9dca6f8fd1bcafdf.zip |
Ajout gestion de la camera avec le clic-milieu
git-svn-id: file:///var/svn/2013-gpudataviz/trunk@5 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d
Diffstat (limited to 'src')
-rw-r--r-- | src/gpudataviz.cc | 76 | ||||
-rw-r--r-- | src/my_gtk_gl_scene_widget.h | 2 |
2 files changed, 50 insertions, 28 deletions
diff --git a/src/gpudataviz.cc b/src/gpudataviz.cc index eef7e5c..954ef5e 100644 --- a/src/gpudataviz.cc +++ b/src/gpudataviz.cc @@ -62,6 +62,7 @@ MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr<Gdk::GL::Config> &glconfig) set_gl_capability(glconfig); Gdk::EventMask mask = Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK; set_events(mask); // The containing window should have those attributes too + this->camera.rx = this->camera.ry = 0.0f; this->camera.tz = -3.0f; } MyGTKGLSceneWidget::~MyGTKGLSceneWidget() { } @@ -89,7 +90,8 @@ void MyGTKGLSceneWidget::on_realize() { GLUquadricObj* qobj = gluNewQuadric(); gluQuadricDrawStyle(qobj, GLU_FILL); glNewList(1, GL_COMPILE); - gluSphere(qobj, 1.0, 20, 20); + //gluSphere(qobj, 1.0, 20, 20); + gluSphere(qobj, 1.0, 5, 5); glEndList(); // Setup scene envrionnement @@ -118,7 +120,7 @@ bool MyGTKGLSceneWidget::on_configure_event(GdkEventConfigure* event) { } bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) { - CALL_TRACE ; // This one runs mainly when GTK GL Widget have to be redrawn +// CALL_TRACE ; // This one runs mainly when GTK GL Widget have to be redrawn Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window(); @@ -131,15 +133,15 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) { //Camera position update glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - gluLookAt(0.0, 0.0, 3.0, - 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0); - glTranslatef(0.0, 0.0, -3.0); + glTranslatef(0.0, 0.0, this->camera.tz); + glRotatef(this->camera.rx, 1.0, 0.0, 0.0); + glRotatef(this->camera.ry, 0.0, 1.0, 0.0); // Drawing all the stuff glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList(1); + glwindow->gl_end(); // *** OpenGL END *** @@ -153,31 +155,33 @@ bool MyGTKGLSceneWidget::on_motion_notify_event (GdkEventMotion *event) { } bool MyGTKGLSceneWidget::on_button_press_event(GdkEventButton *event) { - return do_mouse_logic(event->type, event->state, event->x, event->y); + return do_mouse_logic(event->type, event->state | 1<<(7+event->button) , event->x, event->y); } bool MyGTKGLSceneWidget::on_button_release_event(GdkEventButton *event) { return do_mouse_logic(event->type, event->state, event->x, event->y); } -#define KEYBOARD_MODIFIERS ( \ - GDK_SHIFT_MASK | GDK_LOCK_MASK | GDK_CONTROL_MASK \ - | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK \ -) -/* | GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |GDK_MOD5_MASK \ */ +#define ALL_KEYBOARD_MODIFIERS ( GDK_SHIFT_MASK | GDK_CONTROL_MASK \ + | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ) -#define MOUSE_CLIC(button, allowed_modifier_mask) if ( \ +#define MOUSE_CLIC(button, required_modifier_mask, allowed_extra_modifier_mask) if ( \ type == GDK_BUTTON_RELEASE \ && ( state & button ) == button \ - && ( ( state & KEYBOARD_MODIFIERS ) & ~allowed_modifier_mask ) == 0 \ + && ( state & required_modifier_mask ) == required_modifier_mask \ + && ( ( state & ALL_KEYBOARD_MODIFIERS ) & ~( required_modifier_mask | allowed_extra_modifier_mask ) ) == 0 \ ) #define MOUSE_DOUBLECLIC(state_mask) if ( \ type == GDK_BUTTON_RELEASE \ && ( state & state_mask ) == state_mask \ && prev_type == GDK_2BUTTON_PRESS \ ) +#define MOUSE_DRAG_START(state_mask) if ( \ + type == GDK_BUTTON_PRESS \ + && ( state & state_mask ) == state_mask \ +) #define MOUSE_DRAGING(state_mask) if ( \ - ( type == GDK_BUTTON_PRESS || type == GDK_MOTION_NOTIFY ) \ + ( type == GDK_MOTION_NOTIFY ) \ && ( state & state_mask ) == state_mask \ ) #define MOUSE_DRAG_END(state_mask) if ( \ @@ -198,31 +202,45 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x, * GDK_MOD1_MASK, ... (normally MOD1 it is the Alt key) * GDK_SUPER_MASK, GDK_HYPER_MASK, GDK_META_MASK (extra keybord modifier keys) */ + // Static variables to hold previous mouse button event static GdkEventType prev_type = GDK_NOTHING; -// static guint prev_state= 0; // Empty mask -// - std::cout << "event type " << type << " state " << state << " on (" << x << "," << y << ") " << std::endl; -// std::cout << "DEBUG ( state & KEYBOARD_MODIFIERS ) == " << ( state & KEYBOARD_MODIFIERS ) << std::endl; + /*static guint prev_state=0; UNUSED FOR NOW */ + static guint drag_x=0, drag_y=0; + + bool redraw=false; // Setting it to true will queue a redraw to the widget (invalidate) +// std::cout << "event type " << type << " state " << state << " on (" << x << "," << y << ") " << std::endl; /* *** BEGIN event filtering *** */ - MOUSE_DOUBLECLIC(GDK_BUTTON1_MASK) { - std::cout << "Mouse 1 double clic" << std::endl; + MOUSE_DRAG_START(GDK_BUTTON2_MASK) { + drag_x=x; drag_y=y; } MOUSE_DRAGING(GDK_BUTTON2_MASK) { - std::cout << "Mouse 2 dragging" << " on (" << x << "," << y << ") " << std::endl; + float mouse_sensivity = 0.2f; + gint dx = drag_x - x; // Delta movement (since last event) + gint dy = drag_y - y; // Not unsigned ! + // Yes dy for camera.rx, and -= operator + // GTK mouse coords and Opengl are not on the same coords system + this->camera.rx -= mouse_sensivity * dy; + this->camera.ry -= mouse_sensivity * dx; + drag_x = x; drag_y = y; + redraw=true; } - MOUSE_CLIC(GDK_BUTTON3_MASK, 0) { - std::cout << "Mouse 3 clic without any key modifier" << std::endl; + MOUSE_CLIC(GDK_BUTTON1_MASK, 0, 0) { + //TODO } + - //FIXME : this is buggy !!! - MOUSE_CLIC(GDK_BUTTON3_MASK, GDK_SHIFT_MASK) { - std::cout << "Mouse 3 clic with shift or control" << std::endl; + // Demo filters + MOUSE_CLIC(GDK_BUTTON1_MASK, GDK_SHIFT_MASK, GDK_CONTROL_MASK) { + std::cout << "Mouse 1 clic with shift or control-shift" << std::endl; + } + + MOUSE_DOUBLECLIC(GDK_BUTTON3_MASK) { + std::cout << "Mouse 1 double clic" << std::endl; } - /* *** END event filtering *** */ @@ -237,5 +255,7 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x, default: break; } + + if ( redraw ) queue_draw(); return true; } diff --git a/src/my_gtk_gl_scene_widget.h b/src/my_gtk_gl_scene_widget.h index 8445252..bf156ab 100644 --- a/src/my_gtk_gl_scene_widget.h +++ b/src/my_gtk_gl_scene_widget.h @@ -22,6 +22,8 @@ class MyGTKGLSceneWidget : public Gtk::DrawingArea, public Gtk::GL::Widget<MyGTK virtual bool on_button_release_event(GdkEventButton *event); bool do_mouse_logic(GdkEventType type, guint state, guint x, guint y); + private: + struct camera_params { float rx; float ry; float tz; } camera; }; #endif /*MY_GTK_GL_SCENE_H*/ |