00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Jacques Gasselin * 00003 * jacquesgasselin@hotmail.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Library General Public License as * 00007 * published by the Free Software Foundation; either version 2 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU Library General Public * 00016 * License along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #ifndef MATHGLPPGLCUBICBEZIERSPLINE4_H 00021 #define MATHGLPPGLCUBICBEZIERSPLINE4_H 00022 00023 #include "GLCubicBezierCurve.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 value_type* c0 = cpoints; 00047 00049 for(GLint i = 0; i < number_of_curves; ++i) 00050 { 00052 curves.push_back(curve_type(c0)); 00054 c0+=12; 00055 } 00056 } 00057 00058 CubicBezierSpline4(GLint ncurves, const vector_type* cpoints) 00059 :number_of_curves(ncurves) 00060 { 00061 const vector_type* c0 = cpoints; 00062 00064 for(GLint i = 0; i < number_of_curves; ++i) 00065 { 00067 curves.push_back(curve_type(*c0, *(c0+1), *(c0+2), *(c0+3))); 00069 c0+=3; 00070 } 00071 } 00072 00073 ~CubicBezierSpline4() { curves.clear(); } 00074 00076 inline vector_type interpolate(GLclampf interp) const 00077 { 00078 GLclampf c; GLclampf u = modff(interp*number_of_curves, &c); 00079 if(c == number_of_curves){ c = number_of_curves-1; u = 1.0; } 00080 return curves[int(c)].interpolate(u); 00081 } 00082 00084 void interpolate(GLclampf interp, value_type* vertex) const 00085 { 00086 GLclampf c; GLclampf u = modff(interp*number_of_curves, &c); 00087 if(c == number_of_curves){ c = number_of_curves-1; u = 1.0; } 00088 return curves[int(c)].interpolate(u,vertex); 00089 } 00090 00091 private: 00092 GLint number_of_curves; 00093 std::vector<curve_type > curves; 00094 }; 00095 00097 typedef CubicBezierSpline4<GLbyte> CubicBezierSpline4b; 00099 typedef CubicBezierSpline4<GLshort> CubicBezierSpline4s; 00101 typedef CubicBezierSpline4<GLint> CubicBezierSpline4i; 00103 typedef CubicBezierSpline4<GLfloat> CubicBezierSpline4f; 00105 typedef CubicBezierSpline4<GLdouble> CubicBezierSpline4d; 00106 00107 }; 00108 00109 #endif