CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 
00032 class csSpline
00033 {
00034 protected:
00035   int dimensions;
00036   int num_points;
00037   float* time_points;
00038   float* points;
00039   bool precalculation_valid;
00040   int idx;
00041 
00042 public:
00044   csSpline (int d, int p);
00045 
00047   virtual ~csSpline ();
00048 
00050   int GetDimensionCount () { return dimensions; }
00051 
00053   int GetPointCount () { return num_points; }
00054 
00059   void InsertPoint (int idx);
00060 
00064   void RemovePoint (int idx);
00065 
00072   void SetTimeValues (float* t);
00073 
00077   void SetTimeValue (int idx, float t);
00078 
00082   float* GetTimeValues () { return time_points; }
00083 
00087   float GetTimeValue (int idx) { return GetTimeValues ()[idx]; }
00088 
00095   void SetDimensionValues (int dim, float* d);
00096 
00100   void SetDimensionValue (int dim, int idx, float d);
00101 
00105   float* GetDimensionValues (int dim) { return &points[dim*num_points]; }
00106 
00110   float GetDimensionValue (int dim, int idx)
00111   {
00112     float* d = &points[dim*num_points];
00113     return d[idx];
00114   }
00115 
00119   virtual void Calculate (float time) = 0;
00120 
00124   int GetCurrentIndex () { return idx; }
00125 
00130   virtual float GetInterpolatedDimension (int dim) = 0;
00131 };
00132 
00136 class csCubicSpline : public csSpline
00137 {
00138 private:
00139   bool derivatives_valid;
00140   float* derivative_points;
00141 
00142   // The following values are calculated by Calculate() and
00143   // are used later by GetInterpolatedDimension().
00144   float A, B, C, D;     // For computation of a spline value.
00145 
00146 private:
00147   void PrecalculateDerivatives (int dim);
00148   void PrecalculateDerivatives ();
00149 
00150 public:
00152   csCubicSpline (int d, int p);
00153 
00155   virtual ~csCubicSpline ();
00156 
00160   virtual void Calculate (float time);
00161 
00166   virtual float GetInterpolatedDimension (int dim);
00167 };
00168 
00172 class csBSpline : public csSpline
00173 {
00174 private:
00175   // The following values are calculated by Calculate() and
00176   // are used later by GetInterpolatedDimension().
00177   float t;
00178 
00179 protected:
00181   virtual float BaseFunction (int i, float t);
00182 
00183 public:
00185   csBSpline (int d, int p);
00186 
00188   virtual ~csBSpline ();
00189 
00193   virtual void Calculate (float time);
00194 
00199   virtual float GetInterpolatedDimension (int dim);
00200 };
00201 
00205 class csCatmullRomSpline : public csBSpline
00206 {
00207 protected:
00209   virtual float BaseFunction (int i, float t);
00210 
00211 public:
00213   csCatmullRomSpline (int d, int p) : csBSpline (d, p) { }
00214 };
00215 
00218 #endif // __CS_SPLINE_H__
00219 

Generated for Crystal Space by doxygen 1.2.14