From 47d0dbacaab00319ef039011096a5dfacbd83618 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 31 Mar 2013 19:30:38 +0000 Subject: Review + parsing du source pour trouver les noms des kernels à la vollée MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2013-gpudataviz/trunk@28 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d --- src/gpudataviz.cpp | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'src/gpudataviz.cpp') diff --git a/src/gpudataviz.cpp b/src/gpudataviz.cpp index 89adf40..1dc14f8 100644 --- a/src/gpudataviz.cpp +++ b/src/gpudataviz.cpp @@ -34,7 +34,7 @@ int main(int argc, char* argv[]) { Gdk::GL::ConfigMode glMode = Gdk::GL::MODE_RGB | Gdk::GL::MODE_DEPTH; EXIT_IF_FAIL(2, glconfig=Gdk::GL::Config::create(glMode) ); - // Initialize the OpenGL scene widget (realization came later) + // Initialize the OpenGL scene widget (realization came later, no RAII) MyGTKGLSceneWidget glScene(glconfig); // Instantiate the GTK app (and realize glScene) @@ -49,7 +49,9 @@ int main(int argc, char* argv[]) { // MyGTKGLSceneWidget implementation (extends a Gtk::DrawingArea with Gtk::GL::Widget) // I want to keep all interesting code parts in this file, in natural reading order -MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr &glconfig) { +MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr &glconfig): + continuous_play(false), need_recompute(false), time(0.0f) +{ CALL_TRACE; set_gl_capability(glconfig); Gdk::EventMask mask = Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK \ @@ -57,15 +59,17 @@ MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr &glconfig) | Gdk::SCROLL_MASK; set_events(mask); // The containing window should have those attributes too - // Some starting default values - this->camera.rx = -64.0f; this->camera.ry = -16.0f; this->camera.tz = -2.0f; - need_recompute=false; continuous_play=false; time=0.0f; + // Camera is always looking the center of the mesh + // this->camera affects (only) the camera position + // rx,ry : the camera rotate around the mesh. Those vars are angles in degrees + // tz : distance between the center of the mesh and the camera (roughly) + this->camera.rx = -64.0f; this->camera.ry = 16.0f; this->camera.tz = 2.0f; } MyGTKGLSceneWidget::~MyGTKGLSceneWidget() { } void MyGTKGLSceneWidget::on_size_request(Gtk::Requisition* requisition) { - CALL_TRACE; // Technical stuff : GTK call this to ask the widget minimal size + CALL_TRACE; // Technical stuff, GTK call this to ask for widget minimal size *requisition = Gtk::Requisition(); requisition->width = 320; requisition->height = 240; } @@ -128,15 +132,13 @@ void MyGTKGLSceneWidget::on_realize() { /* calculate centered normalized coordinates [-1.0;1.0] */ float x = u*2.0-1.0; float y = v*2.0-1.0; - /* Calculate the desirated value of the mesh point */ + /* set some constants and calculate some intermediate values */ float freq = 8.0 * 3.14; - float amp = 1.0 / 10.0; /* 0.1 does NOT works for me ! WTF !!! */ float speed = 1.0; + float amp = 1.0 / 10.0; /* 0.1 does NOT works for me ! WTF !!! */ float dist = sqrt(x*x+y*y); - float z; - //for(int i = 0; i < 40000; i++){ - z = amp * sin( freq * dist - speed * time ) / dist ; - //} + /* Calculate the desirated value of the mesh point */ + float z = amp * sin( freq * dist + speed * time ) / dist ; /* We only use normalized quaterinons here */ float w = 1.0; /* Write output vertex (centered) */ @@ -145,10 +147,10 @@ void MyGTKGLSceneWidget::on_realize() { ); // TODO : change API, use only one string and split it at each blanks - std::list knames; - knames.push_back("water1"); - cl_res = this->clKit.compileKernels(knames, source, sizeof(source)); - knames.clear(); + //std::list knames; + //knames.push_back("water1"); + cl_res = this->clKit.compileKernels(/*knames,*/ source, sizeof(source)); + //knames.clear(); EXIT_IF_FAIL(6, cl_res==0); glEnable(GL_BLEND); @@ -168,7 +170,6 @@ bool MyGTKGLSceneWidget::on_configure_event(GdkEventConfigure* event) { Glib::RefPtr glwindow = get_gl_window(); // *** OpenGL BEGIN *** - //FIXME could segfault if get_gl_window() has failed if (!glwindow->gl_begin(get_gl_context())) { std::cerr << "Oops : glwindow->gl_begin(get_gl_context())" << std::endl; return false; @@ -211,9 +212,9 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) { //Camera position update glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.0, 0.0, this->camera.tz); + glTranslatef(0.0, 0.0, this->camera.tz * -1.0); glRotatef(this->camera.rx, 1.0, 0.0, 0.0); - glRotatef(this->camera.ry, 0.0, 0.0, 1.0); + glRotatef(this->camera.ry, 0.0, 0.0, -1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -229,7 +230,7 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) { // The comprehensible one //float c1=(1024*1024)/(m_w*m_h); // coef 1 decreases with mesh point quantity //float c2=(s_h*s_h)/(1024*1024); // coef 2 increases with viewport pixel quantity - //float c3=(-2*-2)/(t_z*t_z); // coef 3 decreases with mesh-camera distance + //float c3=(2*2)/(t_z*t_z); // coef 3 decreases with mesh-camera distance //float alpha=0.5*c1*c2*c3; // Combine it all //if (alpha < 0.01f) alpha = 0.01f; // Prevent values outside acceptable range //if (alpha > 1.0f) alpha = 1.0f; @@ -349,7 +350,7 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x, gint dx = drag_x - x; // Delta movement (since last event) gint dy = drag_y - y; // Not unsigned ! this->camera.rx -= mouse_sensivity * dy; // Camera position update - this->camera.ry -= mouse_sensivity * dx; // Yes dy for camera.rx, and -= operator : + this->camera.ry += mouse_sensivity * dx; // Yes dy for camera.rx, and -= operator : // GTK mouse coords and OpenGL ones are not on the same coords system drag_x = x; drag_y = y; redraw=true; @@ -358,8 +359,8 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x, // Camera zoom-in MOUSE_WHEEL(GDK_SCROLL_UP, 0, 0) { - if (this->camera.tz + 0.5f <= -0.5f) { - this->camera.tz += 0.5f; + if (this->camera.tz - 0.5f >= 0.5f) { + this->camera.tz -= 0.5f; //std::cout << "camera.tz == " << this->camera.tz << std::endl; redraw=true; } @@ -367,8 +368,8 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x, // Camera zoom-out MOUSE_WHEEL(GDK_SCROLL_DOWN, 0, 0) { - if (this->camera.tz - 0.5f >= -9.0f) { - this->camera.tz -= 0.5f; + if (this->camera.tz + 0.5f <= 9.0f) { + this->camera.tz += 0.5f; //std::cout << "camera.tz == " << this->camera.tz << std::endl; redraw=true; } -- cgit v1.2.3