- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# FMath/FMVector2.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005-2007 Feeling Software Inc.
    00003     Portions of the code are:
    00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
    00005
    00006     MIT License: http://www.opensource.org/licenses/mit-license.php
    00007 */
    00008
    00015 #ifndef _FM_VECTOR2_H_
    00016 #define _FM_VECTOR2_H_
    00017
    00024 class FCOLLADA_EXPORT FMVector2
    00025 {
    00026 public:
    00027     union
    00028     {
    00029         float u;
    00030         float x;
    00031     };
    00032     union
    00033     {
    00034         float v;
    00035         float y;
    00036     };
    00037
    00038 public:
    00040     #ifndef _DEBUG
    00041     FMVector2() {}
    00042     #else
    00043     FMVector2() { u = 123456789.0f; v = 123456789.0f; }
    00044     #endif
    00045
    00049     FMVector2(float _u, float _v) { u = _u; v = _v; }
    00050
    00053     inline float LengthSquared() const { return x * x + y * y; }
    00054
    00057     inline float Length() const { return sqrtf(x * x + y * y); }
    00058
    00060     inline void NormalizeIt() { float l = Length(); if (l > 0.0f) { x /= l; y /= l; } else { x = 0; y = 1; }}
    00061
    00064     inline FMVector2 Normalize() const { float l = Length(); return (l > 0.0f) ? FMVector2(x / l, y / l) : FMVector2::XAxis; }
    00065
    00068     inline operator float*() { return &u; }
    00069
    00075     inline FMVector2& operator +=(const FMVector2& a) { u += a.u; v += a.v; return *this; }
    00076
    00082     inline FMVector2& operator *=(float a) { u *= a; v *= a; return *this; }
    00083
    00090     inline FMVector2& operator =(const float* f) { u = *f; v = *(f + 1); return *this; }
    00091
    00092 public:
    00093     static const FMVector2 Zero;
    00094     static const FMVector2 Origin;
    00095     static const FMVector2 XAxis;
    00096     static const FMVector2 YAxis;
    00097 };
    00098
    00103 inline FMVector2 operator + (const FMVector2& a, const FMVector2& b) { return FMVector2(a.u + b.u, a.v + b.v); }
    00104
    00109 inline FMVector2 operator -(const FMVector2& a, const FMVector2& b) { return FMVector2(a.u - b.u, a.v - b.v); }
    00110
    00116 inline float operator *(const FMVector2& a, const FMVector2& b) { return a.u * b.u + a.v * b.v; }
    00117
    00122 inline FMVector2 operator *(const FMVector2& a, float b) { return FMVector2(a.u * b, a.v * b); }
    00123
    00128 inline FMVector2 operator *(float a, const FMVector2& b) { return FMVector2(a * b.u, a * b.v); }
    00129
    00134 inline FMVector2 operator /(const FMVector2& a, float b) { return FMVector2(a.x / b, a.y / b); }
    00135
    00140 inline bool IsEquivalent(const FMVector2& a, const FMVector2& b) { return IsEquivalent(a.x, b.x) && IsEquivalent(a.y, b.y); }
    00141 inline bool operator==(const FMVector2& a, const FMVector2& b) { return IsEquivalent(a.x, b.x) && IsEquivalent(a.y, b.y); }
    00144 typedef fm::vector<FMVector2> FMVector2List;
    00145
    00146 #endif // _FM_VECTOR2_H_