From b9a7cf0fe674fc4b3357d19add9ecf04fbce8c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Tue, 22 Jan 2013 16:06:09 -0200 Subject: [PATCH] move image with the mouse --- openglcanvas.cpp | 20 +++++++++++++++++++- openglcanvas.h | 8 ++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/openglcanvas.cpp b/openglcanvas.cpp index 27a6462..ca83ae7 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -446,7 +446,9 @@ int OpenGLCanvas::getTextureSize(const char * const progname, const char * textu pnm_readpaminit(in_file,&inpam,sizeof(struct pam)); #endif - int size = inpam.width*inpam.height*inpam.depth*inpam.bytes_per_sample; + image_size_x=inpam.width; + image_size_y=inpam.height; + int size = image_size_x*image_size_y*inpam.depth*inpam.bytes_per_sample; pm_close(in_file); //fprintf(stderr,"size=%d\n",size); @@ -590,6 +592,22 @@ void OpenGLCanvas::setShaders() { } +void OpenGLCanvas::mousePressEvent(QMouseEvent *event){ + lastPos=event->pos(); + //fprintf(stderr,"mouse click\n"); +} + +void OpenGLCanvas::mouseMoveEvent(QMouseEvent *event){ + // scroll with the left button + if(event->buttons()==Qt::LeftButton){ + // compute the delta and move the image + center_lambda+=(event->x()-lastPos.x())*3.1415926f/image_size_x; + center_phi+=(event->y()-lastPos.y())*3.1415926f/image_size_y; + lastPos=event->pos(); + updateGL(); + } +} + void OpenGLCanvas::paintGL(){ float fov_rads = (fov/180.f)*1.5708f; diff --git a/openglcanvas.h b/openglcanvas.h index 88dced1..364ce83 100644 --- a/openglcanvas.h +++ b/openglcanvas.h @@ -55,6 +55,8 @@ protected: void readTextureBytes(const char * const progname, const char * texturePath,unsigned char * textureBytes,int * outImageWidth, int * outImageHeight); char *textFileRead(char *fn); void setShaders(); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); signals: void fps(QString newFPS); @@ -93,6 +95,12 @@ private: // options set in the rc file char* shader_dir; char* input_image_file; + + // input image size (determined automatically) + int image_size_x; + int image_size_y; + + QPoint lastPos; // mouse click position }; #endif // OPENGLCANVAS_H -- GitLab