00001
00002
00003
00004
00005
00010 #ifndef _FM_VECTOR3_H_
00011 #define _FM_VECTOR3_H_
00012
00021 class FCOLLADA_EXPORT FMVector3
00022 {
00023 public:
00024 float x;
00025 float y;
00026 float z;
00028 public:
00032 #ifndef _DEBUG
00033 FMVector3() {}
00034 #else
00035 FMVector3() { x = 123456789.0f; y = 123456789.0f; z = 123456789.0f; }
00036 #endif
00037
00045 FMVector3(float _x, float _y, float _z) { x = _x; y = _y; z = _z; }
00046
00057 FMVector3(const float* source, uint32 startIndex = 0);
00058
00064 inline float LengthSquared() const { return x * x + y * y + z * z; }
00065
00071 inline float Length() const { return sqrtf(x * x + y * y + z * z); }
00072
00076 inline void NormalizeIt() { float l = Length(); if (!IsEquivalent(l, 0.0f)) { x /= l; y /= l; z /= l; }}
00077
00083 inline FMVector3 Normalize() const { float l = Length(); return FMVector3(x / l, y / l, z / l); }
00084
00090 inline void Project(const FMVector3& unto) { (*this) = Projected(unto); }
00091
00098 inline FMVector3 Projected(const FMVector3& unto);
00099
00105 inline operator float*() { return &x; }
00106
00112 inline operator const float*() const { return &x; }
00113
00124 inline FMVector3& operator =(const float* v) { x = *v; y = *(v + 1); z = *(v + 2); return *this; }
00125
00134 inline void ComponentMinimum(const FMVector3& min) { if (x < min.x) x = min.x; if (y < min.y) y = min.y; if (z < min.z) z = min.z; }
00135
00144 inline void ComponentMaximum(const FMVector3& max) { if (x > max.x) x = max.x; if (y > max.y) y = max.y; if (z > max.z) z = max.z; }
00145
00157 inline void ComponentClamp(const FMVector3& min, const FMVector3& max) { ComponentMinimum(min); ComponentMaximum(max); }
00158
00159 public:
00160 static const FMVector3 XAxis;
00161 static const FMVector3 YAxis;
00162 static const FMVector3 ZAxis;
00163 static const FMVector3 Zero;
00164 static const FMVector3 Origin;
00165 };
00166
00174 inline FMVector3 operator +(const FMVector3& a, const FMVector3& b) { return FMVector3(a.x + b.x, a.y + b.y, a.z + b.z); }
00175
00183 inline FMVector3 operator -(const FMVector3& a, const FMVector3& b) { return FMVector3(a.x - b.x, a.y - b.y, a.z - b.z); }
00184
00193 inline FMVector3 operator +(const FMVector3& a) { return FMVector3(+a.x, +a.y, +a.z); }
00194
00203 inline FMVector3 operator -(const FMVector3& a) { return FMVector3(-a.x, -a.y, -a.z); }
00204
00212 inline float operator *(const FMVector3& a, const FMVector3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
00213
00221 inline FMVector3 operator *(const FMVector3& a, float b) { return FMVector3(a.x * b, a.y * b, a.z * b); }
00222
00230 inline FMVector3 operator *(float a, const FMVector3& b) { return FMVector3(a * b.x, a * b.y, a * b.z); }
00231
00239 inline FMVector3 operator ^(const FMVector3& a, const FMVector3& b) { return FMVector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); }
00240
00248 inline FMVector3& operator +=(FMVector3& b, const FMVector3& a) { b.x += a.x; b.y += a.y; b.z += a.z; return b; }
00249
00257 inline FMVector3& operator -=(FMVector3& b, const FMVector3& a) { b.x -= a.x; b.y -= a.y; b.z -= a.z; return b; }
00258
00266 inline FMVector3& operator *=(FMVector3& b, float a) { b.x *= a; b.y *= a; b.z *= a; return b; }
00267
00275 inline FMVector3& operator /=(FMVector3& b, float a) { b.x /= a; b.y /= a; b.z /= a; return b; }
00276
00283 inline bool IsEquivalent(const FMVector3& p, const FMVector3& q) { return IsEquivalent(p.x, q.x) && IsEquivalent(p.y, q.y) && IsEquivalent(p.z, q.z); }
00284
00291 inline bool operator == (const FMVector3& a, const FMVector3& b) { return IsEquivalent(a, b); }
00292
00293
00294 inline FMVector3 FMVector3::Projected(const FMVector3& unto) { return ((*this) * unto) / unto.LengthSquared() * unto; }
00295
00297 typedef vector<FMVector3> FMVector3List;
00298
00299 #endif // _FM_VECTOR3_H_