From 57a3b0fd1e0af0eb032bb426655a3af037cf5f01 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sat, 3 Mar 2012 11:56:40 +0100 Subject: [PATCH] math: Move lerp function into SGMisc. --- simgear/math/CMakeLists.txt | 1 - simgear/math/Math.hxx | 23 ----------------------- simgear/math/SGMisc.hxx | 5 +++++ simgear/scene/sky/dome.cxx | 10 +++++----- 4 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 simgear/math/Math.hxx diff --git a/simgear/math/CMakeLists.txt b/simgear/math/CMakeLists.txt index b01f9259..ef71ed50 100644 --- a/simgear/math/CMakeLists.txt +++ b/simgear/math/CMakeLists.txt @@ -2,7 +2,6 @@ include (SimGearComponent) set(HEADERS - Math.hxx SGBox.hxx SGCMath.hxx SGGeoc.hxx diff --git a/simgear/math/Math.hxx b/simgear/math/Math.hxx deleted file mode 100644 index 427923ec..00000000 --- a/simgear/math/Math.hxx +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef SIMGEAR_MATH_MATH_HXX -#define SIMGEAR_MATH_MATH_HXX 1 -namespace simgear -{ -namespace math -{ -/** Linear interpolation between two values. - */ -template -inline T lerp(const T& x, const T& y, double alpha) -{ - return x * (1.0 - alpha) + y * alpha; -} - -template -inline T lerp(const T& x, const T& y, float alpha) -{ - return x * (1.0f - alpha) + y * alpha; -} - -} -} -#endif diff --git a/simgear/math/SGMisc.hxx b/simgear/math/SGMisc.hxx index 89417cb3..5e69077e 100644 --- a/simgear/math/SGMisc.hxx +++ b/simgear/math/SGMisc.hxx @@ -87,6 +87,11 @@ public: static int roundToInt(const T& v) { return int(round(v)); } + // Linear interpolation between two arbitrary typed values + template + static S lerp(const S& val0, const S& val1, const T& t) + { return val0*(T(1) - t) + val1*t; } + #ifndef NDEBUG /// Returns true if v is a NaN value /// Use with care: allways code that you do not need to use that! diff --git a/simgear/scene/sky/dome.cxx b/simgear/scene/sky/dome.cxx index 5cd40cb4..53018f02 100644 --- a/simgear/scene/sky/dome.cxx +++ b/simgear/scene/sky/dome.cxx @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -234,7 +234,7 @@ static void fade_to_black(osg::Vec3 sky_color[], float asl, int count) { sky_color[i] *= d; } -inline void clampColor(osg::Vec3& color) +static inline void clampColor(osg::Vec3& color) { color.x() = osg::clampTo(color.x(), 0.0f, 1.0f); color.y() = osg::clampTo(color.y(), 0.0f, 1.0f); @@ -310,17 +310,17 @@ SGSkyDome::repaint( const SGVec3f& sun_color, const SGVec3f& sky_color, int j=0; // Color top half by linear interpolation (90...60 degrees) for (; j < upperRings; j++) - colors(j, i) = simgear::math::lerp(toOsg(sky_color), colors(upperRings, i), j / (float)upperRings); + colors(j, i) = SGMiscf::lerp(toOsg(sky_color), colors(upperRings, i), j / (float)upperRings); j++; // Skip the 60 deg ring // From 60 to ~85 degrees for (int l = 0; j < upperRings + middleRings + 1; j++, l++) - colors(j, i) = simgear::math::lerp(colors(upperRings, i), + colors(j, i) = SGMiscf::lerp(colors(upperRings, i), toOsg(sky_color - middleVisFactor * diff + middle_amt), l / (float)middleRings); // 85 to 90 degrees for (int l = 0; j < halfRings; j++, l++) - colors(j, i) = simgear::math::lerp(colors(upperRings + middleRings, i), toOsg(fog_color + outer_amt), + colors(j, i) = SGMiscf::lerp(colors(upperRings + middleRings, i), toOsg(fog_color + outer_amt), l / (float)(halfRings - upperRings - middleRings)); // Original colors -- 2.39.5