@@ -37,7 +37,7 @@ liblolcore_headers = \ | |||||
\ | \ | ||||
lol/math/math.h \ | lol/math/math.h \ | ||||
lol/math/functions.h lol/math/vector.h lol/math/half.h lol/math/real.h \ | lol/math/functions.h lol/math/vector.h lol/math/half.h lol/math/real.h \ | ||||
lol/math/remez.h lol/math/math.h lol/math/geometry.h \ | |||||
lol/math/remez.h lol/math/math.h lol/math/geometry.h lol/math/interp.h \ | |||||
\ | \ | ||||
lol/sys/sys.h \ | lol/sys/sys.h \ | ||||
lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/atomic.h \ | lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/atomic.h \ | ||||
@@ -0,0 +1,88 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
// | |||||
// Interpolator classes | |||||
// -------------------- | |||||
// | |||||
#if !defined __LOL_MATH_INTERP_H__ | |||||
#define __LOL_MATH_INTERP_H__ | |||||
namespace lol | |||||
{ | |||||
template<typename T, int N = 16> class Interp | |||||
{ | |||||
public: | |||||
inline Interp() : m_pos(-N) {} | |||||
inline ~Interp() {} | |||||
void Set(float key, T const &val) | |||||
{ | |||||
if (m_pos < 0) | |||||
{ | |||||
m_key[m_pos + N] = key; | |||||
m_val[m_pos + N] = val; | |||||
++m_pos; | |||||
} | |||||
else | |||||
{ | |||||
m_key[m_pos] = key; | |||||
m_val[m_pos] = val; | |||||
m_pos = (m_pos + 1) % N; | |||||
} | |||||
} | |||||
T Get(float key) | |||||
{ | |||||
if (m_pos == -N) | |||||
return T(); | |||||
if (m_pos == 1 - N) | |||||
return m_val[0]; | |||||
int start = max(0, m_pos); | |||||
int a = 0; | |||||
int b = min(m_pos + N, N); | |||||
while (a + 1 < b) | |||||
{ | |||||
int c = (a + b) / 2; | |||||
if (m_key[(start + c) % N] >= key) | |||||
b = c; | |||||
else | |||||
a = c; | |||||
} | |||||
float ka = m_key[(start + a) % N]; | |||||
float kb = m_key[(start + b) % N]; | |||||
float u = (key - ka) / (kb - ka); | |||||
return (1.f - u) * m_val[(start + a) % N] + u * m_val[(start + b) % N]; | |||||
} | |||||
inline void Reset() | |||||
{ | |||||
m_pos = -N; | |||||
} | |||||
private: | |||||
float m_key[N]; | |||||
T m_val[N]; | |||||
/* If m_pos < 0, the value indicates how many free slots | |||||
* there are. */ | |||||
int m_pos; | |||||
}; | |||||
} /* namespace lol */ | |||||
#endif // __LOL_MATH_INTERP_H__ | |||||
@@ -16,6 +16,7 @@ | |||||
#include <lol/math/real.h> | #include <lol/math/real.h> | ||||
#include <lol/math/vector.h> | #include <lol/math/vector.h> | ||||
#include <lol/math/geometry.h> | #include <lol/math/geometry.h> | ||||
#include <lol/math/interp.h> | |||||
#endif // __LOL_MATH_MATH_H__ | #endif // __LOL_MATH_MATH_H__ | ||||
@@ -214,6 +214,7 @@ | |||||
<ClInclude Include="lol\math\functions.h" /> | <ClInclude Include="lol\math\functions.h" /> | ||||
<ClInclude Include="lol\math\geometry.h" /> | <ClInclude Include="lol\math\geometry.h" /> | ||||
<ClInclude Include="lol\math\half.h" /> | <ClInclude Include="lol\math\half.h" /> | ||||
<ClInclude Include="lol\math\interp.h" /> | |||||
<ClInclude Include="lol\math\math.h" /> | <ClInclude Include="lol\math\math.h" /> | ||||
<ClInclude Include="lol\math\real.h" /> | <ClInclude Include="lol\math\real.h" /> | ||||
<ClInclude Include="lol\math\remez.h" /> | <ClInclude Include="lol\math\remez.h" /> | ||||
@@ -280,4 +281,4 @@ | |||||
<ImportGroup Label="ExtensionTargets"> | <ImportGroup Label="ExtensionTargets"> | ||||
<Import Project="$(SolutionDir)\Lol.Fx.targets" /> | <Import Project="$(SolutionDir)\Lol.Fx.targets" /> | ||||
</ImportGroup> | </ImportGroup> | ||||
</Project> | |||||
</Project> |
@@ -512,6 +512,9 @@ | |||||
<ClInclude Include="lol\math\geometry.h"> | <ClInclude Include="lol\math\geometry.h"> | ||||
<Filter>lol\math</Filter> | <Filter>lol\math</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="lol\math\interp.h"> | |||||
<Filter>lol\math</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="easymesh\csgbsp.h"> | <ClInclude Include="easymesh\csgbsp.h"> | ||||
<Filter>easymesh</Filter> | <Filter>easymesh</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
@@ -21,7 +21,7 @@ testsuite_SOURCES = testsuite.cpp \ | |||||
unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \ | unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \ | ||||
unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \ | unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \ | ||||
unit/array.cpp unit/rotation.cpp unit/string.cpp unit/map.cpp \ | unit/array.cpp unit/rotation.cpp unit/string.cpp unit/map.cpp \ | ||||
unit/color.cpp unit/atomic.cpp | |||||
unit/color.cpp unit/atomic.cpp unit/interp.cpp | |||||
testsuite_CPPFLAGS = $(AM_CPPFLAGS) | testsuite_CPPFLAGS = $(AM_CPPFLAGS) | ||||
testsuite_DEPENDENCIES = @LOL_DEPENDENCIES@ | testsuite_DEPENDENCIES = @LOL_DEPENDENCIES@ | ||||
@@ -42,6 +42,7 @@ | |||||
<ClCompile Include="unit\color.cpp" /> | <ClCompile Include="unit\color.cpp" /> | ||||
<ClCompile Include="unit\half.cpp" /> | <ClCompile Include="unit\half.cpp" /> | ||||
<ClCompile Include="unit\image.cpp" /> | <ClCompile Include="unit\image.cpp" /> | ||||
<ClCompile Include="unit\interp.cpp" /> | |||||
<ClCompile Include="unit\map.cpp" /> | <ClCompile Include="unit\map.cpp" /> | ||||
<ClCompile Include="unit\matrix.cpp" /> | <ClCompile Include="unit\matrix.cpp" /> | ||||
<ClCompile Include="unit\quat.cpp" /> | <ClCompile Include="unit\quat.cpp" /> | ||||
@@ -84,7 +84,7 @@ LOLUNIT_FIXTURE(ColorTest) | |||||
LOLUNIT_SET_CONTEXT(n / 7); | LOLUNIT_SET_CONTEXT(n / 7); | ||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(d1, d2, 0.0001); | LOLUNIT_ASSERT_DOUBLES_EQUAL(d1, d2, 0.0001); | ||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(d2, d3, 0.0001); | LOLUNIT_ASSERT_DOUBLES_EQUAL(d2, d3, 0.0001); | ||||
LOLUNIT_UNSET_CONTEXT(); | |||||
LOLUNIT_UNSET_CONTEXT(n / 7); | |||||
} | } | ||||
} | } | ||||
@@ -106,7 +106,7 @@ LOLUNIT_FIXTURE(ColorTest) | |||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(v1.g, v3.g, 0.0001); | LOLUNIT_ASSERT_DOUBLES_EQUAL(v1.g, v3.g, 0.0001); | ||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(v1.b, v3.b, 0.0001); | LOLUNIT_ASSERT_DOUBLES_EQUAL(v1.b, v3.b, 0.0001); | ||||
LOLUNIT_UNSET_CONTEXT(); | |||||
LOLUNIT_UNSET_CONTEXT(&rgb[0]); | |||||
} | } | ||||
} | } | ||||
@@ -128,7 +128,7 @@ LOLUNIT_FIXTURE(ColorTest) | |||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.y, v3.y, 0.0001); | LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.y, v3.y, 0.0001); | ||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.z, v3.z, 0.0001); | LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.z, v3.z, 0.0001); | ||||
LOLUNIT_UNSET_CONTEXT(); | |||||
LOLUNIT_UNSET_CONTEXT(&rgb[0]); | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||
@@ -0,0 +1,41 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include "core.h" | |||||
#include "lol/unit.h" | |||||
namespace lol | |||||
{ | |||||
LOLUNIT_FIXTURE(InterpTest) | |||||
{ | |||||
void SetUp() {} | |||||
void TearDown() {} | |||||
LOLUNIT_TEST(FloatInterp) | |||||
{ | |||||
Interp<float> interp; | |||||
interp.Set(1.f, 100.f); | |||||
interp.Set(2.f, 150.f); | |||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(75.f, interp.Get(0.5f), 1.e-5f); | |||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(125.f, interp.Get(1.5f), 1.e-5f); | |||||
LOLUNIT_ASSERT_DOUBLES_EQUAL(175.f, interp.Get(2.5f), 1.e-5f); | |||||
} | |||||
}; | |||||
} /* namespace lol */ | |||||