typedef enum LocusType
{
LT_LINEAR = 0,
LT_B_SPLINE,
LT_STEP,
}LocusType;
class LocusBase
{
public:
int m_time;
protected:
LocusBase(LocusType type);
const LocusType mc_type;
};
template< class Point >
class Locus : public LocusBase// 轨迹
{
public:
Locus(LocusType type);
struct Node
{
Node():m_time(0), m_p()
{
}
Node(const Node &n):m_time(n.m_time), m_p(n.m_p)
{
}
Node(int time, Point &p):m_time(time), m_p(p)
{
}
int m_time;
Point m_p;
bool operator < (int time) const
{
return m_time < time;
}
};
void loadData(const char *data);
virtual int getInterval(int time, Point &result) = 0;
::std::vector< Node > m_data;
};
/// LocusLinear
/// @note 线性插值轨迹
template< class Point >
class LocusLinear : public Locus< Point >
{
public:
LocusLinear();
int getInterval(int time, Point &result);
};
/// LocusBspline
/// @note B样条曲线插值轨迹
template< class Point >
class LocusBspline : public Locus< Point >
{
public:
LocusBspline();
int getInterval(int time, Point &result);
};
/// LocusStep
/// @note 位置直接跳变的轨迹
template< class Point >
class LocusStep : public Locus< Point >
{
public:
LocusStep();
int getInterval(int time, Point &result);
};
{
LT_LINEAR = 0,
LT_B_SPLINE,
LT_STEP,
}LocusType;
class LocusBase
{
public:
int m_time;
protected:
LocusBase(LocusType type);
const LocusType mc_type;
};
template< class Point >
class Locus : public LocusBase// 轨迹
{
public:
Locus(LocusType type);
struct Node
{
Node():m_time(0), m_p()
{
}
Node(const Node &n):m_time(n.m_time), m_p(n.m_p)
{
}
Node(int time, Point &p):m_time(time), m_p(p)
{
}
int m_time;
Point m_p;
bool operator < (int time) const
{
return m_time < time;
}
};
void loadData(const char *data);
virtual int getInterval(int time, Point &result) = 0;
::std::vector< Node > m_data;
};
/// LocusLinear
/// @note 线性插值轨迹
template< class Point >
class LocusLinear : public Locus< Point >
{
public:
LocusLinear();
int getInterval(int time, Point &result);
};
/// LocusBspline
/// @note B样条曲线插值轨迹
template< class Point >
class LocusBspline : public Locus< Point >
{
public:
LocusBspline();
int getInterval(int time, Point &result);
};
/// LocusStep
/// @note 位置直接跳变的轨迹
template< class Point >
class LocusStep : public Locus< Point >
{
public:
LocusStep();
int getInterval(int time, Point &result);
};
效果:
https://files.cnblogs.com/kaikai/locus.rar
数据随机生成:
srand(timeGetTime());
Clip clip;
LocusBspline2d locus;
LocusLinear2d locusZoom;
LocusLinear1d locusRot;
clip.pFace = &ims;
struct DATA{
int time;
int type;
int size;
Locus2d::Node node[LOCUS_MAX_NODE_COUNT];
} data, zoom;
data.time = 1000;
data.type = LT_B_SPLINE,
data.size = 10;
zoom.time = 1000;
zoom.type = LT_LINEAR,
zoom.size = 10;
struct DATA2{
int time;
int type;
int size;
Locus1d::Node node[LOCUS_MAX_NODE_COUNT];
} rot;
rot.time = 1000;
rot.type = LT_LINEAR,
rot.size = 10;
for (i = 0; i<10; i++)
{
data.node[i] = Locus2d::Node(i*100, Point2d(rand()%640,rand()%480));
zoom.node[i] = Locus2d::Node(i*100, Point2d(rand()%100/50.f,rand()%100/50.f));
rot.node[i].m_time = i*100;
rot.node[i].m_p = rand()%360;
}
locus.loadData((const char *)&data);
locusZoom.loadData((const char *)&zoom);
locusRot.loadData((const char *)&rot);
Anim ani(clip, &locus, &locusZoom, &locusRot);
Clip clip;
LocusBspline2d locus;
LocusLinear2d locusZoom;
LocusLinear1d locusRot;
clip.pFace = &ims;
struct DATA{
int time;
int type;
int size;
Locus2d::Node node[LOCUS_MAX_NODE_COUNT];
} data, zoom;
data.time = 1000;
data.type = LT_B_SPLINE,
data.size = 10;
zoom.time = 1000;
zoom.type = LT_LINEAR,
zoom.size = 10;
struct DATA2{
int time;
int type;
int size;
Locus1d::Node node[LOCUS_MAX_NODE_COUNT];
} rot;
rot.time = 1000;
rot.type = LT_LINEAR,
rot.size = 10;
for (i = 0; i<10; i++)
{
data.node[i] = Locus2d::Node(i*100, Point2d(rand()%640,rand()%480));
zoom.node[i] = Locus2d::Node(i*100, Point2d(rand()%100/50.f,rand()%100/50.f));
rot.node[i].m_time = i*100;
rot.node[i].m_p = rand()%360;
}
locus.loadData((const char *)&data);
locusZoom.loadData((const char *)&zoom);
locusRot.loadData((const char *)&rot);
Anim ani(clip, &locus, &locusZoom, &locusRot);