00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00071 virtual ~csPath () { }
00072
00074 int Length ()
00075 {
00076 return GetPointCount();
00077 }
00079 void CalculateAtTime (float time)
00080 {
00081 Calculate (time);
00082 }
00083 int GetCurrentIndex ()
00084 {
00085 return csCatmullRomSpline::GetCurrentIndex();
00086 }
00087 float GetTime (int idx)
00088 {
00089 return GetTimeValue(idx);
00090 }
00091 void SetTime (int idx, float t)
00092 {
00093 SetTimeValue(idx,t);
00094 }
00095
00097 void SetPositionVectors (csVector3* v)
00098 {
00099 SetVectorAsDimensionValues (0, v);
00100 }
00102 void SetUpVectors (csVector3* v)
00103 {
00104 SetVectorAsDimensionValues (3, v);
00105 }
00107 void SetForwardVectors (csVector3* v)
00108 {
00109 SetVectorAsDimensionValues (6, v);
00110 }
00112 void SetPositionVector (int idx, const csVector3& v)
00113 {
00114 SetDimensionValue (0, idx, v.x);
00115 SetDimensionValue (1, idx, v.y);
00116 SetDimensionValue (2, idx, v.z);
00117 }
00119 void SetUpVector (int idx, const csVector3& v)
00120 {
00121 SetDimensionValue (3, idx, v.x);
00122 SetDimensionValue (4, idx, v.y);
00123 SetDimensionValue (5, idx, v.z);
00124 }
00126 void SetForwardVector (int idx, const csVector3& v)
00127 {
00128 SetDimensionValue (6, idx, v.x);
00129 SetDimensionValue (7, idx, v.y);
00130 SetDimensionValue (8, idx, v.z);
00131 }
00133 void GetPositionVector (int idx, csVector3& v)
00134 {
00135 v.x = GetDimensionValue (0, idx);
00136 v.y = GetDimensionValue (1, idx);
00137 v.z = GetDimensionValue (2, idx);
00138 }
00140 void GetUpVector (int idx, csVector3& v)
00141 {
00142 v.x = GetDimensionValue (3, idx);
00143 v.y = GetDimensionValue (4, idx);
00144 v.z = GetDimensionValue (5, idx);
00145 }
00147 void GetForwardVector (int idx, csVector3& v)
00148 {
00149 v.x = GetDimensionValue (6, idx);
00150 v.y = GetDimensionValue (7, idx);
00151 v.z = GetDimensionValue (8, idx);
00152 }
00153
00155 void GetInterpolatedPosition (csVector3& pos)
00156 {
00157 pos.x = GetInterpolatedDimension (0);
00158 pos.y = GetInterpolatedDimension (1);
00159 pos.z = GetInterpolatedDimension (2);
00160 }
00162 void GetInterpolatedUp (csVector3& pos)
00163 {
00164 pos.x = GetInterpolatedDimension (3);
00165 pos.y = GetInterpolatedDimension (4);
00166 pos.z = GetInterpolatedDimension (5);
00167 }
00169 void GetInterpolatedForward (csVector3& pos)
00170 {
00171 pos.x = GetInterpolatedDimension (6);
00172 pos.y = GetInterpolatedDimension (7);
00173 pos.z = GetInterpolatedDimension (8);
00174 }
00175 };
00176
00179 #endif // __CS_PATH_H__