|
ctvector.h00001 /* 00002 Dynamics/Kinematics modeling and simulation library. 00003 Copyright (C) 1999 by Michael Alexander Ewert 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 00019 */ 00020 00021 #ifndef __CT_VECTOR__ 00022 #define __CT_VECTOR__ 00023 00024 // very annoying that I can't use templates. 00025 // Crystal Space people have some beef with templates. 00026 00027 class ctVector3; 00028 class ctMatrix3; 00029 00030 /* 00031 * written by: Michael Alexander Ewert 00032 */ 00033 00034 // seems like I could abstract a parent class of ctVector3 and ctVectorTranspose3 00035 00036 #include <stdarg.h> 00037 #include <math.h> 00038 #include "csphyzik/phyztype.h" 00039 #include "csphyzik/debug.h" 00040 00041 class ctVectorTranspose3 00042 { 00043 public: 00044 ctVectorTranspose3 () 00045 { elements[0] = elements[1] = elements[2] = 0.0; } 00046 00047 ctVectorTranspose3 ( real pfirst, real psecond, real pthird ) 00048 { 00049 elements[0] = pfirst; 00050 elements[1] = psecond; 00051 elements[2] = pthird; 00052 } 00053 00054 void set ( real pfirst, real psecond, real pthird ) 00055 { 00056 elements[0] = pfirst; 00057 elements[1] = psecond; 00058 elements[2] = pthird; 00059 } 00060 00061 void set ( int pnum, real *pele ) 00062 { 00063 int idx; 00064 for(idx = 0; idx < pnum; idx++ ) 00065 { 00066 elements[idx] = *pele; 00067 pele++; 00068 } 00069 } 00070 00071 void set ( real *pele ) 00072 { 00073 int idx; 00074 for (idx = 0; idx < 3; idx++) 00075 { 00076 elements[idx] = *pele; 00077 pele++; 00078 } 00079 } 00080 00081 real operator[] (const int index) const 00082 { return elements[index]; } 00083 00084 real& operator[] (const int index) 00085 { return elements[index]; } 00086 00087 ctVectorTranspose3 operator* ( const real pk ) 00088 { 00089 ctVectorTranspose3 scaled; 00090 int idx; 00091 for(idx = 0; idx < 3; idx++ ) 00092 scaled.elements[idx] = elements[idx] * pk; 00093 return scaled; 00094 } 00095 00096 void operator*= (const real p) 00097 { int idx; for (idx=0; idx<3; ++idx) elements[idx] *= p; } 00098 00099 void operator/= (const real p) 00100 { int idx; for (idx=0; idx<3; ++idx) elements[idx] /= p; } 00101 00102 real operator* ( const ctVector3 &bs ); 00103 00104 protected: 00105 real elements[ 3 ]; 00106 }; 00107 00108 00109 #include "csgeom/math3d_d.h" 00110 #define ctVector3 csDVector3 00111 /* 00112 class ctVector3 : public csDVector3 00113 { 00114 public: 00115 00116 ctVector3(){ 00117 x = y = z = 0.0; 00118 } 00119 00120 ctVector3( real pone, real ptwo, real pthree ){ 00121 x = pone; 00122 y = ptwo; 00123 z = pthree; 00124 } 00125 00126 ctVector3( const csDVector3 &csv ){ x = csv.x; y = csv.y; z = csv.z; } 00127 00128 void operator=( const csDVector3 &csv ){ x = csv.x; y = csv.y; z = csv.z; } 00129 00131 inline real & operator[](int n){return !n?x:n&1?y:z;} 00133 inline real operator[](int n) const {return !n?x:n&1?y:z;} 00134 00135 ctMatrix3 operator*( const ctVectorTranspose3 &pvt ); 00136 00137 void cross(const ctVector3 & px, const ctVector3 & py){ 00138 x = px.y*py.z - px.z*py.y; 00139 y = px.z*py.x - px.x*py.z; 00140 z = px.x*py.y - px.y*py.x; 00141 } 00142 00143 ctVector3 unit() const { return Unit(); } 00144 00145 void normalize(); 00146 real length(){ return Norm(); } 00147 }; 00148 */ 00149 00150 #endif // __CT_VECTOR__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |