+++ /dev/null
-#ifndef SIMGEAR_MATH_MATH_HXX
-#define SIMGEAR_MATH_MATH_HXX 1
-namespace simgear
-{
-namespace math
-{
-/** Linear interpolation between two values.
- */
-template<typename T>
-inline T lerp(const T& x, const T& y, double alpha)
-{
- return x * (1.0 - alpha) + y * alpha;
-}
-
-template<typename T>
-inline T lerp(const T& x, const T& y, float alpha)
-{
- return x * (1.0f - alpha) + y * alpha;
-}
-
-}
-}
-#endif
static int roundToInt(const T& v)
{ return int(round(v)); }
+ // Linear interpolation between two arbitrary typed values
+ template<typename S>
+ 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!
#include <osg/CullFace>
#include <simgear/debug/logstream.hxx>
-#include <simgear/math/Math.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/scene/util/VectorArrayAdapter.hxx>
#include <simgear/scene/material/Effect.hxx>
#include <simgear/scene/material/EffectGeode.hxx>
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);
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