Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Onuralp SEZER
Game Library
Commits
bdb952be
Commit
bdb952be
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
cleanup easing functions
parent
a65a6767
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/fggl/math/easing.hpp
+29
-28
29 additions, 28 deletions
include/fggl/math/easing.hpp
with
29 additions
and
28 deletions
include/fggl/math/easing.hpp
+
29
−
28
View file @
bdb952be
...
...
@@ -6,14 +6,15 @@
#define FGGL_MATH_EASING_H
#include
<fggl/math/types.hpp>
#include
<functional>
namespace
fggl
::
math
{
inline
float
lerp
(
float
a
,
float
b
,
float
w
)
{
constexpr
inline
float
lerp
(
float
a
,
float
b
,
float
w
)
{
return
(
b
-
a
)
*
w
+
a
;
}
inline
float
scale
(
float
in
,
float
inMin
,
float
inMax
,
float
outMin
,
float
outMax
)
{
constexpr
inline
float
scale
(
float
in
,
float
inMin
,
float
inMax
,
float
outMin
,
float
outMax
)
{
return
((
in
-
inMin
)
*
(
outMax
-
outMin
))
/
(
inMax
-
inMin
);
}
...
...
@@ -22,42 +23,42 @@ namespace fggl::math {
//
using
transformF
=
std
::
function
<
float
(
float
)
>
;
inline
float
scaleFilter
(
float
in
,
float
inMin
,
float
inMax
,
float
outMin
,
float
outMax
,
transformF
filter
)
{
inline
float
scaleFilter
(
float
in
,
float
inMin
,
float
inMax
,
float
outMin
,
float
outMax
,
const
transformF
&
filter
)
{
float
out
=
in
-
inMin
;
out
/=
(
inMax
-
inMin
);
out
=
f
(
out
);
out
*=
(
out
End
-
out
Start
);
out
=
f
ilter
(
out
);
out
*=
(
out
Max
-
out
Min
);
return
out
+
outMin
;
}
inline
float
mix
(
transformF
a
,
transformF
b
,
float
weightB
,
float
t
)
{
return
((
1
-
weightB
)
*
a
(
t
))
+
(
weightB
*
b
(
t
));
inline
float
mix
(
const
transformF
&
funcA
,
const
transformF
&
funcB
,
float
weightB
,
float
t
)
{
return
((
1
-
weightB
)
*
funcA
(
t
))
+
(
weightB
*
funcB
(
t
));
}
inline
float
crossFade
(
transformF
a
,
transformF
b
,
float
t
)
{
return
((
1
-
t
)
*
a
(
t
))
+
(
t
*
b
);
inline
float
crossFade
(
transformF
funcA
,
transformF
funcB
,
float
t
)
{
return
((
1
-
t
)
*
funcA
(
t
))
+
(
t
*
funcB
(
t
)
);
}
//
// building blocks
//
inline
float
scale
(
transformF
a
,
float
t
)
{
inline
float
scale
(
transformF
f
,
float
t
)
{
return
t
*
f
(
t
);
}
inline
float
reverseScale
(
transformF
a
,
float
t
)
{
return
(
1
-
t
)
*
a
(
t
);
inline
float
reverseScale
(
transformF
f
,
float
t
)
{
return
(
1
-
t
)
*
f
(
t
);
}
inline
float
Arch2
(
float
t
)
{
constexpr
inline
float
Arch2
(
float
t
)
{
return
t
*
(
1
-
t
);
}
inline
float
BounceClampBottom
(
float
t
)
{
constexpr
inline
float
BounceClampBottom
(
float
t
)
{
return
fabs
(
t
);
}
inline
float
BounceClampTop
(
float
t
)
{
constexpr
inline
float
BounceClampTop
(
float
t
)
{
return
1.
f
-
fabs
(
1.
f
-
t
);
}
...
...
@@ -66,39 +67,39 @@ namespace fggl::math {
// see Math for Game Programmers: Fast and Funky 1D Nonlinear Transformations, GDC 2015
//
inline
float
SmoothStart2
(
float
t
)
{
constexpr
inline
float
SmoothStart2
(
float
t
)
{
return
t
*
t
;
}
inline
float
SmoothStart3
(
float
t
)
{
constexpr
inline
float
SmoothStart3
(
float
t
)
{
return
t
*
t
*
t
;
}
inline
float
SmoothStart4
(
float
t
)
{
constexpr
inline
float
SmoothStart4
(
float
t
)
{
return
t
*
t
*
t
*
t
;
}
inline
float
SmoothStart5
(
float
t
)
{
constexpr
inline
float
SmoothStart5
(
float
t
)
{
return
t
*
t
*
t
*
t
*
t
;
}
inline
float
SmoothStop2
(
float
t
)
{
const
expr
tFlip
=
1
-
y
;
constexpr
inline
float
SmoothStop2
(
float
t
)
{
const
auto
tFlip
=
1
-
t
;
return
1
-
(
tFlip
*
tFlip
);
}
inline
float
SmoothStop3
(
float
t
)
{
const
expr
tFlip
=
1
-
y
;
constexpr
inline
float
SmoothStop3
(
float
t
)
{
const
auto
tFlip
=
1
-
t
;
return
1
-
(
tFlip
*
tFlip
);
}
inline
float
SmoothStop4
(
float
t
)
{
const
expr
tFlip
=
1
-
y
;
constexpr
inline
float
SmoothStop4
(
float
t
)
{
const
auto
tFlip
=
1
-
t
;
return
1
-
(
tFlip
*
tFlip
*
tFlip
*
tFlip
);
}
inline
float
SmoothStop5
(
float
t
)
{
const
expr
tFlip
=
1
-
y
;
constexpr
inline
float
SmoothStop5
(
float
t
)
{
const
auto
tFlip
=
1
-
t
;
return
1
-
(
tFlip
*
tFlip
*
tFlip
*
tFlip
*
tFlip
);
}
...
...
@@ -106,7 +107,7 @@ namespace fggl::math {
// Bezier curves
//
inline
float
NormalizedBezier3
(
float
B
,
float
C
,
float
t
)
{
constexpr
inline
float
NormalizedBezier3
(
float
B
,
float
C
,
float
t
)
{
const
float
s
=
1.
f
-
t
;
const
float
t2
=
t
*
t
;
const
float
s2
=
s
*
s
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment