From b102f57bd43217866ba9b6f378ba5d3647982cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Fri, 25 Jan 2013 16:44:31 -0200 Subject: [PATCH] some numerical stability --- openglcanvas.cpp | 77 ++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/openglcanvas.cpp b/openglcanvas.cpp index 6fa0b0b..e7a1851 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -22,6 +22,11 @@ #define VERT_SHADER_FILE "test_vertex_shader.vert" #define FRAG_SHADER_FILE "fragment_shader.frag" +#define CONST_PI 3.141592653589793238462 +#define CONST_PI_2 1.57079632679489661923 +#define CONST_PI_F 3.14159265358979f +#define CONST_PI_2_F 1.570796326794897f // TODO: check this one + OpenGLCanvas::OpenGLCanvas(QWidget *parent) : QGLWidget(parent) { @@ -50,8 +55,8 @@ void OpenGLCanvas::change_fov(double f){ fov=f; if (fov<=fov_max) scale=1.f; - else if (fov>295.f) - scale = 0.02f; // TODO: check this value wrt fov_max + //else if (fov>295.f) + // scale = 0.02f; // TODO: check this value wrt fov_max else { if (fov_scale_relation == "Naive") scale=fov_max/fov; @@ -69,7 +74,7 @@ void OpenGLCanvas::change_fov(double f){ // scale = 0.3f; - fprintf(stderr,"change fov=%f, fov_max=%f\n",fov,fov_max); + fprintf(stderr,"change fov, fov=%f, fov_max=%f, scale=%f\n",fov,fov_max,scale); emit fov_changed((int)fov); updateGL(); @@ -77,15 +82,17 @@ void OpenGLCanvas::change_fov(double f){ } void OpenGLCanvas::change_fov(int new_fov){ - change_fov((double)new_fov); + if(new_fov<=360&&new_fov>=1) + change_fov((double)new_fov); } void OpenGLCanvas::change_fov_max(int new_fov_max){ - fov_max=(double)new_fov_max; + if(new_fov_max<=360&&new_fov_max>=0) + fov_max=(double)new_fov_max; if (fov<=fov_max) scale=1.f; - else if (fov>295.f) - scale = 0.02f; // TODO: check this value wrt fov_max + //else if (fov>295.f) + // scale = 0.02f; // TODO: check this value wrt fov_max else { if (fov_scale_relation == "Naive") scale=fov_max/fov; @@ -100,7 +107,7 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){ else if (fov_scale_relation == "Logarithm") scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max)); } - fprintf(stderr,"change fov_max=%f, new scale=%f\n",fov_max,scale); + fprintf(stderr,"change fov_max, fov=%f, fov_max=%f, new scale=%f\n",fov,fov_max,scale); emit max_fov_changed((int)fov_max); updateGL(); } @@ -114,7 +121,7 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){ void OpenGLCanvas::change_center_lambda(double lambda){ - if (center_lambda!=lambda && lambda>=-3.14f && lambda<=3.14f) { + if (center_lambda!=lambda && lambda>=-CONST_PI && lambda<=CONST_PI) { center_lambda = lambda; updateGL(); } @@ -123,7 +130,7 @@ void OpenGLCanvas::change_center_lambda(double lambda){ void OpenGLCanvas::change_center_phi(double phi){ - if (center_phi!=phi && phi>=-1.57f && phi<=1.57f) { + if (center_phi!=phi && phi>=-CONST_PI_2 && phi<=CONST_PI_2) { center_phi = phi; updateGL(); } @@ -139,8 +146,8 @@ void OpenGLCanvas::re_center(){ void OpenGLCanvas::change_fov_scale_relation(QString name){ fov_scale_relation = name; - if (fov<60.f) scale = 1.f; - else if (fov>295.f) scale = 0.01f; + if (fov295.f) scale = 0.01f; else{ if (fov_scale_relation == "Naive") scale=fov_max/fov; @@ -278,7 +285,7 @@ void OpenGLCanvas::initializeGL(){ if (texCoord == NULL){ printf("problem allocating memory for texture coordinates \n"); } - define_texture_coordinates(texCoord, m, n, -1.57f, 1.57f, -3.14f, 3.14f); + define_texture_coordinates(texCoord, m, n, -CONST_PI_2_F, CONST_PI_2_F, -CONST_PI_F, CONST_PI_F); //defining positions of the sphere vertices int meshNumVertices = m*n; @@ -311,8 +318,8 @@ void OpenGLCanvas::define_texture_coordinates(float *texCoord, int m, int n, flo for (int i = 0; ibuttons()==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; + center_lambda+=(event->x()-lastPos.x())*CONST_PI_F/image_size_x; + center_phi+=(event->y()-lastPos.y())*CONST_PI_F/image_size_y; lastPos=event->pos(); updateGL(); } @@ -689,7 +696,7 @@ void OpenGLCanvas::wheelEvent(QWheelEvent *event){ void OpenGLCanvas::paintGL(){ - float fov_rads = (fov/180.f)*1.5708f; + float fov_rads = (fov/360.)*CONST_PI; // // changing scale to generate the figures for the paper (remove it after) // scale = 0.8; -- GitLab