00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __AELIB_AEGEOM_VECTOR3_H__
00023 #define __AELIB_AEGEOM_VECTOR3_H__
00024
00025 #define ONLY_INCLUDE_STD
00026 #include <aedefs.h>
00027 #undef ONLY_INCLUDE_STD
00028
00033 class aeVector3 {
00034 public:
00039 inline aeVector3() {}
00040
00048 inline aeVector3(float nx, float ny, float nz) :
00049 x(nx), y(ny), z(nz) {}
00050
00056 inline aeVector3(const aeVector3 &v) :
00057 x(v.x), y(v.y), z(v.z) {}
00058
00059 inline ~aeVector3() {}
00060
00062 float x;
00064 float y;
00066 float z;
00067
00076 inline friend aeVector3 operator+(const aeVector3 &v1, const aeVector3 &v2) {
00077 return aeVector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
00078 }
00079
00088 inline friend aeVector3 operator-(const aeVector3 &v1, const aeVector3 &v2) {
00089 return aeVector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
00090 }
00091
00100 inline friend float operator*(const aeVector3 &v1, const aeVector3 &v2) {
00101 return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
00102 }
00103
00112 inline friend aeVector3 operator%(const aeVector3 &v1, const aeVector3 &v2) {
00113 return aeVector3((v1.y * v2.z) - (v1.z * v2.y),
00114 (v1.z * v2.x) - (v1.x * v2.z),
00115 (v1.x * v2.y) - (v1.y * v2.x));
00116 }
00117
00126 inline friend aeVector3 operator*(const aeVector3 &v1, float s) {
00127 return aeVector3(v1.x * s, v1.y * s, v1.z * s);
00128 }
00129
00138 inline friend aeVector3 operator*(float s, const aeVector3 &v1) {
00139 return aeVector3(v1.x * s, v1.y * s, v1.z * s);
00140 }
00141
00150 inline friend aeVector3 operator*(int s, const aeVector3 &v1) {
00151 return v1 * (float)s;
00152 }
00153
00162 inline friend aeVector3 operator/(const aeVector3 &v1, float s) {
00163 s = 1.0f / s;
00164 return aeVector3(v1.x * s, v1.y * s, v1.z * s);
00165 }
00166
00175 inline friend aeVector3 operator/(const aeVector3 &v1, int s) {
00176 return (v1 / (float)s);
00177 }
00178
00187 inline friend bool operator==(const aeVector3 &v1, const aeVector3 &v2) {
00188 return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
00189 }
00190
00199 inline friend bool operator!=(const aeVector3 &v1, const aeVector3 &v2) {
00200 return v1.x != v2.x || v1.y != v2.y || v1.z != v2.z;
00201 }
00202
00210 inline float operator[](int n) const { return !n ? x : n & 1 ? y : z; }
00211
00219 inline float & operator[](int n) { return !n ? x : n & 1 ? y : z; }
00220
00228 inline aeVector3 & operator+=(const aeVector3 &v1) {
00229 x += v1.x;
00230 y += v1.y;
00231 z += v1.z;
00232 return *this;
00233 }
00234
00242 inline aeVector3 & operator-=(const aeVector3 &v1) {
00243 x -= v1.x;
00244 y -= v1.y;
00245 z -= v1.z;
00246 return *this;
00247 }
00248
00256 inline aeVector3 & operator*=(float s) {
00257 x *= s;
00258 y *= s;
00259 z *= s;
00260 return *this;
00261 }
00262
00270 inline aeVector3 & operator/=(float s) {
00271 s = 1.0f / s;
00272 x *= s;
00273 y *= s;
00274 z *= s;
00275 return *this;
00276 }
00277
00284 inline aeVector3 operator+() const { return *this; }
00285
00292 inline aeVector3 operator-() const { return aeVector3(-x, -y, -z); }
00293
00301 inline void set(float nx, float ny, float nz) {
00302 x = nx;
00303 y = ny;
00304 z = nz;
00305 }
00306
00312 inline void set(const aeVector3 &v) {
00313 x = v.x;
00314 y = v.y;
00315 z = v.z;
00316 }
00317
00324 void cross(const aeVector3 &v1, const aeVector3 &v2);
00325
00332 float magnitude() const;
00333
00341 inline aeVector3 unit() const { return this->normalize(); }
00342
00349 aeVector3 normalize() const;
00350 };
00351
00352 #endif // __AELIB_AEGEOM_VECTOR3_H__