CubicBezierSpline.h

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 "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

Generated on Wed Oct 3 12:50:48 2007 for MathGL++ by  doxygen 1.5.2