CrystalSpace

Public API Reference

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

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 
00029 #include "csextern.h"
00030 
00031 #include "csutil/scf.h"
00032 #include "csgeom/spline.h"
00033 #include "csgeom/vector3.h"
00034 #include "igeom/path.h"
00035 
00042 class CS_CSGEOM_EXPORT csPath : public csCatmullRomSpline, public iPath
00043 {
00044 private:
00045   void SetVectorAsDimensionValues (int dim, csVector3* v)
00046   {
00047     int i;
00048     float* x, * y, * z;
00049     x = new float [GetPointCount ()];
00050     y = new float [GetPointCount ()];
00051     z = new float [GetPointCount ()];
00052     for (i = 0 ; i < GetPointCount () ; i++)
00053     {
00054       x[i] = v[i].x;
00055       y[i] = v[i].y;
00056       z[i] = v[i].z;
00057     }
00058     SetDimensionValues (dim+0, x);
00059     SetDimensionValues (dim+1, y);
00060     SetDimensionValues (dim+2, z);
00061     delete[] x;
00062     delete[] y;
00063     delete[] z;
00064   }
00065 
00066 public:
00067   SCF_DECLARE_IBASE;
00068 
00070   csPath (int p) : csCatmullRomSpline (9, p)
00071   {
00072     SCF_CONSTRUCT_IBASE (0);
00073   }
00074 
00076   virtual ~csPath () { SCF_DESTRUCT_IBASE(); }
00077 
00079   int Length ()
00080   {
00081     return GetPointCount();
00082   }
00084   void CalculateAtTime (float time)
00085   {
00086     Calculate (time);
00087   }
00088   int GetCurrentIndex ()
00089   {
00090     return csCatmullRomSpline::GetCurrentIndex();
00091   }
00092   float GetTime (int idx)
00093   {
00094     return GetTimeValue(idx);
00095   }
00096   void SetTime (int idx, float t)
00097   {
00098     SetTimeValue(idx,t);
00099   }
00100 
00102   void SetPositionVectors (csVector3* v)
00103   {
00104     SetVectorAsDimensionValues (0, v);
00105   }
00107   void SetUpVectors (csVector3* v)
00108   {
00109     SetVectorAsDimensionValues (3, v);
00110   }
00112   void SetForwardVectors (csVector3* v)
00113   {
00114     SetVectorAsDimensionValues (6, v);
00115   }
00117   void SetPositionVector (int idx, const csVector3& v)
00118   {
00119     SetDimensionValue (0, idx, v.x);
00120     SetDimensionValue (1, idx, v.y);
00121     SetDimensionValue (2, idx, v.z);
00122   }
00124   void SetUpVector (int idx, const csVector3& v)
00125   {
00126     SetDimensionValue (3, idx, v.x);
00127     SetDimensionValue (4, idx, v.y);
00128     SetDimensionValue (5, idx, v.z);
00129   }
00131   void SetForwardVector (int idx, const csVector3& v)
00132   {
00133     SetDimensionValue (6, idx, v.x);
00134     SetDimensionValue (7, idx, v.y);
00135     SetDimensionValue (8, idx, v.z);
00136   }
00138   void GetPositionVector (int idx, csVector3& v)
00139   {
00140     v.x = GetDimensionValue (0, idx);
00141     v.y = GetDimensionValue (1, idx);
00142     v.z = GetDimensionValue (2, idx);
00143   }
00145   void GetUpVector (int idx, csVector3& v)
00146   {
00147     v.x = GetDimensionValue (3, idx);
00148     v.y = GetDimensionValue (4, idx);
00149     v.z = GetDimensionValue (5, idx);
00150   }
00152   void GetForwardVector (int idx, csVector3& v)
00153   {
00154     v.x = GetDimensionValue (6, idx);
00155     v.y = GetDimensionValue (7, idx);
00156     v.z = GetDimensionValue (8, idx);
00157   }
00158 
00160   void GetInterpolatedPosition (csVector3& pos)
00161   {
00162     pos.x = GetInterpolatedDimension (0);
00163     pos.y = GetInterpolatedDimension (1);
00164     pos.z = GetInterpolatedDimension (2);
00165   }
00167   void GetInterpolatedUp (csVector3& pos)
00168   {
00169     pos.x = GetInterpolatedDimension (3);
00170     pos.y = GetInterpolatedDimension (4);
00171     pos.z = GetInterpolatedDimension (5);
00172   }
00174   void GetInterpolatedForward (csVector3& pos)
00175   {
00176     pos.x = GetInterpolatedDimension (6);
00177     pos.y = GetInterpolatedDimension (7);
00178     pos.z = GetInterpolatedDimension (8);
00179   }
00180 };
00181 
00184 #endif // __CS_PATH_H__

Generated for Crystal Space by doxygen 1.3.9.1