1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-16 08:42:23 +00:00

Use std::sin/std::cos, clarify floating point types, update comment

This commit is contained in:
Sam Hellawell 2024-07-19 01:29:15 +01:00
parent 380d357d02
commit ecb5616b36

View File

@ -23,23 +23,23 @@ namespace MWRender
float sineOut(float x) float sineOut(float x)
{ {
return sin((x * osg::PIf) / 2); return std::sin((x * osg::PIf) / 2.f);
} }
float sineIn(float x) float sineIn(float x)
{ {
return 1 - cos((x * osg::PIf) / 2); return 1.f - std::cos((x * osg::PIf) / 2.f);
} }
float sineInOut(float x) float sineInOut(float x)
{ {
return -(cos(osg::PIf * x) - 1) / 2; return -(std::cos(osg::PIf * x) - 1.f) / 2.f;
} }
float cubicOut(float t) float cubicOut(float t)
{ {
float t1 = 1 - t; float t1 = 1.f - t;
return 1 - (t1 * t1 * t1); // (1-t)^3 return 1.f - (t1 * t1 * t1); // (1-t)^3
} }
float cubicIn(float x) float cubicIn(float x)
@ -49,21 +49,21 @@ namespace MWRender
float cubicInOut(float x) float cubicInOut(float x)
{ {
if (x < 0.5) if (x < 0.5f)
{ {
return 4 * x * x * x; // 4x^3 return 4.f * x * x * x; // 4x^3
} }
else else
{ {
float x2 = -2 * x + 2; float x2 = -2.f * x + 2.f;
return 1 - (x2 * x2 * x2) / 2; // (1 - (-2x + 2)^3)/2 return 1.f - (x2 * x2 * x2) / 2.f; // (1 - (-2x + 2)^3)/2
} }
} }
float quartOut(float t) float quartOut(float t)
{ {
float t1 = 1 - t; float t1 = 1.f - t;
return 1 - (t1 * t1 * t1 * t1); // (1-t)^4 return 1.f - (t1 * t1 * t1 * t1); // (1-t)^4
} }
float quartIn(float t) float quartIn(float t)
@ -73,14 +73,14 @@ namespace MWRender
float quartInOut(float x) float quartInOut(float x)
{ {
if (x < 0.5) if (x < 0.5f)
{ {
return 8 * x * x * x * x; // 8x^4 return 8.f * x * x * x * x; // 8x^4
} }
else else
{ {
float x2 = -2 * x + 2; float x2 = -2.f * x + 2.f;
return 1 - (x2 * x2 * x2 * x2) / 2; // 1 - ((-2x + 2)^4)/2 return 1.f - (x2 * x2 * x2 * x2) / 2.f; // 1 - ((-2x + 2)^4)/2
} }
} }
@ -89,27 +89,27 @@ namespace MWRender
// Higher lambda = lower swing amplitude. 1 = 150% swing amplitude. // Higher lambda = lower swing amplitude. 1 = 150% swing amplitude.
// w is the frequency of oscillation in the easing func, controls the amount of overswing // w is the frequency of oscillation in the easing func, controls the amount of overswing
const float w = 1.5f * osg::PIf; // 4.71238 const float w = 1.5f * osg::PIf; // 4.71238
return 1 - expf(-lambda * x) * cos(w * x); return 1.f - expf(-lambda * x) * std::cos(w * x);
} }
float springOutWeak(float x) float springOutWeak(float x)
{ {
return springOutGeneric(x, 4); return springOutGeneric(x, 4.f);
} }
float springOutMed(float x) float springOutMed(float x)
{ {
return springOutGeneric(x, 3); return springOutGeneric(x, 3.f);
} }
float springOutStrong(float x) float springOutStrong(float x)
{ {
return springOutGeneric(x, 2); return springOutGeneric(x, 2.f);
} }
float springOutTooMuch(float x) float springOutTooMuch(float x)
{ {
return springOutGeneric(x, 1); return springOutGeneric(x, 1.f);
} }
const std::unordered_map<std::string, EasingFn> easingsMap = { const std::unordered_map<std::string, EasingFn> easingsMap = {
@ -231,7 +231,7 @@ namespace MWRender
if (!mInterpActive) if (!mInterpActive)
return; return;
// Shouldnt happen, but potentially an edge case where a new bone was added // Shouldn't happen, but potentially an edge case where a new bone was added
// between gatherRecursiveBoneTransforms and this update // between gatherRecursiveBoneTransforms and this update
// currently OpenMW will never do this // currently OpenMW will never do this
assert(mBlendBoneTransforms.find(bone) != mBlendBoneTransforms.end()); assert(mBlendBoneTransforms.find(bone) != mBlendBoneTransforms.end());