CubicBezierCurve.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 GLCUBICBEZIERCURVE_H
00021 #define GLCUBICBEZIERCURVE_H
00022 
00023 
00024 #include "GLMatrix.h"
00025 
00026 namespace mathglpp
00027 {
00028 
00035 template <typename T>
00036 class CubicBezierCurve4
00037 {
00038 public:
00039     enum { D = 4 };
00040     typedef T value_type;
00041     typedef GLMatrix<value_type> matrix_type;
00042 
00044     CubicBezierCurve4(const value_type* cpoints)
00045     :basis(cpoints)
00046     {
00048         static value_type coeffs[D*D] =
00049             {  1, -0,  0, -0,
00050               -3,  3, -0,  0,
00051                3, -6,  3, -0,
00052               -1,  3, -3,  1 };
00053 
00055         basis *= GLMatrix<value_type>(coeffs);
00056     }
00057 
00059     CubicBezierCurve4(const value_type* c0, const value_type* c1, const value_type* c2, const value_type* c3)
00060     :basis(c0,c1,c2,c3)
00061     {
00063         static value_type coeffs[16] =
00064             {  1, -0,  0, -0,
00065               -3,  3, -0,  0,
00066                3, -6,  3, -0,
00067               -1,  3, -3,  1 };
00068 
00069 
00071         basis *= GLMatrix<value_type>(coeffs);
00072     }
00073 
00074     CubicBezierCurve4(const CubicBezierCurve4& bc)
00075     :basis(bc.basis){}
00076 
00078     ~CubicBezierCurve4(){}
00079 
00081     inline void interpolate(GLclampf interp, value_type* vertex) const
00082     {
00083         vertex[0] = 1;
00084         vertex[1] = value_type(interp);
00085         vertex[2] = value_type(interp * interp);
00086         vertex[3] = value_type(interp * interp * interp);
00087         basis.vdot4(vertex);
00088     }
00089 
00090 private:
00091     GLMatrix<value_type> basis;
00092 };
00093 
00094 
00096 typedef CubicBezierCurve4<GLbyte> CubicBezierCurve4b;
00098 typedef CubicBezierCurve4<GLshort> CubicBezierCurve4s;
00100 typedef CubicBezierCurve4<GLint> CubicBezierCurve4i;
00102 typedef CubicBezierCurve4<GLfloat> CubicBezierCurve4f;
00104 typedef CubicBezierCurve4<GLdouble> CubicBezierCurve4d;
00105 
00106 };
00107 
00108 #endif

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