00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 public:
00012
00013 union
00014 {
00015 SCALAR array[3];
00016 struct { SCALAR x, y, z, h; };
00017 struct { SCALAR r, g, b, a; };
00018 };
00019
00020 inline void set(SCALAR px, SCALAR py, SCALAR pz, SCALAR ph)
00021 {
00022 x = px;
00023 y = py;
00024 z = pz;
00025 h = ph;
00026 }
00027
00028 inline void setNull()
00029 {
00030 x = y = z = h = 0;
00031 }
00032
00033
00034
00035 SCALAR operator[](const long i)
00036 {
00037 assert(i >= 0 && i < 4);
00038 return(array[i]);
00039 }
00040
00041 SCALAR operator[](const unsigned long i)
00042 {
00043 assert(i < 4);
00044 return(array[i]);
00045 }
00046
00047 SCALAR operator[](const int i)
00048 {
00049 assert(i >= 0 && i < 4);
00050 return(array[i]);
00051 }
00052
00053 SCALAR operator[](const unsigned int i)
00054 {
00055 assert(i < 4);
00056 return(array[i]);
00057 }
00058
00059 SCALAR operator[](const short i)
00060 {
00061 assert(i >= 0 && i < 4);
00062 return(array[i]);
00063 }
00064
00065 SCALAR operator[](const unsigned short i)
00066 {
00067 assert(i < 4);
00068 return(array[i]);
00069 }
00070
00071 SCALAR operator[](const char i)
00072 {
00073 assert(i >= 0 && i < 4);
00074 return(array[i]);
00075 }
00076
00077 SCALAR operator[](const unsigned char i)
00078 {
00079 assert(i < 4);
00080 return(array[i]);
00081 }
00082
00083
00084
00085 inline bool operator==(VECTOR &pv)
00086 {
00087 return(x == pv.x && y == pv.y && z == pv.z && h == pv.h);
00088 }
00089
00090 bool nearlyEqual(VECTOR& pv, SCALAR e)
00091 {
00092 return(fabs(x-pv.x) < e && fabs(y-pv.y) < e && fabs(z-pv.z) < e && fabs(h-pv.h) < e);
00093 }
00094
00095
00096
00097 inline bool operator!=(VECTOR &pv)
00098 {
00099 return(x != pv.x || y != pv.y || z != pv.z || h != pv.h);
00100 }
00101
00102 #ifndef SCALARUNSIGNED
00103 inline VECTOR operator-()
00104 {
00105 return(VECTOR(-x, -y, -z, -h));
00106 }
00107 #endif
00108
00109 inline VECTOR& operator=(VECTOR &pv)
00110 {
00111 x = pv.x;
00112 y = pv.y;
00113 z = pv.z;
00114 h = pv.h;
00115 return(*this);
00116 }
00117
00118 inline VECTOR& operator=(float &ps)
00119 {
00120 x = y = z = h = (SCALAR)ps;
00121 return(*this);
00122 }
00123
00124 inline VECTOR& operator=(double &ps)
00125 {
00126 x = y = z = h = (SCALAR)ps;
00127 return(*this);
00128 }
00129
00130 inline VECTOR& operator=(long &ps)
00131 {
00132 x = y = z = h = (SCALAR)ps;
00133 return(*this);
00134 }
00135
00136 inline VECTOR& operator=(unsigned long &ps)
00137 {
00138 x = y = z = h = (SCALAR)ps;
00139 return(*this);
00140 }
00141
00142 inline VECTOR& operator=(int &ps)
00143 {
00144 x = y = z = h = (SCALAR)ps;
00145 return(*this);
00146 }
00147
00148 inline VECTOR& operator=(unsigned int &ps)
00149 {
00150 x = y = z = h = (SCALAR)ps;
00151 return(*this);
00152 }
00153
00154 inline VECTOR& operator=(short &ps)
00155 {
00156 x = y = z = h = (SCALAR)ps;
00157 return(*this);
00158 }
00159
00160 inline VECTOR& operator=(unsigned short &ps)
00161 {
00162 x = y = z = h = (SCALAR)ps;
00163 return(*this);
00164 }
00165
00166 inline VECTOR& operator=(char &ps)
00167 {
00168 x = y = z = h = (SCALAR)ps;
00169 return(*this);
00170 }
00171
00172 inline VECTOR& operator=(unsigned char &ps)
00173 {
00174 x = y = z = h = (SCALAR)ps;
00175 return(*this);
00176 }
00177
00178
00179
00180 inline operator SCALAR*()
00181 {
00182 return(array);
00183 }
00184
00185
00187
00188
00189 inline VECTOR operator+(VECTOR &pv)
00190 {
00191 return(VECTOR(x + pv.x, y + pv.y, z + pv.z, h + pv.h));
00192 }
00193
00194 inline VECTOR& operator+=(VECTOR &pv)
00195 {
00196 x += pv.x;
00197 y += pv.y;
00198 z += pv.z;
00199 h += pv.h;
00200 return(*this);
00201 }
00202
00203 inline VECTOR operator-(VECTOR &pv)
00204 {
00205 return(VECTOR(x - pv.x, y - pv.y, z - pv.z, h - pv.h));
00206 }
00207
00208 inline VECTOR& operator-=(VECTOR &pv)
00209 {
00210 x -= pv.x;
00211 y -= pv.y;
00212 z -= pv.z;
00213 h -= pv.h;
00214 return(*this);
00215 }
00216
00217
00218 inline VECTOR operator*(VECTOR &pv)
00219 {
00220 return(VECTOR(x * pv.x, y * pv.y, z * pv.z, h * pv.h));
00221 }
00222
00223 inline VECTOR& operator*=(VECTOR &pv)
00224 {
00225 x *= pv.x;
00226 y *= pv.y;
00227 z *= pv.z;
00228 h *= pv.h;
00229 }
00230
00231 inline VECTOR operator/(VECTOR &pv)
00232 {
00233 return(VECTOR(x / pv.x, y / pv.y, z / pv.z, h / pv.h));
00234 }
00235
00236 inline VECTOR& operator/=(VECTOR &pv)
00237 {
00238 x /= pv.x;
00239 y /= pv.y;
00240 z /= pv.z;
00241 h /= pv.h;
00242 }
00243
00244
00246
00247
00248 inline VECTOR operator+(SCALAR s)
00249 {
00250 return(VECTOR(x + s, y + s, z + s, h + s));
00251 }
00252
00253 inline VECTOR& operator+=(SCALAR s)
00254 {
00255 x += s;
00256 y += s;
00257 z += s;
00258 h += s;
00259 }
00260
00261 inline VECTOR operator-(SCALAR s)
00262 {
00263 return(VECTOR(x - s, y - s, z - s, h - s));
00264 }
00265
00266 inline VECTOR& operator-=(SCALAR s)
00267 {
00268 x -= s;
00269 y -= s;
00270 z -= s;
00271 h -= s;
00272 }
00273
00274 inline VECTOR operator*(SCALAR s)
00275 {
00276 return(VECTOR(x * s, y * s, z * s, h * s));
00277 }
00278
00279 inline VECTOR& operator*=(SCALAR s)
00280 {
00281 x *= s;
00282 y *= s;
00283 z *= s;
00284 h *= s;
00285 return(*this);
00286 }
00287
00288 friend inline VECTOR operator*(SCALAR& s, VECTOR& pv);
00289
00290 inline VECTOR operator/(SCALAR s)
00291 {
00292 return(VECTOR(x / s, y / s, z / s, h / s));
00293 }
00294
00295 inline VECTOR& operator/=(SCALAR s)
00296 {
00297 x /= s;
00298 y /= s;
00299 z /= s;
00300 h /= s;
00301 return(*this);
00302 }
00303
00304
00306
00307
00308 inline void Normalize()
00309 {
00310 SCALAR f = getLength();
00311 x /= f;
00312 y /= f;
00313 z /= f;
00314 h /= f;
00315 }
00316
00317 inline void unit()
00318 {
00319 Normalize();
00320 }
00321
00322
00323 inline SCALAR getLength()
00324 {
00325
00326 return((SCALAR)sqrt(x*x + y*y + z*z + h*h));
00327 }
00328
00329 inline SCALAR len()
00330 {
00331 return(getLength());
00332 }
00333
00334 inline SCALAR getQuadLength()
00335 {
00336
00337 return(x*x + y*y + z*z + h*h);
00338 }
00339
00340 inline SCALAR quadlen()
00341 {
00342 return(getQuadLength());
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 inline SCALAR getDotProduct(VECTOR &pv)
00359 {
00360 return(x*pv.x + y*pv.y + z*pv.z + h*pv.h);
00361 }
00362
00363 inline SCALAR dot(VECTOR &pv)
00364 {
00365 return(getDotProduct(pv));
00366 }
00367
00368
00369 inline SCALAR getAngle(VECTOR &pv)
00370 {
00371 return((SCALAR)(acos((double)getDotProduct(pv)) * (double)MUL_RAD_TO_DEG));
00372 }
00373
00374 inline SCALAR angle(VECTOR &pv)
00375 {
00376 return(getAngle(pv));
00377 }
00378
00379
00380 inline SCALAR getDistance(VECTOR &pv)
00381 {
00382 VECTOR t(pv.x - x, pv.y - y, pv.z - z, pv.h - h);
00383 return(t.getLength());
00384 }
00385
00386 inline SCALAR getQuadDistance(VECTOR &pv)
00387 {
00388 VECTOR t(pv.x - x, pv.y - y, pv.z - z, pv.h - h);
00389 return(t.getQuadLength());
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 inline void Translate(VECTOR &pv)
00443 {
00444 (*this) += pv;
00445 }
00446
00447 inline void Translate(SCALAR px, SCALAR py, SCALAR pz, SCALAR ph)
00448 {
00449 x += px;
00450 y += py;
00451 z += pz;
00452 h += ph;
00453 }
00454
00455
00456 inline void Scale(VECTOR &pv)
00457 {
00458 (*this) *= pv;
00459 }
00460
00461 inline void Scale(SCALAR sx, SCALAR sy, SCALAR sz, SCALAR sh)
00462 {
00463 x *= sx;
00464 y *= sy;
00465 z *= sz;
00466 h *= sh;
00467 }
00468 };
00469
00470
00471 VECTOR operator*(SCALAR& s, VECTOR& pv)
00472 {
00473 return(pv * s);
00474 }