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 } 00088 00090 virtual void CalculateAtTime (float time) 00091 { 00092 spline.Calculate (time); 00093 } 00094 00096 virtual int GetCurrentIndex () 00097 { 00098 return spline.GetCurrentIndex(); 00099 } 00101 virtual float GetTime (int idx) 00102 { 00103 return spline.GetTimeValue(idx); 00104 } 00105 00107 virtual void SetTime (int idx, float t) 00108 { 00109 spline.SetTimeValue(idx,t); 00110 } 00111 00118 void SetTimes (float const* t) 00119 { 00120 spline.SetTimeValues(t); 00121 } 00122 00124 float const* GetTimes () const 00125 { 00126 return spline.GetTimeValues(); 00127 } 00128 00130 virtual void SetPositionVectors (csVector3* v) 00131 { 00132 SetVectorAsDimensionValues (0, v); 00133 } 00135 virtual void SetUpVectors (csVector3* v) 00136 { 00137 SetVectorAsDimensionValues (3, v); 00138 } 00140 virtual void SetForwardVectors (csVector3* v) 00141 { 00142 SetVectorAsDimensionValues (6, v); 00143 } 00145 virtual void SetPositionVector (int idx, const csVector3& v) 00146 { 00147 spline.SetDimensionValue (0, idx, v.x); 00148 spline.SetDimensionValue (1, idx, v.y); 00149 spline.SetDimensionValue (2, idx, v.z); 00150 } 00152 virtual void SetUpVector (int idx, const csVector3& v) 00153 { 00154 spline.SetDimensionValue (3, idx, v.x); 00155 spline.SetDimensionValue (4, idx, v.y); 00156 spline.SetDimensionValue (5, idx, v.z); 00157 } 00159 virtual void SetForwardVector (int idx, const csVector3& v) 00160 { 00161 spline.SetDimensionValue (6, idx, v.x); 00162 spline.SetDimensionValue (7, idx, v.y); 00163 spline.SetDimensionValue (8, idx, v.z); 00164 } 00166 virtual void GetPositionVector (int idx, csVector3& v) 00167 { 00168 v.x = spline.GetDimensionValue (0, idx); 00169 v.y = spline.GetDimensionValue (1, idx); 00170 v.z = spline.GetDimensionValue (2, idx); 00171 } 00173 virtual void GetUpVector (int idx, csVector3& v) 00174 { 00175 v.x = spline.GetDimensionValue (3, idx); 00176 v.y = spline.GetDimensionValue (4, idx); 00177 v.z = spline.GetDimensionValue (5, idx); 00178 } 00180 virtual void GetForwardVector (int idx, csVector3& v) 00181 { 00182 v.x = spline.GetDimensionValue (6, idx); 00183 v.y = spline.GetDimensionValue (7, idx); 00184 v.z = spline.GetDimensionValue (8, idx); 00185 } 00186 00188 virtual void GetInterpolatedPosition (csVector3& pos) 00189 { 00190 pos.x = spline.GetInterpolatedDimension (0); 00191 pos.y = spline.GetInterpolatedDimension (1); 00192 pos.z = spline.GetInterpolatedDimension (2); 00193 } 00195 virtual void GetInterpolatedUp (csVector3& pos) 00196 { 00197 pos.x = spline.GetInterpolatedDimension (3); 00198 pos.y = spline.GetInterpolatedDimension (4); 00199 pos.z = spline.GetInterpolatedDimension (5); 00200 } 00202 virtual void GetInterpolatedForward (csVector3& pos) 00203 { 00204 pos.x = spline.GetInterpolatedDimension (6); 00205 pos.y = spline.GetInterpolatedDimension (7); 00206 pos.z = spline.GetInterpolatedDimension (8); 00207 } 00209 float const* GetDimensionValues (int dim) const 00210 { 00211 return spline.GetDimensionValues(dim); 00212 } 00214 float GetDimensionValue (int dim, int idx) const 00215 { 00216 return spline.GetDimensionValue(dim, idx); 00217 } 00222 void InsertPoint (int idx) 00223 { 00224 spline.InsertPoint(idx); 00225 } 00227 void RemovePoint (int idx) 00228 { 00229 spline.RemovePoint(idx); 00230 } 00231 }; 00232 00235 #endif // __CS_PATH_H__
Generated for Crystal Space 1.2.1 by doxygen 1.5.3