Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | 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 "csgeom/spline.h" 00032 #include "csgeom/vector3.h" 00033 #include "csutil/scf_implementation.h" 00034 00035 #include "igeom/path.h" 00036 00043 class CS_CRYSTALSPACE_EXPORT csPath : 00044 public scfImplementation1<csPath, iPath> 00045 { 00046 protected: 00047 csCatmullRomSpline spline; 00048 00049 private: 00050 void SetVectorAsDimensionValues (int dim, csVector3* v) 00051 { 00052 int i; 00053 int N = spline.GetPointCount(); 00054 float* x, * y, * z; 00055 x = new float [N]; 00056 y = new float [N]; 00057 z = new float [N]; 00058 for (i = 0 ; i < N ; i++) 00059 { 00060 x[i] = v[i].x; 00061 y[i] = v[i].y; 00062 z[i] = v[i].z; 00063 } 00064 spline.SetDimensionValues (dim+0, x); 00065 spline.SetDimensionValues (dim+1, y); 00066 spline.SetDimensionValues (dim+2, z); 00067 delete[] x; 00068 delete[] y; 00069 delete[] z; 00070 } 00071 00072 public: 00073 00075 csPath (int p) : scfImplementationType(this), spline (9, p) 00076 { } 00077 00079 virtual ~csPath () 00080 { } 00081 00083 virtual int Length () 00084 { 00085 return spline.GetPointCount(); 00086 } 00091 int GetPointCount() 00092 { 00093 return Length(); 00094 } 00096 virtual void CalculateAtTime (float time) 00097 { 00098 spline.Calculate (time); 00099 } 00104 virtual void Calculate (float time) 00105 { 00106 CalculateAtTime(time); 00107 } 00109 virtual int GetCurrentIndex () 00110 { 00111 return spline.GetCurrentIndex(); 00112 } 00114 virtual float GetTime (int idx) 00115 { 00116 return spline.GetTimeValue(idx); 00117 } 00122 float GetTimeValue (int idx) const 00123 { 00124 return spline.GetTimeValue(idx); 00125 } 00127 virtual void SetTime (int idx, float t) 00128 { 00129 spline.SetTimeValue(idx,t); 00130 } 00135 virtual void SetTimeValue (int idx, float t) 00136 { 00137 SetTime(idx, t); 00138 } 00145 void SetTimes (float const* t) 00146 { 00147 spline.SetTimeValues(t); 00148 } 00153 void SetTimeValues (float const* t) 00154 { 00155 SetTimes(t); 00156 } 00158 float const* GetTimes () const 00159 { 00160 return spline.GetTimeValues(); 00161 } 00166 float const* GetTimeValues () const 00167 { 00168 return GetTimes(); 00169 } 00171 virtual void SetPositionVectors (csVector3* v) 00172 { 00173 SetVectorAsDimensionValues (0, v); 00174 } 00176 virtual void SetUpVectors (csVector3* v) 00177 { 00178 SetVectorAsDimensionValues (3, v); 00179 } 00181 virtual void SetForwardVectors (csVector3* v) 00182 { 00183 SetVectorAsDimensionValues (6, v); 00184 } 00186 virtual void SetPositionVector (int idx, const csVector3& v) 00187 { 00188 spline.SetDimensionValue (0, idx, v.x); 00189 spline.SetDimensionValue (1, idx, v.y); 00190 spline.SetDimensionValue (2, idx, v.z); 00191 } 00193 virtual void SetUpVector (int idx, const csVector3& v) 00194 { 00195 spline.SetDimensionValue (3, idx, v.x); 00196 spline.SetDimensionValue (4, idx, v.y); 00197 spline.SetDimensionValue (5, idx, v.z); 00198 } 00200 virtual void SetForwardVector (int idx, const csVector3& v) 00201 { 00202 spline.SetDimensionValue (6, idx, v.x); 00203 spline.SetDimensionValue (7, idx, v.y); 00204 spline.SetDimensionValue (8, idx, v.z); 00205 } 00207 virtual void GetPositionVector (int idx, csVector3& v) 00208 { 00209 v.x = spline.GetDimensionValue (0, idx); 00210 v.y = spline.GetDimensionValue (1, idx); 00211 v.z = spline.GetDimensionValue (2, idx); 00212 } 00214 virtual void GetUpVector (int idx, csVector3& v) 00215 { 00216 v.x = spline.GetDimensionValue (3, idx); 00217 v.y = spline.GetDimensionValue (4, idx); 00218 v.z = spline.GetDimensionValue (5, idx); 00219 } 00221 virtual void GetForwardVector (int idx, csVector3& v) 00222 { 00223 v.x = spline.GetDimensionValue (6, idx); 00224 v.y = spline.GetDimensionValue (7, idx); 00225 v.z = spline.GetDimensionValue (8, idx); 00226 } 00227 00229 virtual void GetInterpolatedPosition (csVector3& pos) 00230 { 00231 pos.x = spline.GetInterpolatedDimension (0); 00232 pos.y = spline.GetInterpolatedDimension (1); 00233 pos.z = spline.GetInterpolatedDimension (2); 00234 } 00236 virtual void GetInterpolatedUp (csVector3& pos) 00237 { 00238 pos.x = spline.GetInterpolatedDimension (3); 00239 pos.y = spline.GetInterpolatedDimension (4); 00240 pos.z = spline.GetInterpolatedDimension (5); 00241 } 00243 virtual void GetInterpolatedForward (csVector3& pos) 00244 { 00245 pos.x = spline.GetInterpolatedDimension (6); 00246 pos.y = spline.GetInterpolatedDimension (7); 00247 pos.z = spline.GetInterpolatedDimension (8); 00248 } 00250 float const* GetDimensionValues (int dim) const 00251 { 00252 return spline.GetDimensionValues(dim); 00253 } 00255 float GetDimensionValue (int dim, int idx) const 00256 { 00257 return spline.GetDimensionValue(dim, idx); 00258 } 00263 void InsertPoint (int idx) 00264 { 00265 spline.InsertPoint(idx); 00266 } 00268 void RemovePoint (int idx) 00269 { 00270 spline.RemovePoint(idx); 00271 } 00272 }; 00273 00276 #endif // __CS_PATH_H__
Generated for Crystal Space by doxygen 1.4.4