SuperTuxKart
ipo.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2009-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_IPO_HPP
20 #define HEADER_IPO_HPP
21 
22 #include <string>
23 #include <vector>
24 
25 #include <vector2d.h>
26 #include <vector3d.h>
27 using namespace irr;
28 
29 #include "utils/no_copy.hpp"
30 #include "utils/vec3.hpp"
31 
32 class XMLNode;
33 
37 class Ipo : public NoCopy
38 {
39 public:
43  enum IpoChannelType {IPO_LOCX, IPO_LOCY, IPO_LOCZ,
44  IPO_LOCXYZ,
45  IPO_ROTX, IPO_ROTY, IPO_ROTZ,
46  IPO_SCALEX, IPO_SCALEY, IPO_SCALEZ,
47  IPO_MAX};
48  static const std::string m_all_channel_names[IPO_MAX];
49 private:
53  class IpoData
54  {
55  public:
58 
60  enum {IP_CONST, IP_LINEAR, IP_BEZIER} m_interpolation;
62  enum {ET_CONST, ET_EXTRAP, ET_CYCLIC_EXTRAP, ET_CYCLIC} m_extend;
63 
65  std::vector<Vec3> m_points;
66 
68  std::vector<Vec3> m_handle1, m_handle2;
69 
71  float m_start_time;
72 
74  float m_end_time;
75 
78 
81  private:
82  float getCubicBezier(float t, float p0, float p1,
83  float p2, float p3) const;
84  float getCubicBezierDerivative(float t, float p0, float p1,
85  float p2, float p3) const;
86  void approximateBezier(float t0, float t1,
87  const Vec3 &p0, const Vec3 &p1,
88  const Vec3 &h0, const Vec3 &h2,
89  unsigned int rec_level = 0);
90  public:
91  IpoData(const XMLNode &curve, float fps, bool reverse);
92  void readCurve(const XMLNode &node, bool reverse);
93  void readIPO(const XMLNode &node, float fps, bool reverse);
94  float approximateLength(float t0, float t1,
95  const Vec3 &p0, const Vec3 &p1,
96  const Vec3 &h1, const Vec3 &h2);
97  float adjustTime(float time);
98  float get(float time, unsigned int index, unsigned int n);
99  float getDerivative(float time, unsigned int index, unsigned int n);
100 
101  }; // IpoData
102  // ------------------------------------------------------------------------
107 
112 
117  mutable unsigned int m_next_n;
118 
119  void updateNextN(float *time) const;
120 
121  Ipo(const Ipo *ipo);
122 public:
123  Ipo(const XMLNode &curve, float fps=25, bool reverse=false);
124  virtual ~Ipo();
125  Ipo *clone();
126  void update(float time, Vec3 *xyz=NULL, Vec3 *hpr=NULL,
127  Vec3 *scale=NULL);
128  void getDerivative(float time, Vec3 *xyz);
129  float get(float time, unsigned int index) const;
130  void setInitialTransform(const Vec3 &xyz, const Vec3 &hpr);
131  void reset();
132  // ------------------------------------------------------------------------
134  const std::vector<Vec3>& getPoints() const { return m_ipo_data->m_points; }
135  // ------------------------------------------------------------------------
138  float getEndTime() const { return m_ipo_data->m_end_time; }
139 }; // Ipo
140 
141 #endif
142 
This object stores the read-only data of an IPO.
Definition: ipo.hpp:54
std::vector< Vec3 > m_handle1
Only used for bezier curves: the two handles.
Definition: ipo.hpp:68
Vec3 m_initial_xyz
Stores the inital position of the object.
Definition: ipo.hpp:77
Vec3 m_initial_hpr
Stores the inital rotation of the object.
Definition: ipo.hpp:80
float m_end_time
Time of the last control point.
Definition: ipo.hpp:74
float m_start_time
Time of the first control point.
Definition: ipo.hpp:71
std::vector< Vec3 > m_points
The actual control points.
Definition: ipo.hpp:65
IpoChannelType m_channel
The type of this IPO.
Definition: ipo.hpp:57
A class to manage a single blender IPO curve.
Definition: ipo.hpp:38
bool m_own_ipo_data
True if m_ipo_data is 'owned' by this object and therefore needs to be freed.
Definition: ipo.hpp:111
unsigned int m_next_n
Which control points will be the next one (so m_next_n-1 and m_next_n are the control points to use n...
Definition: ipo.hpp:117
float getEndTime() const
Returns the last specified time (i.e.
Definition: ipo.hpp:138
const std::vector< Vec3 > & getPoints() const
Returns the raw data points for this IPO.
Definition: ipo.hpp:134
IpoData * m_ipo_data
The actual data of the IPO.
Definition: ipo.hpp:106
IpoChannelType
All supported ipo types.
Definition: ipo.hpp:43
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48