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 #include "csutil/csobject.h" 00036 00037 #include "igeom/path.h" 00038 00045 class csPath : public scfImplementationExt1<csPath, csObject, 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 00079 virtual ~csPath () 00080 { } 00081 00083 virtual int Length () 00084 { 00085 return spline.GetPointCount(); 00086 } 00087 00088 // Get the iObject for this path. 00089 virtual iObject* QueryObject () 00090 { 00091 return this; 00092 } 00093 00095 virtual void CalculateAtTime (float time) 00096 { 00097 spline.Calculate (time); 00098 } 00099 00101 virtual int GetCurrentIndex () 00102 { 00103 return spline.GetCurrentIndex(); 00104 } 00106 virtual float GetTime (int idx) 00107 { 00108 return spline.GetTimeValue(idx); 00109 } 00110 00112 virtual void SetTime (int idx, float t) 00113 { 00114 spline.SetTimeValue(idx,t); 00115 } 00116 00123 void SetTimes (float const* t) 00124 { 00125 spline.SetTimeValues(t); 00126 } 00127 00129 float const* GetTimes () const 00130 { 00131 return spline.GetTimeValues(); 00132 } 00133 00135 virtual void SetPositionVectors (csVector3* v) 00136 { 00137 SetVectorAsDimensionValues (0, v); 00138 } 00140 virtual void SetUpVectors (csVector3* v) 00141 { 00142 SetVectorAsDimensionValues (3, v); 00143 } 00145 virtual void SetForwardVectors (csVector3* v) 00146 { 00147 SetVectorAsDimensionValues (6, v); 00148 } 00150 virtual void SetPositionVector (int idx, const csVector3& v) 00151 { 00152 spline.SetDimensionValue (0, idx, v.x); 00153 spline.SetDimensionValue (1, idx, v.y); 00154 spline.SetDimensionValue (2, idx, v.z); 00155 } 00157 virtual void SetUpVector (int idx, const csVector3& v) 00158 { 00159 spline.SetDimensionValue (3, idx, v.x); 00160 spline.SetDimensionValue (4, idx, v.y); 00161 spline.SetDimensionValue (5, idx, v.z); 00162 } 00164 virtual void SetForwardVector (int idx, const csVector3& v) 00165 { 00166 spline.SetDimensionValue (6, idx, v.x); 00167 spline.SetDimensionValue (7, idx, v.y); 00168 spline.SetDimensionValue (8, idx, v.z); 00169 } 00171 virtual void GetPositionVector (int idx, csVector3& v) 00172 { 00173 v.x = spline.GetDimensionValue (0, idx); 00174 v.y = spline.GetDimensionValue (1, idx); 00175 v.z = spline.GetDimensionValue (2, idx); 00176 } 00178 virtual void GetUpVector (int idx, csVector3& v) 00179 { 00180 v.x = spline.GetDimensionValue (3, idx); 00181 v.y = spline.GetDimensionValue (4, idx); 00182 v.z = spline.GetDimensionValue (5, idx); 00183 } 00185 virtual void GetForwardVector (int idx, csVector3& v) 00186 { 00187 v.x = spline.GetDimensionValue (6, idx); 00188 v.y = spline.GetDimensionValue (7, idx); 00189 v.z = spline.GetDimensionValue (8, idx); 00190 } 00191 00193 virtual void GetInterpolatedPosition (csVector3& pos) 00194 { 00195 pos.x = spline.GetInterpolatedDimension (0); 00196 pos.y = spline.GetInterpolatedDimension (1); 00197 pos.z = spline.GetInterpolatedDimension (2); 00198 } 00200 virtual void GetInterpolatedUp (csVector3& pos) 00201 { 00202 pos.x = spline.GetInterpolatedDimension (3); 00203 pos.y = spline.GetInterpolatedDimension (4); 00204 pos.z = spline.GetInterpolatedDimension (5); 00205 } 00207 virtual void GetInterpolatedForward (csVector3& pos) 00208 { 00209 pos.x = spline.GetInterpolatedDimension (6); 00210 pos.y = spline.GetInterpolatedDimension (7); 00211 pos.z = spline.GetInterpolatedDimension (8); 00212 } 00214 float const* GetDimensionValues (int dim) const 00215 { 00216 return spline.GetDimensionValues(dim); 00217 } 00219 float GetDimensionValue (int dim, int idx) const 00220 { 00221 return spline.GetDimensionValue(dim, idx); 00222 } 00227 void InsertPoint (int idx) 00228 { 00229 spline.InsertPoint(idx); 00230 } 00232 void RemovePoint (int idx) 00233 { 00234 spline.RemovePoint(idx); 00235 } 00236 }; 00237 00240 #endif // __CS_PATH_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1