00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023 #ifndef H_SPK_VECTOR3D
00024 #define H_SPK_VECTOR3D
00025
00026 #include "Core/SPK_DEF.h"
00027
00028
00029 namespace SPK
00030 {
00041 class SPK_PREFIX Vector3D
00042 {
00043 public :
00044
00046
00048
00049 float x;
00050 float y;
00051 float z;
00053
00054
00056
00063 Vector3D(float x = 0.0f,float y = 0.0f,float z = 0.0f);
00064
00066
00068
00080 Vector3D& operator+=(const Vector3D& v);
00081
00093 Vector3D& operator-=(const Vector3D& v);
00094
00106 Vector3D& operator+=(float f);
00107
00119 Vector3D& operator-=(float f);
00120
00132 Vector3D& operator*=(float f);
00133
00145 Vector3D& operator/=(float f);
00146
00155 Vector3D operator-() const;
00156
00171 float& operator[](size_t index);
00172
00182 const float& operator[](size_t index) const;
00183
00185
00187
00194 void set(float x,float y,float z = 0.0f);
00195
00197
00199
00208 float getSqrNorm() const;
00209
00217 float getNorm() const;
00218
00230 bool normalize();
00231
00240 void revert();
00241
00252 void abs();
00253
00258 void crossProduct(const Vector3D& v);
00259 };
00260
00262
00264
00277 Vector3D operator+(const Vector3D& v0,const Vector3D& v1);
00278
00291 Vector3D operator-(const Vector3D& v0,const Vector3D& v1);
00292
00305 Vector3D operator+(const Vector3D& v,float f);
00306
00319 Vector3D operator+(float f,const Vector3D& v);
00320
00333 Vector3D operator-(const Vector3D& v,float f);
00334
00347 Vector3D operator-(float f,const Vector3D& v);
00348
00361 Vector3D operator*(const Vector3D& v,float f);
00362
00375 Vector3D operator*(float f,const Vector3D& v);
00376
00389 Vector3D operator/(const Vector3D& v,float f);
00390
00403 Vector3D operator/(float f,const Vector3D& v);
00404
00412 bool operator==(const Vector3D& v0,const Vector3D& v1);
00413
00421 bool operator!=(const Vector3D& v0,const Vector3D& v1);
00422
00433 std::ostream& operator<<(std::ostream& s,const Vector3D& v);
00434
00436
00438
00448 extern SPK_PREFIX float getSqrDist(const Vector3D& v0,const Vector3D& v1);
00449
00456 extern SPK_PREFIX float getDist(const Vector3D& v0,const Vector3D& v1);
00457
00464 float dotProduct(const Vector3D& v0,const Vector3D& v1);
00465
00472 extern SPK_PREFIX Vector3D crossProduct(const Vector3D& v0,const Vector3D& v1);
00473
00480 extern SPK_PREFIX void crossProduct(const Vector3D& v0,const Vector3D& v1,Vector3D& result);
00481
00482
00483 inline float Vector3D::getSqrNorm() const
00484 {
00485 return x * x + y * y + z * z;
00486 }
00487
00488 inline float Vector3D::getNorm() const
00489 {
00490 return std::sqrt(getSqrNorm());
00491 }
00492
00493 inline Vector3D Vector3D::operator-() const
00494 {
00495 return Vector3D(-x,-y,-z);
00496 }
00497
00498 inline float dotProduct(const Vector3D& v0,const Vector3D& v1)
00499 {
00500 return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z;
00501 }
00502
00503 inline Vector3D operator+(const Vector3D& v0,const Vector3D& v1)
00504 {
00505 return Vector3D(v0.x + v1.x,v0.y + v1.y,v0.z + v1.z);
00506 }
00507
00508 inline Vector3D operator-(const Vector3D& v0,const Vector3D& v1)
00509 {
00510 return Vector3D(v0.x - v1.x,v0.y - v1.y,v0.z - v1.z);
00511 }
00512
00513 inline Vector3D operator+(const Vector3D& v,float f)
00514 {
00515 return Vector3D(v.x + f,v.y + f,v.z + f);
00516 }
00517
00518 inline Vector3D operator+(float f,const Vector3D& v)
00519 {
00520 return Vector3D(v.x + f,v.y + f,v.z + f);
00521 }
00522
00523 inline Vector3D operator-(const Vector3D& v,float f)
00524 {
00525 return Vector3D(v.x - f,v.y - f,v.z - f);
00526 }
00527
00528 inline Vector3D operator-(float f,const Vector3D& v)
00529 {
00530 return Vector3D(v.x - f,v.y - f,v.z - f);
00531 }
00532
00533 inline Vector3D operator*(const Vector3D& v,float f)
00534 {
00535 return Vector3D(v.x * f,v.y * f,v.z * f);
00536 }
00537
00538 inline Vector3D operator*(float f,const Vector3D& v)
00539 {
00540 return Vector3D(v.x * f,v.y * f,v.z * f);
00541 }
00542
00543 inline Vector3D operator/(const Vector3D& v,float f)
00544 {
00545 float mul = 1.0f / f;
00546 return Vector3D(v.x * mul,v.y * mul,v.z * mul);
00547 }
00548
00549 inline Vector3D operator/(float f,const Vector3D& v)
00550 {
00551 return Vector3D(f / v.x,f / v.y,f / v.z);
00552 }
00553
00554 inline bool operator==(const Vector3D& v0,const Vector3D& v1)
00555 {
00556 return (v0.x == v1.x)&&(v0.y == v1.y)&&(v0.z == v1.z);
00557 }
00558
00559 inline bool operator!=(const Vector3D& v0,const Vector3D& v1)
00560 {
00561 return (v0.x != v1.x)||(v0.y != v1.y)||(v0.z != v1.z);
00562 }
00563
00564 inline std::ostream& operator<<(std::ostream& s,const Vector3D& v)
00565 {
00566 return s << '(' << v.x << ',' << v.y << ',' << v.z << ')';
00567 }
00568 }
00569
00570 #endif