CrystalSpace

Public API Reference

csgeom/path.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_PATH_H__
00020 #define __CS_PATH_H__
00021 
00022 
00030 #include "csextern.h"
00031 
00032 #include "csgeom/spline.h"
00033 #include "csgeom/vector3.h"
00034 #include "csutil/scf_implementation.h"
00035 #include "csutil/csobject.h"
00036 
00037 #include "igeom/path.h"
00038 
00045 class csPath : public scfImplementationExt1<csPath, csObject, iPath>
00046 {
00047 protected:
00048   csCatmullRomSpline spline;
00049 
00050 private:
00051   void SetVectorAsDimensionValues (int dim, csVector3* v)
00052   {
00053     int i;
00054     int N = spline.GetPointCount();
00055     float* x, * y, * z;
00056     x = new float [N];
00057     y = new float [N];
00058     z = new float [N];
00059     for (i = 0 ; i < N ; i++)
00060     {
00061       x[i] = v[i].x;
00062       y[i] = v[i].y;
00063       z[i] = v[i].z;
00064     }
00065     spline.SetDimensionValues (dim+0, x);
00066     spline.SetDimensionValues (dim+1, y);
00067     spline.SetDimensionValues (dim+2, z);
00068     delete[] x;
00069     delete[] y;
00070     delete[] z;
00071   }
00072 
00073 public:
00074 
00076   csPath (int p) : scfImplementationType(this), spline (9, p) {};
00077 
00079   void Setup (int p) { spline.Setup (9, p); }
00080 
00082   virtual ~csPath ()
00083   { }
00084 
00086   virtual int Length ()
00087   {
00088     return spline.GetPointCount();
00089   }
00090 
00091   // Get the iObject for this path.
00092   virtual iObject* QueryObject ()
00093   { 
00094     return this; 
00095   }
00096 
00098   virtual void CalculateAtTime (float time)
00099   {
00100     spline.Calculate (time);
00101   }
00102  
00104   virtual int GetCurrentIndex ()
00105   {
00106     return spline.GetCurrentIndex();
00107   }
00109   virtual float GetTime (int idx)
00110   {
00111     return spline.GetTimeValue(idx);
00112   }
00113   
00115   virtual void SetTime (int idx, float t)
00116   {
00117     spline.SetTimeValue(idx,t);
00118   }
00119   
00126   void SetTimes (float const* t)
00127   {
00128     spline.SetTimeValues(t);
00129   }
00130  
00132   float const* GetTimes () const
00133   {
00134     return spline.GetTimeValues();
00135   }
00136   
00138   virtual void SetPositionVectors (csVector3* v)
00139   {
00140     SetVectorAsDimensionValues (0, v);
00141   }
00143   virtual void SetUpVectors (csVector3* v)
00144   {
00145     SetVectorAsDimensionValues (3, v);
00146   }
00148   virtual void SetForwardVectors (csVector3* v)
00149   {
00150     SetVectorAsDimensionValues (6, v);
00151   }
00153   virtual void SetPositionVector (int idx, const csVector3& v)
00154   {
00155     spline.SetDimensionValue (0, idx, v.x);
00156     spline.SetDimensionValue (1, idx, v.y);
00157     spline.SetDimensionValue (2, idx, v.z);
00158   }
00160   virtual void SetUpVector (int idx, const csVector3& v)
00161   {
00162     spline.SetDimensionValue (3, idx, v.x);
00163     spline.SetDimensionValue (4, idx, v.y);
00164     spline.SetDimensionValue (5, idx, v.z);
00165   }
00167   virtual void SetForwardVector (int idx, const csVector3& v)
00168   {
00169     spline.SetDimensionValue (6, idx, v.x);
00170     spline.SetDimensionValue (7, idx, v.y);
00171     spline.SetDimensionValue (8, idx, v.z);
00172   }
00174   virtual void GetPositionVector (int idx, csVector3& v)
00175   {
00176     v.x = spline.GetDimensionValue (0, idx);
00177     v.y = spline.GetDimensionValue (1, idx);
00178     v.z = spline.GetDimensionValue (2, idx);
00179   }
00181   virtual void GetUpVector (int idx, csVector3& v)
00182   {
00183     v.x = spline.GetDimensionValue (3, idx);
00184     v.y = spline.GetDimensionValue (4, idx);
00185     v.z = spline.GetDimensionValue (5, idx);
00186   }
00188   virtual void GetForwardVector (int idx, csVector3& v)
00189   {
00190     v.x = spline.GetDimensionValue (6, idx);
00191     v.y = spline.GetDimensionValue (7, idx);
00192     v.z = spline.GetDimensionValue (8, idx);
00193   }
00194 
00196   virtual void GetInterpolatedPosition (csVector3& pos)
00197   {
00198     pos.x = spline.GetInterpolatedDimension (0);
00199     pos.y = spline.GetInterpolatedDimension (1);
00200     pos.z = spline.GetInterpolatedDimension (2);
00201   }
00203   virtual void GetInterpolatedUp (csVector3& pos)
00204   {
00205     pos.x = spline.GetInterpolatedDimension (3);
00206     pos.y = spline.GetInterpolatedDimension (4);
00207     pos.z = spline.GetInterpolatedDimension (5);
00208   }
00210   virtual void GetInterpolatedForward (csVector3& pos)
00211   {
00212     pos.x = spline.GetInterpolatedDimension (6);
00213     pos.y = spline.GetInterpolatedDimension (7);
00214     pos.z = spline.GetInterpolatedDimension (8);
00215   }
00217   float const* GetDimensionValues (int dim) const
00218   {
00219     return spline.GetDimensionValues(dim);
00220   }
00222   float GetDimensionValue (int dim, int idx) const
00223   {
00224     return spline.GetDimensionValue(dim, idx);
00225   }
00230   void InsertPoint (int idx)
00231   {
00232     spline.InsertPoint(idx);
00233   }
00235   void RemovePoint (int idx)
00236   {
00237     spline.RemovePoint(idx);
00238   }
00239 };
00240 
00243 #endif // __CS_PATH_H__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1