00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MATHGLPPGLCUBICBEZIERSPLINE4_H
00021 #define MATHGLPPGLCUBICBEZIERSPLINE4_H
00022
00023 #include "CubicBezierCurve.h"
00024 #include <vector>
00025 #include <cmath>
00026
00027 namespace mathglpp {
00028
00032 template <typename T>
00033 class CubicBezierSpline4
00034 {
00035 public:
00036
00037 enum { D = 4 };
00038 typedef T value_type;
00039 typedef GLVector4<value_type> vector_type;
00040 typedef CubicBezierCurve4<value_type> curve_type;
00041
00043 CubicBezierSpline4(GLint ncurves, const value_type* cpoints)
00044 :number_of_curves(ncurves)
00045 {
00046 const value_type* c0 = cpoints;
00048 for(GLint i = 0; i < number_of_curves; ++i, c0+=12)
00050 curves.push_back(curve_type(c0));
00051 }
00052
00053 CubicBezierSpline4(GLint ncurves, const vector_type* cpoints)
00054 :number_of_curves(ncurves)
00055 {
00056 const vector_type* c0 = cpoints;
00058 for(GLint i = 0; i < number_of_curves; ++i, c0+=3)
00060 curves.push_back(curve_type(*c0, *(c0+1), *(c0+2), *(c0+3)));
00061 }
00062
00063 ~CubicBezierSpline4() { curves.clear(); }
00064
00066 void interpolate(GLclampf interp, value_type* vertex) const
00067 {
00068 GLclampf c; GLclampf u = modff(interp*number_of_curves, &c);
00069 if(c == number_of_curves){ c = number_of_curves-1; u = 1.0; }
00070 return curves[int(c)].interpolate(u,vertex);
00071 }
00072
00073 private:
00074 GLint number_of_curves;
00075 std::vector<curve_type > curves;
00076 };
00077
00079 typedef CubicBezierSpline4<GLbyte> CubicBezierSpline4b;
00081 typedef CubicBezierSpline4<GLshort> CubicBezierSpline4s;
00083 typedef CubicBezierSpline4<GLint> CubicBezierSpline4i;
00085 typedef CubicBezierSpline4<GLfloat> CubicBezierSpline4f;
00087 typedef CubicBezierSpline4<GLdouble> CubicBezierSpline4d;
00088
00089 };
00090
00091 #endif