00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GLCUBICHERMITECURVE_H
00021 #define GLCUBICHERMITECURVE_H
00022
00023 #include "GLMatrix.h"
00030 namespace mathglpp
00031 {
00032
00033 template <typename T>
00034 class GLCubicHermiteCurve4
00035 {
00036 public:
00037 enum { D = 4 };
00038 typedef T value_type;
00039 typedef GLVector4<value_type> vector_type;
00040 typedef GLMatrix<value_type> matrix_type;
00041
00043 GLCubicHermiteCurve4(const value_type* cpoints)
00044 :basis(cpoints)
00045 {
00047 static value_type coeffs[16] =
00048 { 1, 0, 0, 0,
00049 0, 1, 0, 0,
00050 -3, -2, 3, -1,
00051 2, 1, -2, 1 };
00052
00054 basis *= matrix_type(coeffs);
00055 }
00056
00058 GLCubicHermiteCurve4(const vector_type* cpoints)
00059 {
00061 static value_type coeffs[16] =
00062 { 1, 0, 0, 0,
00063 0, 1, 0, 0,
00064 -3, -2, 3, -1,
00065 2, 1, -2, 1 };
00066
00067 cpoints[0].copyTo(&basis[0]);
00068 cpoints[1].copyTo(&basis[4]);
00069 cpoints[2].copyTo(&basis[8]);
00070 cpoints[3].copyTo(&basis[12]);
00071
00073 basis *= matrix_type(coeffs);
00074 }
00075
00077 GLCubicHermiteCurve4(const vector_type& c0, const vector_type& c1, const vector_type& c2, const vector_type& c3)
00078 {
00080 static value_type coeffs[16] =
00081 { 1, 0, 0, 0,
00082 0, 1, 0, 0,
00083 -3, -2, 3, -1,
00084 2, 1, -2, 1 };
00085
00086 c0.copyTo(&basis[0]);
00087 c1.copyTo(&basis[4]);
00088 c2.copyTo(&basis[8]);
00089 c3.copyTo(&basis[12]);
00090
00092 basis *= matrix_type(coeffs);
00093 }
00094
00095 GLCubicHermiteCurve4(const GLCubicHermiteCurve4& hc)
00096 :basis(hc.basis) {}
00097
00099 ~GLCubicHermiteCurve4(){}
00100
00102 inline void glVertex(GLclampf interp) const
00103 {
00104 value_type interpVec[D] = { 1, value_type(interp), value_type(interp * interp), value_type(interp * interp * interp) };
00105 basis.dot4(interpVec).glVertex();
00106 }
00107
00109 inline vector_type interpolate(GLclampf interp) const
00110 {
00111 value_type interpVec[D] = { 1, value_type(interp), value_type(interp * interp), value_type(interp * interp * interp) };
00112 return basis.dot4(interpVec);
00113 }
00114
00116 void interpolate(GLclampf interp, value_type* vertex) const
00117 {
00118 vertex[0] = 1;
00119 vertex[1] = value_type(interp);
00120 vertex[2] = value_type(interp * interp);
00121 vertex[3] = value_type(interp * interp * interp);
00122 basis.vdot4(vertex);
00123 }
00124
00125 inline vector_type operator()(GLclampf interp) const
00126 {
00127 value_type interpVec[D] = { 1, value_type(interp), value_type(interp * interp), value_type(interp * interp * interp) };
00128 return basis.dot4(interpVec);
00129 }
00130
00131 inline void operator()(GLclampf interp, value_type* v) const
00132 {
00133 v[0] = 1;
00134 v[1] = value_type(interp);
00135 v[2] = value_type(interp * interp);
00136 v[3] = value_type(interp * interp * interp);
00137 basis.vdot4(v);
00138 }
00139
00140 private:
00141 matrix_type basis;
00142 };
00143
00144
00146 typedef GLCubicHermiteCurve4<GLbyte> GLCubicHermiteCurve4b;
00148 typedef GLCubicHermiteCurve4<GLshort> GLCubicHermiteCurve4s;
00150 typedef GLCubicHermiteCurve4<GLint> GLCubicHermiteCurve4i;
00152 typedef GLCubicHermiteCurve4<GLfloat> GLCubicHermiteCurve4f;
00154 typedef GLCubicHermiteCurve4<GLdouble> GLCubicHermiteCurve4d;
00155
00156 };
00157 #endif