math: Move lerp function into SGMisc.
This commit is contained in:
parent
9414874e1d
commit
57a3b0fd1e
@ -2,7 +2,6 @@ include (SimGearComponent)
|
||||
|
||||
|
||||
set(HEADERS
|
||||
Math.hxx
|
||||
SGBox.hxx
|
||||
SGCMath.hxx
|
||||
SGGeoc.hxx
|
||||
|
@ -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<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
|
@ -87,6 +87,11 @@ public:
|
||||
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!
|
||||
|
@ -40,7 +40,7 @@
|
||||
#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>
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user