SuperTuxKart
Loading...
Searching...
No Matches
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>
27using namespace irr;
28
29#include "utils/no_copy.hpp"
30#include "utils/vec3.hpp"
31
32class XMLNode;
33
37class Ipo : public NoCopy
38{
39public:
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];
49private:
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
72
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);
122public:
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
enum Ipo::IpoData::@0 m_interpolation
The three interpolations defined by blender.
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
void approximateBezier(float t0, float t1, const Vec3 &p0, const Vec3 &p1, const Vec3 &h0, const Vec3 &h2, unsigned int rec_level=0)
This function approximates a bezier curve by piecewise linear functions.
Definition: ipo.cpp:218
float m_end_time
Time of the last control point.
Definition: ipo.hpp:74
void readIPO(const XMLNode &node, float fps, bool reverse)
Reads a blender IPO curve, which constists of a frame number and a control point.
Definition: ipo.cpp:102
float getDerivative(float time, unsigned int index, unsigned int n)
Determines the derivative of a IPO at a given point.
Definition: ipo.cpp:374
float m_start_time
Time of the first control point.
Definition: ipo.hpp:71
float adjustTime(float time)
Adjusts the time so that it is between start and end of this Ipo.
Definition: ipo.cpp:289
enum Ipo::IpoData::@1 m_extend
The four extend types.
float getCubicBezier(float t, float p0, float p1, float p2, float p3) const
Computes a cubic bezier curve for a given t in [0,1] and four control points.
Definition: ipo.cpp:357
float approximateLength(float t0, float t1, const Vec3 &p0, const Vec3 &p1, const Vec3 &h1, const Vec3 &h2)
Approximates the length of a bezier curve using a simple Euler approximation by dividing the interval...
Definition: ipo.cpp:254
std::vector< Vec3 > m_points
The actual control points.
Definition: ipo.hpp:65
void readCurve(const XMLNode &node, bool reverse)
Reads in 3 dimensional curve data - i.e.
Definition: ipo.cpp:147
IpoChannelType m_channel
The type of this IPO.
Definition: ipo.hpp:57
float getCubicBezierDerivative(float t, float p0, float p1, float p2, float p3) const
Returns the derivative of a cubic bezier curve for a given t in [0,1] and four control points.
Definition: ipo.cpp:412
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
Ipo * clone()
Creates a copy of this object (the copy constructor is disabled in order to avoid implicit copies hap...
Definition: ipo.cpp:459
virtual ~Ipo()
The destructor only frees IpoData if it was created by this instance (and not if this instance was co...
Definition: ipo.cpp:468
void setInitialTransform(const Vec3 &xyz, const Vec3 &hpr)
Stores the initial transform.
Definition: ipo.cpp:479
void update(float time, Vec3 *xyz=NULL, Vec3 *hpr=NULL, Vec3 *scale=NULL)
Updates the time of this ipo and interpolates the new position and rotation (taking the cycle length ...
Definition: ipo.cpp:503
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
void getDerivative(float time, Vec3 *xyz)
Returns the derivative for any location based curves.
Definition: ipo.cpp:579
void reset()
Resets the IPO for (re)starting an animation.
Definition: ipo.cpp:489
float get(float time, unsigned int index) const
Returns the interpolated value at the current time (which this objects keeps track of).
Definition: ipo.cpp:559
IpoData * m_ipo_data
The actual data of the IPO.
Definition: ipo.hpp:106
IpoChannelType
All supported ipo types.
Definition: ipo.hpp:43
void updateNextN(float *time) const
Updates the value of m_next_n to point to the right ipo segment based on the time.
Definition: ipo.cpp:537
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