Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

spline.h

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 
00026 class csSpline
00027 {
00028 protected:
00029   int dimensions;
00030   int num_points;
00031   float* time_points;
00032   float* points;
00033   bool precalculation_valid;
00034   int idx;
00035 
00036 public:
00038   csSpline (int d, int p);
00039 
00041   virtual ~csSpline ();
00042 
00044   int GetDimensionCount () { return dimensions; }
00045 
00047   int GetPointCount () { return num_points; }
00048 
00053   void InsertPoint (int idx);
00054 
00058   void RemovePoint (int idx);
00059 
00066   void SetTimeValues (float* t);
00067 
00071   void SetTimeValue (int idx, float t);
00072 
00076   float* GetTimeValues () { return time_points; }
00077 
00081   float GetTimeValue (int idx) { return GetTimeValues ()[idx]; }
00082 
00089   void SetDimensionValues (int dim, float* d);
00090 
00094   void SetDimensionValue (int dim, int idx, float d);
00095 
00099   float* GetDimensionValues (int dim) { return &points[dim*num_points]; }
00100 
00104   float GetDimensionValue (int dim, int idx)
00105   {
00106     float* d = &points[dim*num_points];
00107     return d[idx];
00108   }
00109 
00113   virtual void Calculate (float time) = 0;
00114 
00118   int GetCurrentIndex () { return idx; }
00119 
00124   virtual float GetInterpolatedDimension (int dim) = 0;
00125 };
00126 
00130 class csCubicSpline : public csSpline
00131 {
00132 private:
00133   bool derivatives_valid;
00134   float* derivative_points;
00135 
00136   // The following values are calculated by Calculate() and
00137   // are used later by GetInterpolatedDimension().
00138   float A, B, C, D;     // For computation of a spline value.
00139 
00140 private:
00141   void PrecalculateDerivatives (int dim);
00142   void PrecalculateDerivatives ();
00143 
00144 public:
00146   csCubicSpline (int d, int p);
00147 
00149   virtual ~csCubicSpline ();
00150 
00154   virtual void Calculate (float time);
00155 
00160   virtual float GetInterpolatedDimension (int dim);
00161 };
00162 
00166 class csBSpline : public csSpline
00167 {
00168 private:
00169   // The following values are calculated by Calculate() and
00170   // are used later by GetInterpolatedDimension().
00171   float t;
00172 
00173 protected:
00175   virtual float BaseFunction (int i, float t);
00176 
00177 public:
00179   csBSpline (int d, int p);
00180 
00182   virtual ~csBSpline ();
00183 
00187   virtual void Calculate (float time);
00188 
00193   virtual float GetInterpolatedDimension (int dim);
00194 };
00195 
00199 class csCatmullRomSpline : public csBSpline
00200 {
00201 protected:
00203   virtual float BaseFunction (int i, float t);
00204 
00205 public:
00207   csCatmullRomSpline (int d, int p) : csBSpline (d, p) { }
00208 };
00209 
00210 #endif // __CS_SPLINE_H__
00211 

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000