## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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
    00036 #include "igeom/path.h"
    00037
    00044 class CS_CRYSTALSPACE_EXPORT csPath :
    00045   public scfImplementation1<csPath, 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   { }
    00078
    00080   virtual ~csPath ()
    00081   { }
    00082
    00084   virtual int Length ()
    00085   {
    00086     return spline.GetPointCount();
    00087   }
    00092   int GetPointCount()
    00093   {
    00094     return Length();
    00095   }
    00097   virtual void CalculateAtTime (float time)
    00098   {
    00099     spline.Calculate (time);
    00100   }
    00105   virtual void Calculate (float time)
    00106   {
    00107     CalculateAtTime(time);
    00108   }
    00110   virtual int GetCurrentIndex ()
    00111   {
    00112     return spline.GetCurrentIndex();
    00113   }
    00115   virtual float GetTime (int idx)
    00116   {
    00117     return spline.GetTimeValue(idx);
    00118   }
    00123   float GetTimeValue (int idx) const
    00124   {
    00125     return spline.GetTimeValue(idx);
    00126   }
    00128   virtual void SetTime (int idx, float t)
    00129   {
    00130     spline.SetTimeValue(idx,t);
    00131   }
    00136   virtual void SetTimeValue (int idx, float t)
    00137   {
    00138     SetTime(idx, t);
    00139   }
    00146   void SetTimes (float const* t)
    00147   {
    00148     spline.SetTimeValues(t);
    00149   }
    00154   void SetTimeValues (float const* t)
    00155   {
    00156     SetTimes(t);
    00157   }
    00159   float const* GetTimes () const
    00160   {
    00161     return spline.GetTimeValues();
    00162   }
    00167   float const* GetTimeValues () const
    00168   {
    00169     return GetTimes();
    00170   }
    00172   virtual void SetPositionVectors (csVector3* v)
    00173   {
    00174     SetVectorAsDimensionValues (0, v);
    00175   }
    00177   virtual void SetUpVectors (csVector3* v)
    00178   {
    00179     SetVectorAsDimensionValues (3, v);
    00180   }
    00182   virtual void SetForwardVectors (csVector3* v)
    00183   {
    00184     SetVectorAsDimensionValues (6, v);
    00185   }
    00187   virtual void SetPositionVector (int idx, const csVector3& v)
    00188   {
    00189     spline.SetDimensionValue (0, idx, v.x);
    00190     spline.SetDimensionValue (1, idx, v.y);
    00191     spline.SetDimensionValue (2, idx, v.z);
    00192   }
    00194   virtual void SetUpVector (int idx, const csVector3& v)
    00195   {
    00196     spline.SetDimensionValue (3, idx, v.x);
    00197     spline.SetDimensionValue (4, idx, v.y);
    00198     spline.SetDimensionValue (5, idx, v.z);
    00199   }
    00201   virtual void SetForwardVector (int idx, const csVector3& v)
    00202   {
    00203     spline.SetDimensionValue (6, idx, v.x);
    00204     spline.SetDimensionValue (7, idx, v.y);
    00205     spline.SetDimensionValue (8, idx, v.z);
    00206   }
    00208   virtual void GetPositionVector (int idx, csVector3& v)
    00209   {
    00210     v.x = spline.GetDimensionValue (0, idx);
    00211     v.y = spline.GetDimensionValue (1, idx);
    00212     v.z = spline.GetDimensionValue (2, idx);
    00213   }
    00215   virtual void GetUpVector (int idx, csVector3& v)
    00216   {
    00217     v.x = spline.GetDimensionValue (3, idx);
    00218     v.y = spline.GetDimensionValue (4, idx);
    00219     v.z = spline.GetDimensionValue (5, idx);
    00220   }
    00222   virtual void GetForwardVector (int idx, csVector3& v)
    00223   {
    00224     v.x = spline.GetDimensionValue (6, idx);
    00225     v.y = spline.GetDimensionValue (7, idx);
    00226     v.z = spline.GetDimensionValue (8, idx);
    00227   }
    00228
    00230   virtual void GetInterpolatedPosition (csVector3& pos)
    00231   {
    00232     pos.x = spline.GetInterpolatedDimension (0);
    00233     pos.y = spline.GetInterpolatedDimension (1);
    00234     pos.z = spline.GetInterpolatedDimension (2);
    00235   }
    00237   virtual void GetInterpolatedUp (csVector3& pos)
    00238   {
    00239     pos.x = spline.GetInterpolatedDimension (3);
    00240     pos.y = spline.GetInterpolatedDimension (4);
    00241     pos.z = spline.GetInterpolatedDimension (5);
    00242   }
    00244   virtual void GetInterpolatedForward (csVector3& pos)
    00245   {
    00246     pos.x = spline.GetInterpolatedDimension (6);
    00247     pos.y = spline.GetInterpolatedDimension (7);
    00248     pos.z = spline.GetInterpolatedDimension (8);
    00249   }
    00251   float const* GetDimensionValues (int dim) const
    00252   {
    00253     return spline.GetDimensionValues(dim);
    00254   }
    00256   float GetDimensionValue (int dim, int idx) const
    00257   {
    00258     return spline.GetDimensionValue(dim, idx);
    00259   }
    00264   void InsertPoint (int idx)
    00265   {
    00266     spline.InsertPoint(idx);
    00267   }
    00269   void RemovePoint (int idx)
    00270   {
    00271     spline.RemovePoint(idx);
    00272   }
    00273 };
    00274
    00277 #endif // __CS_PATH_H__