00001
00002
00003
00004
00005
00006 template<typename Real>
00007 v4<Real>& v4<Real>::set(const Real x, const Real y, const Real z, const Real w){
00008 v[0] = x;
00009 v[1] = y;
00010 v[2] = z;
00011 v[3] = w;
00012 return *this;
00013 }
00014
00015 template<typename Real>
00016 v4<Real>& v4<Real>::get(Real& x, Real& y, Real& z, Real& w){
00017 x = v[0];
00018 y = v[1];
00019 z = v[2];
00020 w = v[3];
00021 return *this;
00022 }
00023
00024 template<typename Real>
00025 Real v4<Real>::modulus(){
00026 return sqrt(modulus2());
00027 }
00028
00029 template<typename Real>
00030 Real v4<Real>::modulus2(){
00031 return v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3];
00032 }
00033
00034 template<typename Real>
00035 v4<Real>& v4<Real>::zero(void){
00036 VecOpSca(v, =, 0.f, 4);
00037 return *this;
00038 }
00039
00040 template<typename Real>
00041 v4<Real>& v4<Real>::identity(void){
00042 VecOpSca(v, =, 1.f, 4);
00043 return *this;
00044 }
00045
00046 template<typename Real>
00047 v4<Real>& v4<Real>::normalize(void){
00048 const Real mod = invsqrt(modulus2());
00049 VecOpSca(v, *=, mod, 4);
00050 return *this;
00051 }
00052
00053
00054
00055
00056
00057 template<typename Real>
00058 v4<Real>& v4<Real>::operator = (const v4<Real>& vec){
00059 x = vec.x;
00060 y = vec.y;
00061 z = vec.z;
00062 w = vec.w;
00063 return *this;
00064 }
00065
00066 template<typename Real>
00067 v4<Real>& v4<Real>::operator += (const v4<Real>& vec){
00068 x += vec.x;
00069 y += vec.y;
00070 z += vec.z;
00071 w += vec.w;
00072 return *this;
00073 }
00074
00075 template<typename Real>
00076 v4<Real>& v4<Real>::operator -= (const v4<Real>& vec){
00077 x -= vec.x;
00078 y -= vec.y;
00079 z -= vec.z;
00080 w -= vec.w;
00081 return *this;
00082 }
00083
00084 template<typename Real>
00085 v4<Real>& v4<Real>::operator *= (const Real f){
00086 x *= f;
00087 y *= f;
00088 z *= f;
00089 w *= f;
00090 return *this;
00091 }
00092
00093 template<typename Real>
00094 v4<Real>& v4<Real>::operator /= (const Real f){
00095 x /= f;
00096 y /= f;
00097 z /= f;
00098 w /= f;
00099 return *this;
00100 }
00101
00102 template<typename Real>
00103 bool v4<Real>::operator == (const v4<Real>& vec){
00104 return
00105 (v[0] == vec[0]) &&
00106 (v[1] == vec[1]) &&
00107 (v[2] == vec[2]) &&
00108 (v[3] == vec[3]);
00109 }
00110
00111 template<typename Real>
00112 bool v4<Real>::operator != (const v4<Real>& vec){
00113 return
00114 (v[0] != vec[0]) ||
00115 (v[1] != vec[1]) ||
00116 (v[2] != vec[2]) ||
00117 (v[3] != vec[3]);
00118 }
00119
00120 template<typename Real>
00121 Real& v4<Real>::operator [] (const unsigned char i){
00122 return v[i];
00123 }
00124
00125 template<typename Real>
00126 const Real v4<Real>::operator [] (const unsigned char i) const{
00127 return v[i];
00128 }
00129
00130 template<typename Real>
00131 Real& v4<Real>::operator () (const unsigned char i){
00132 return v[i];
00133 }
00134
00135 template<typename Real>
00136 const Real v4<Real>::operator () (const unsigned char i) const{
00137 return v[i];
00138 }
00139
00140
00141
00142
00143
00144 template<typename Real>
00145 v4<Real> Zero4(void){
00146 return v4<Real>(0.f,0.f,0.f);
00147 }
00148
00149 template<typename Real>
00150 v4<Real> Identity4(void){
00151 return v4<Real>(1.f,1.f,1.f);
00152 }
00153
00154 template<typename Real>
00155 v4<Real> cross(const v4<Real>& a, const v4<Real>& b, const v4<Real>& c){
00156 const Real Pxy = b.x*c.y - c.x*b.y;
00157 const Real Pxz = b.x*c.z - c.x*b.z;
00158 const Real Pxw = b.x*c.w - c.x*b.w;
00159 const Real Pyz = b.y*c.z - c.y*b.z;
00160 const Real Pyw = b.y*c.w - c.y*b.w;
00161 const Real Pzw = b.z*c.w - c.z*b.w;
00162 return v4<Real>(
00163 a.y*Pzw - a.z*Pyw + a.w*Pyz,
00164 a.z*Pxw - a.x*Pzw - a.w*Pxz,
00165 a.x*Pyw - a.y*Pxw + a.w*Pxy,
00166 a.y*Pxz - a.x*Pyz - a.z*Pxy);
00167 }
00168
00169 template<typename Real>
00170 v4<Real> normalize(const v4<Real>& v){
00171 return v * invsqrt(modulusSQ(v));
00172 }
00173
00174 template<typename Real>
00175 Real modulus(const v4<Real>& v){
00176 return sqrt(modulusSQ(v));
00177 }
00178
00179 template<typename Real>
00180 Real modulus2(const v4<Real>& v){
00181 return dot(v,v);
00182 }
00183
00184 template<typename Real>
00185 Real dot(const v4<Real>& a, const v4<Real>& b){
00186 return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
00187 }
00188
00189
00190
00191
00192
00193 template<typename Real>
00194 v4<Real> operator + (const v4<Real>& a, const v4<Real>& b){
00195 return v4<Real>(a[0]+b[0], a[1]+b[1], a[2]+b[2], a[3]+b[3]);
00196 }
00197
00198 template<typename Real>
00199 v4<Real> operator - (const v4<Real>& a, const v4<Real>& b){
00200 return v4<Real>(a[0]-b[0], a[1]-b[1], a[2]-b[2], a[3]-b[3]);
00201 }
00202
00203 template<typename Real>
00204 Real operator * (const v4<Real>& a, const v4<Real>& b){
00205 return dot(a,b);
00206 }
00207
00208 template<typename Real>
00209 v4<Real> operator * (Real f, const v4<Real>& v){
00210 return v4<Real>(v[0]*f, v[1]*f, v[2]*f, v[3]*f);
00211 }
00212
00213 template<typename Real>
00214 v4<Real> operator * (const v4<Real>& v, Real f){
00215 return f*v;
00216 }
00217
00218 template<typename Real>
00219 v4<Real> operator / (Real f, const v4<Real>& v){
00220 return v4<Real>(v[0]/f, v[1]/f, v[2]/f, v[3]/f);
00221 }
00222
00223 template<typename Real>
00224 v4<Real> operator / (const v4<Real>& v, Real f){
00225 return f/v;
00226 }
00227
00228 template<typename Real>
00229 v4<Real> operator - (const v4<Real>& v){
00230 return v4<Real>(-v[0], -v[1], -v[2], -v[3]);
00231 }