[AE Engine logo] Public API Reference
Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

vector2.h

00001 /*
00002  *  AE Engine
00003  *
00004  *  Copyright (C) 2003 Riku "Rakkis" Nurminen
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef __AELIB_AEGEOM_VECTOR2_H__
00023 #define __AELIB_AEGEOM_VECTOR2_H__
00024 
00025 #define ONLY_INCLUDE_STD
00026 #include <aedefs.h>
00027 #undef ONLY_INCLUDE_STD
00028 
00033 class aeVector2 {
00034  public:
00039         inline aeVector2() {}
00040 
00047         inline aeVector2(float nx, float ny) :
00048                 x(nx), y(ny) {}
00049 
00055         inline aeVector2(const aeVector2 &v) :
00056                 x(v.x), y(v.y) {}
00057 
00058         inline ~aeVector2() {};
00059 
00061         float x;
00063         float y;
00064 
00073         inline friend aeVector2 operator+(const aeVector2 &v1, const aeVector2 &v2) {
00074                 return aeVector2(v1.x + v2.x, v1.y + v2.y);
00075         }
00076 
00085         inline friend aeVector2 operator-(const aeVector2 &v1, const aeVector2 &v2) {
00086                 return aeVector2(v1.x - v2.x, v1.y - v2.y);
00087         }
00088 
00097         inline friend float operator*(const aeVector2 &v1, const aeVector2 &v2) {
00098                 return (v1.x * v2.x) + (v1.y * v2.y);
00099         }
00100 
00109         inline friend aeVector2 operator*(const aeVector2 &v1, float s) {
00110                 return aeVector2(v1.x * s, v1.y * s);
00111         }
00112 
00121         inline friend aeVector2 operator*(float s, const aeVector2 &v1) {
00122                 return aeVector2(v1.x * s, v1.y * s);
00123         }
00124 
00133         inline friend aeVector2 operator*(int s, const aeVector2 &v1) {
00134                 return v1 * (float)s;
00135         }
00136 
00145         inline friend aeVector2 operator/(const aeVector2 &v1, float s) {
00146                 s = 1.0f / s;
00147                 return aeVector2(v1.x * s, v1.y * s);
00148         }
00149 
00158         inline friend aeVector2 operator/(const aeVector2 &v1, int s) {
00159                 return (v1 / (float)s);
00160         }
00161 
00170         inline friend bool operator==(const aeVector2 &v1, const aeVector2 &v2) {
00171                 return v1.x == v2.x && v1.y == v2.y;
00172         }
00173 
00182         inline friend bool operator!=(const aeVector2 &v1, const aeVector2 &v2) {
00183                 return v1.x != v2.x || v1.y != v2.y;
00184         }
00185 
00193         inline aeVector2 & operator+=(const aeVector2 &v1) {
00194                 x += v1.x;
00195                 y += v1.y;
00196                 return *this;
00197         }
00198 
00206         inline aeVector2 & operator-=(const aeVector2 &v1) {
00207                 x -= v1.x;
00208                 y -= v1.y;
00209                 return *this;
00210         }
00211 
00219         inline aeVector2 & operator*=(float s) {
00220                 x *= s;
00221                 y *= s;
00222                 return *this;
00223         }
00224 
00232         inline aeVector2 & operator/=(float s) {
00233                 s = 1.0f / s;
00234                 x *= s;
00235                 y *= s;
00236                 return *this;
00237         }
00238 
00245         inline aeVector2 operator+() const { return *this; }
00246 
00253         inline aeVector2 operator-() const { return aeVector(-x, -y); }
00254 
00261         inline void set(float nx, float ny) {
00262                 x = nx;
00263                 y = ny;
00264         }
00265 
00271         inline void set(const aeVector2 &v) {
00272                 x = v.x;
00273                 y = v.y;
00274         }
00275 
00282         aeVector2 cross(const aeVector2 &v1, const aeVector2 &v2);
00283 
00290         float magnitude() const;
00291 
00299         inline aeVector2 unit() const { return this->normalize(); }
00300 
00307         aeVector2 normalize() const;
00308 };
00309 
00310 #endif // __AELIB_AEGEOM_VECTOR2_H__

AE Engine Public API Reference
Generated on Wed Apr 9 09:43:40 2003 by Doxygen.