diff --git a/openglcanvas.cpp b/openglcanvas.cpp index 4c9a865a2b7cc2479502a68127b324b1aaf08185..631739ed678bc350df598516864879d13bc9317a 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -65,15 +65,15 @@ void OpenGLCanvas::change_fov(double f){ if (fov_scale_relation == "Naive") scale=fov_max/fov; else if (fov_scale_relation == "Square Root") - scale=sqrt((360.f-fov_max-fov)/(360.-2*fov_max)); + scale=sqrtf((360.f-fov_max-fov)/(360.-2*fov_max)); else if (fov_scale_relation == "Linear") - scale=(360.f-fov_max-fov)/(360.-2*fov_max); + scale=(360.f-fov_max-fov)/(360.f-2.f*fov_max); else if (fov_scale_relation == "Square Power") - scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),2); + scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),2.f); else if (fov_scale_relation == "Cubic Power") - scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),3); + scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),3.f); else if (fov_scale_relation == "Logarithm") - scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max)); + scale=logf(expf(1.f)+(1.f-expf(1.f))*(fov-fov_max)/(360.f-2.f*fov_max)); } // scale = 0.3f; @@ -99,7 +99,7 @@ void OpenGLCanvas::change_fov(int new_fov){ } void OpenGLCanvas::change_fov_max(int new_fov_max){ - if(new_fov_max<=360&&new_fov_max>=1) + if(new_fov_max<=360.f&&new_fov_max>=1) fov_max=(double)new_fov_max; if (fov<=fov_max) scale=1.f; @@ -109,15 +109,15 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){ if (fov_scale_relation == "Naive") scale=fov_max/fov; else if (fov_scale_relation == "Square Root") - scale=sqrt((360.f-fov_max-fov)/(360.-2*fov_max)); + scale=sqrtf((360.f-fov_max-fov)/(360.f-2.f*fov_max)); else if (fov_scale_relation == "Linear") - scale=(360.f-fov_max-fov)/(360.-2*fov_max); + scale=(360.f-fov_max-fov)/(360.f-2.f*fov_max); else if (fov_scale_relation == "Square Power") - scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),2); + scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),2.f); else if (fov_scale_relation == "Cubic Power") - scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),3); + scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),3.f); else if (fov_scale_relation == "Logarithm") - scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max)); + scale=logf(expf(1.f)+(1.f-expf(1.f))*(fov-fov_max)/(360.f-2.f*fov_max)); } 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); @@ -133,7 +133,7 @@ void OpenGLCanvas::change_fov_max(int new_fov_max){ void OpenGLCanvas::change_center_lambda(double lambda){ - if (center_lambda!=lambda && lambda>=-CONST_PI && lambda<=CONST_PI) { + if (center_lambda!=lambda && lambda>=-CONST_PI_F && lambda<=CONST_PI_F) { center_lambda = lambda; updateGL(); } @@ -142,7 +142,7 @@ void OpenGLCanvas::change_center_lambda(double lambda){ void OpenGLCanvas::change_center_phi(double phi){ - if (center_phi!=phi && phi>=-CONST_PI_2 && phi<=CONST_PI_2) { + if (center_phi!=phi && phi>=-CONST_PI_2_F && phi<=CONST_PI_2_F) { center_phi = phi; updateGL(); } @@ -164,15 +164,15 @@ void OpenGLCanvas::change_fov_scale_relation(QString name){ if (fov_scale_relation == "Naive") scale=fov_max/fov; else if (fov_scale_relation == "Square Root") - scale=sqrt((360.f-fov_max-fov)/(360.-2*fov_max)); + scale=sqrtf((360.f-fov_max-fov)/(360.f-2.f*fov_max)); else if (fov_scale_relation == "Linear") - scale=(360.f-fov_max-fov)/(360.-2*fov_max); + scale=(360.f-fov_max-fov)/(360.f-2.f*fov_max); else if (fov_scale_relation == "Square Power") - scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),2); + scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),2.f); else if (fov_scale_relation == "Cubic Power") - scale=powf((360.f-fov_max-fov)/(360.-2*fov_max),3); + scale=powf((360.f-fov_max-fov)/(360.f-2.f*fov_max),3.f); else if (fov_scale_relation == "Logarithm") - scale=log(exp(1.f)+(1.f-exp(1.f))*(fov-fov_max)/(360.-2*fov_max)); + scale=logf(expf(1.f)+(1.f-expf(1.f))*(fov-fov_max)/(360.f-2.f*fov_max)); } fprintf(stderr,"changed scale relation, scale=%f, fov_max=%f\n",scale,fov_max); updateGL(); @@ -393,6 +393,7 @@ void OpenGLCanvas::define_texture_coordinates(float *texCoord, int m, int n, flo } +// This function makes the same computation GLSL does. It is never called. void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float center_lambda, float center_phi, float fov_rads, float scale){ float min_lambda = -CONST_PI_F; @@ -406,68 +407,67 @@ void OpenGLCanvas::vertex_transformation(float *positions, int m, int n, float c float lambda, phi, x, y, z, u, v, r, theta; //calculating the extent of the projection for the given FOV - lambda = fov_rads; - phi = 0.f; + lambda=fov_rads; + phi=0.f; // OpenGL: x is the vertical axes pointg downwards, and y is horizontal axes - y = sin(phi); - x = -sin(lambda)*cos(phi); - z = -cos(lambda)*cos(phi); - u = 2.f*x/(-z+1.f); - v = 2.f*y/(-z+1.f); - r = sqrt(u*u+v*v); - theta = atan2(u,v); - r *= scale; - u = -r*sin(theta); - v = r*cos(theta); - x = (4.f*u)/(u*u+v*v+4.f); - y = (4.f*v)/(u*u+v*v+4.f); - z = (u*u+v*v-4.f)/(u*u+v*v+4.f); - u = x/(-z); - v = y/(-z); - float extent = u; + y=sinf(phi); + x=-sinf(lambda)*cosf(phi); + z = -cosf(lambda)*cosf(phi); + u=2.f*x/(1.f-z); + v=2.f*y/(1.f-z); + r=hypotf(u,v); + theta=atan2f(u,v); + r*=scale; + u=-r*sinf(theta); + v=r*cosf(theta); + x=(4.f*u)/(u*u+v*v+4.f); + y=(4.f*v)/(u*u+v*v+4.f); + z=(u*u+v*v-4.f)/(u*u+v*v+4.f); + u=x/(-z); + v=y/(-z); + float extent=u; for (int i = 0; i