Crystal Space: csgeom/path.h Source File (Crystal Space Public API Reference)

| ## 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   CS_DEPRECATED_METHOD_MSG("Use Length() instead.")
    00093   int GetPointCount()
    00094   {
    00095     return Length();
    00096   }
    00098   virtual void CalculateAtTime (float time)
    00099   {
    00100     spline.Calculate (time);
    00101   }
    00106   CS_DEPRECATED_METHOD_MSG("Use CalculateAtTime() instead.")
    00107   virtual void Calculate (float time)
    00108   {
    00109     CalculateAtTime(time);
    00110   }
    00112   virtual int GetCurrentIndex ()
    00113   {
    00114     return spline.GetCurrentIndex();
    00115   }
    00117   virtual float GetTime (int idx)
    00118   {
    00119     return spline.GetTimeValue(idx);
    00120   }
    00125   CS_DEPRECATED_METHOD_MSG("Use GetTime() instead.")
    00126   float GetTimeValue (int idx) const
    00127   {
    00128     return spline.GetTimeValue(idx);
    00129   }
    00131   virtual void SetTime (int idx, float t)
    00132   {
    00133     spline.SetTimeValue(idx,t);
    00134   }
    00139   CS_DEPRECATED_METHOD_MSG("Use SetTime() instead.")
    00140   virtual void SetTimeValue (int idx, float t)
    00141   {
    00142     SetTime(idx, t);
    00143   }
    00150   void SetTimes (float const* t)
    00151   {
    00152     spline.SetTimeValues(t);
    00153   }
    00158   CS_DEPRECATED_METHOD_MSG("Use SetTimes() instead.")
    00159   void SetTimeValues (float const* t)
    00160   {
    00161     SetTimes(t);
    00162   }
    00164   float const* GetTimes () const
    00165   {
    00166     return spline.GetTimeValues();
    00167   }
    00172   CS_DEPRECATED_METHOD_MSG("Use GetTimes() instead.")
    00173   float const* GetTimeValues () const
    00174   {
    00175     return GetTimes();
    00176   }
    00178   virtual void SetPositionVectors (csVector3* v)
    00179   {
    00180     SetVectorAsDimensionValues (0, v);
    00181   }
    00183   virtual void SetUpVectors (csVector3* v)
    00184   {
    00185     SetVectorAsDimensionValues (3, v);
    00186   }
    00188   virtual void SetForwardVectors (csVector3* v)
    00189   {
    00190     SetVectorAsDimensionValues (6, v);
    00191   }
    00193   virtual void SetPositionVector (int idx, const csVector3& v)
    00194   {
    00195     spline.SetDimensionValue (0, idx, v.x);
    00196     spline.SetDimensionValue (1, idx, v.y);
    00197     spline.SetDimensionValue (2, idx, v.z);
    00198   }
    00200   virtual void SetUpVector (int idx, const csVector3& v)
    00201   {
    00202     spline.SetDimensionValue (3, idx, v.x);
    00203     spline.SetDimensionValue (4, idx, v.y);
    00204     spline.SetDimensionValue (5, idx, v.z);
    00205   }
    00207   virtual void SetForwardVector (int idx, const csVector3& v)
    00208   {
    00209     spline.SetDimensionValue (6, idx, v.x);
    00210     spline.SetDimensionValue (7, idx, v.y);
    00211     spline.SetDimensionValue (8, idx, v.z);
    00212   }
    00214   virtual void GetPositionVector (int idx, csVector3& v)
    00215   {
    00216     v.x = spline.GetDimensionValue (0, idx);
    00217     v.y = spline.GetDimensionValue (1, idx);
    00218     v.z = spline.GetDimensionValue (2, idx);
    00219   }
    00221   virtual void GetUpVector (int idx, csVector3& v)
    00222   {
    00223     v.x = spline.GetDimensionValue (3, idx);
    00224     v.y = spline.GetDimensionValue (4, idx);
    00225     v.z = spline.GetDimensionValue (5, idx);
    00226   }
    00228   virtual void GetForwardVector (int idx, csVector3& v)
    00229   {
    00230     v.x = spline.GetDimensionValue (6, idx);
    00231     v.y = spline.GetDimensionValue (7, idx);
    00232     v.z = spline.GetDimensionValue (8, idx);
    00233   }
    00234
    00236   virtual void GetInterpolatedPosition (csVector3& pos)
    00237   {
    00238     pos.x = spline.GetInterpolatedDimension (0);
    00239     pos.y = spline.GetInterpolatedDimension (1);
    00240     pos.z = spline.GetInterpolatedDimension (2);
    00241   }
    00243   virtual void GetInterpolatedUp (csVector3& pos)
    00244   {
    00245     pos.x = spline.GetInterpolatedDimension (3);
    00246     pos.y = spline.GetInterpolatedDimension (4);
    00247     pos.z = spline.GetInterpolatedDimension (5);
    00248   }
    00250   virtual void GetInterpolatedForward (csVector3& pos)
    00251   {
    00252     pos.x = spline.GetInterpolatedDimension (6);
    00253     pos.y = spline.GetInterpolatedDimension (7);
    00254     pos.z = spline.GetInterpolatedDimension (8);
    00255   }
    00257   float const* GetDimensionValues (int dim) const
    00258   {
    00259     return spline.GetDimensionValues(dim);
    00260   }
    00262   float GetDimensionValue (int dim, int idx) const
    00263   {
    00264     return spline.GetDimensionValue(dim, idx);
    00265   }
    00270   void InsertPoint (int idx)
    00271   {
    00272     spline.InsertPoint(idx);
    00273   }
    00275   void RemovePoint (int idx)
    00276   {
    00277     spline.RemovePoint(idx);
    00278   }
    00279 };
    00280
    00283 #endif // __CS_PATH_H__