csgeom/spline.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2001 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_SPLINE_H__ 00020 #define __CS_SPLINE_H__ 00021 00028 #include "csextern.h" 00029 00034 class CS_CSGEOM_EXPORT csSpline 00035 { 00036 protected: 00037 int dimensions; 00038 int num_points; 00039 float* time_points; 00040 float* points; 00041 bool precalculation_valid; 00042 int idx; 00043 00044 public: 00046 csSpline (int d, int p); 00047 00049 virtual ~csSpline (); 00050 00052 int GetDimensionCount () { return dimensions; } 00053 00055 int GetPointCount () { return num_points; } 00056 00061 void InsertPoint (int idx); 00062 00066 void RemovePoint (int idx); 00067 00074 void SetTimeValues (float* t); 00075 00079 void SetTimeValue (int idx, float t); 00080 00084 float* GetTimeValues () { return time_points; } 00085 00089 float GetTimeValue (int idx) { return GetTimeValues ()[idx]; } 00090 00097 void SetDimensionValues (int dim, float* d); 00098 00102 void SetDimensionValue (int dim, int idx, float d); 00103 00107 float* GetDimensionValues (int dim) { return &points[dim*num_points]; } 00108 00112 float GetDimensionValue (int dim, int idx) 00113 { 00114 float* d = &points[dim*num_points]; 00115 return d[idx]; 00116 } 00117 00121 virtual void Calculate (float time) = 0; 00122 00126 int GetCurrentIndex () { return idx; } 00127 00132 virtual float GetInterpolatedDimension (int dim) = 0; 00133 }; 00134 00138 class CS_CSGEOM_EXPORT csCubicSpline : public csSpline 00139 { 00140 private: 00141 bool derivatives_valid; 00142 float* derivative_points; 00143 00144 // The following values are calculated by Calculate() and 00145 // are used later by GetInterpolatedDimension(). 00146 float A, B, C, D; // For computation of a spline value. 00147 00148 private: 00149 void PrecalculateDerivatives (int dim); 00150 void PrecalculateDerivatives (); 00151 00152 public: 00154 csCubicSpline (int d, int p); 00155 00157 virtual ~csCubicSpline (); 00158 00162 virtual void Calculate (float time); 00163 00168 virtual float GetInterpolatedDimension (int dim); 00169 }; 00170 00174 class CS_CSGEOM_EXPORT csBSpline : public csSpline 00175 { 00176 private: 00177 // The following values are calculated by Calculate() and 00178 // are used later by GetInterpolatedDimension(). 00179 float t; 00180 00181 protected: 00183 virtual float BaseFunction (int i, float t); 00184 00185 public: 00187 csBSpline (int d, int p); 00188 00190 virtual ~csBSpline (); 00191 00195 virtual void Calculate (float time); 00196 00201 virtual float GetInterpolatedDimension (int dim); 00202 }; 00203 00207 class CS_CSGEOM_EXPORT csCatmullRomSpline : public csBSpline 00208 { 00209 protected: 00211 virtual float BaseFunction (int i, float t); 00212 00213 public: 00215 csCatmullRomSpline (int d, int p) : csBSpline (d, p) { } 00216 00218 virtual ~csCatmullRomSpline () {} 00219 }; 00220 00223 #endif // __CS_SPLINE_H__ 00224
Generated for Crystal Space by doxygen 1.2.18