Debian Codegraph @

src/game/MTFH/animationcurve.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2017 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #include "animationcurve.hpp"
17
18 #include <cassert>
19 #include <cmath>
20
21 namespace MTFH {
22
23 AnimationCurve::AnimationCurve(size_t steps, int exp)
24 : m_values(steps, 1)
25 {
26 assert(steps > 2);
27 assert(exp >= 1);
28
29 float index = 0;
30 for (float & value : m_values)
31 {
32 value = std::pow(index / (steps - 1), exp);
33 index++;
34 }
35 }
36
37 void AnimationCurve::step()
38 {
39 if (m_index + 1 < m_values.size())
40 {
41 m_index++;
42 }
43 }
44
45 void AnimationCurve::reset()
46 {
47 m_index = 0;
48 }
49
50 float AnimationCurve::value() const
51 {
52 return m_values.at(m_index);
53 }
54
55 AnimationCurve::~AnimationCurve() = default;
56
57 } // namespace MTFH