00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _VECTORN_H_
00018 #define _VECTORN_H_
00019 #include <assert.h>
00020 #include <iostream>
00021 #include <stuff/array_allocator.h>
00022
00025
00026 template <int Rows, int Cols, typename Base>
00027 struct _Matrix;
00028
00046 template <int N, typename Base=double>
00047 struct _Vector{
00048 typedef Base BaseType;
00049
00052 inline int size() const {return _allocator.size();}
00053
00056 inline const Base& operator[](int i) const {return _allocator[i];}
00057 inline bool operator==(const _Vector<N, Base>& other) const;
00058
00060 inline Base& operator[](int i) {return _allocator[i];}
00061
00063 _Vector(int s=N): _allocator(s){}
00064 static const int TemplateSize=N;
00065
00069 template <typename Base2>
00070 _Vector(const _Vector<N, Base2>& v);
00071
00076 _Vector(Base v0, Base v1){_allocator[0]=v0; _allocator[1]=v1;}
00077
00083 _Vector(Base v0, Base v1, Base v2) {_allocator[0]=v0; _allocator[1]=v1; _allocator[2]=v2;}
00084
00091 _Vector(Base v0, Base v1, Base v2, Base v3) {_allocator[0]=v0; _allocator[1]=v1; _allocator[2]=v2; _allocator[3]=v3;}
00092
00093
00094
00096 inline const Base& x() const {return _allocator[0];}
00097
00099 inline const Base& y() const {return _allocator[1];}
00100
00102 inline const Base& z() const {return _allocator[2];}
00103
00105 inline const Base& w() const {return _allocator[3];}
00106
00108 inline Base& x() {return _allocator[0];}
00109
00111 inline Base& y() {return _allocator[1];}
00112
00114 inline Base& z() {return _allocator[2];}
00115
00117 inline Base& w() {return _allocator[3];}
00118
00119
00121 inline const Base& roll() const {if (size() == 6) return _allocator[3]; return _allocator[0];}
00122
00124 inline const Base& pitch() const {if (size() == 6) return _allocator[4]; return _allocator[1];}
00125
00127 inline const Base& yaw() const {if (size() == 6) return _allocator[5]; return _allocator[2];}
00128
00130 inline Base& roll() {if (size() == 6) return _allocator[3]; return _allocator[0];}
00131
00133 inline Base& pitch() {if (size() == 6) return
00134 _allocator[4]; return _allocator[1];}
00135
00137 inline Base& yaw() {if (size() == 6) return _allocator[5]; return _allocator[2];}
00138
00139
00143 _Vector<N,Base> operator + (const _Vector<N,Base>& v) const;
00144
00148 _Vector<N,Base>& operator += (const _Vector<N,Base>& v);
00149
00153 _Vector<N,Base> operator - (const _Vector<N,Base>& v) const;
00154
00158 _Vector<N,Base>& operator -= (const _Vector<N,Base>& v);
00159
00162 Base operator *(const _Vector<N,Base>& v) const;
00163
00166 _Vector<N,Base>& operator *= (Base c);
00167
00170 _Vector<N,Base> operator * (Base c) const;
00171
00174 Base squaredNorm() const;
00175
00178 Base norm() const;
00179
00182 void normalize();
00183
00187 void fill(Base scalar);
00188
00191 _Vector<N,Base> normalized() const;
00192
00195 operator _Matrix<N, 1, Base>() const;
00196
00199 _ArrayAllocator<N,Base> _allocator;
00200
00201 };
00202
00205 template <int N, typename Base>
00206 std::ostream& operator << (std::ostream& os, const _Vector<N, Base>& v);
00207
00209 template <int N, typename Base>
00210 _Vector<N, Base> operator* (Base x, const _Vector<N, Base>& v);
00211
00212 typedef _Vector<2,int> Vector2i;
00213 typedef _Vector<2,float> Vector2f;
00214 typedef _Vector<3,float> Vector3f;
00215 typedef _Vector<6,float> Vector6f;
00216
00217
00218 typedef _Vector<2,double> Vector2;
00219 typedef _Vector<3,double> Vector3;
00220 typedef _Vector<6,double> Vector6;
00221
00222
00223 typedef _Vector<0,double> VectorX;
00224 typedef _Vector<0,float> VectorXf;
00225
00226 template <int N, typename Base>
00227 void st2dyn(_Vector<0,Base>& dest, const _Vector<N,Base> src){
00228 std2dyn(dest._allocator, src._allocator);
00229 }
00230
00231 template <int N, typename Base>
00232 void dyn2st(_Vector<0,Base>& dest, const _Vector<N,Base> src){
00233 dyn2st(dest._allocator, src._alloator);
00234 }
00235
00237
00238 #include "vector_n.hpp"
00239
00240 #endif