CrystalSpace

Public API Reference

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

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

Generated for Crystal Space by doxygen 1.2.18