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

vector4.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_VECTOR4_H__
00023 #define __AELIB_AEGEOM_VECTOR4_H__
00024 
00025 #define ONLY_INCLUDE_STD
00026 #include <aedefs.h>
00027 #undef ONLY_INCLUDE_STD
00028 
00033 class aeVector4 {
00034  public:
00039         inline aeVector4() {}
00040 
00049         inline aeVector4(float nx, float ny, float nz, float nw) :
00050                 x(nx), y(ny), z(nz), w(nw) {}
00051 
00057         inline aeVector4(const aeVector4 &v) :
00058                 x(v.x), y(v.y), z(v.z), w(v.w) {}
00059 
00060         inline ~aeVector4() {}
00061 
00063         float x;
00065         float y;
00067         float z;
00069         float w;
00070 
00079         inline friend aeVector4 operator+(const aeVector4 &v1, const aeVector4 &v2) {
00080                 return aeVector4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
00081         }
00082 
00091         inline friend aeVector4 operator-(const aeVector4 &v1, const aeVector4 &v2) {
00092                 return aeVector4(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w + v2.w);
00093         }
00094 
00103         inline friend float operator*(const aeVector4 &v1, const aeVector4 &v2) {
00104                 return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z) + (v1.w * v2.w);
00105         }
00106 
00115         inline friend aeVector4 operator%(const aeVector4 &v1, const aeVector4 &v2) {
00116                 return aeVector4((v1.x * v2.y - v1.y * v2.x) + (v1.x * v2.z - v1.z * v2.x) +
00117                                                  (v1.y * v2.z - v1.z * v2.y),
00118                                                  (v1.z * v2.y - v1.y * v2.z) + (v1.y * v2.w - v1.w * v2.y) +
00119                                                  (v1.z * v2.w - v1.w * v2.z),
00120                                                  (v1.x * v2.z - v1.z * v2.x) + (v1.w * v2.x - v1.x * v2.w) +
00121                                                  (v1.z * v2.w - v1.w * v2.z),
00122                                                  (v1.y * v1.x - v1.x * v2.y) + (v1.w * v2.x - v1.x * v2.w) +
00123                                                  (v1.w * v2.y - v1.y * v2.w));
00124         }
00125 
00134         inline friend aeVector4 operator*(const aeVector4 &v1, float s) {
00135                 return aeVector4(v1.x * s, v1.y * s, v1.z * s, v1.w * s);
00136         }
00137 
00146         inline friend aeVector4 operator*(float s, const aeVector4 &v1) {
00147                 return aeVector4(s * v1.x, s * v1.y, s * v1.z, s * v1.w);
00148         }
00149 
00158         inline friend aeVector4 operator*(const aeVector4 &v1, int s) {
00159                 return v1 * (float)s;
00160         }
00161 
00170         inline friend aeVector4 operator*(int s, const aeVector4 &v1) {
00171                 return (float)s * v1;
00172         }
00173 
00182         inline friend aeVector4 operator/(const aeVector4 &v1, float s) {
00183                 s = 1.0f / s;
00184                 return aeVector4(v1.x * s, v1.y * s, v1.z * s, v1.w * s);
00185         }
00186 
00195         inline friend aeVector4 operator/(const aeVector4 &v1, int s) {
00196                 return (v1 / (float)s);
00197         }
00198 
00207         inline friend bool operator==(const aeVector4 &v1, const aeVector4 &v2) {
00208                 return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
00209         }
00210 
00219         inline friend bool operator!=(const aeVector4 &v1, const aeVector4 &v2) {
00220                 return v1.x != v2.x || v1.y != v2.y || v1.z != v2.z || v1.w != v2.w;
00221         }
00222 
00230         inline float operator[](int n) const { return !n ? x : n & 1 ? y : n & 2 ? z : w; }
00231 
00239         inline float & operator[](int n) { return !n ? x : n & 1 ? y : n & 2 ? z : w; }
00240 
00248         inline aeVector4 & operator+=(const aeVector4 &v1) {
00249                 x += v1.x;
00250                 y += v1.y;
00251                 z += v1.z;
00252                 w += v1.w;
00253                 return *this;
00254         }
00255 
00263         inline aeVector4 & operator-=(const aeVector4 &v1) {
00264                 x -= v1.x;
00265                 y -= v1.y;
00266                 z -= v1.z;
00267                 w -= v1.w;
00268                 return *this;
00269         }
00270 
00278         inline aeVector4 & operator*=(float s) {
00279                 x *= s;
00280                 y *= s;
00281                 z *= s;
00282                 w *= s;
00283                 return *this;
00284         }
00285 
00293         inline aeVector4 & operator/=(float s) {
00294                 s = 1.0f / s;
00295                 x *= s;
00296                 y *= s;
00297                 z *= s;
00298                 w *= s;
00299                 return *this;
00300         }
00301 
00308         inline aeVector4 operator+() const { return *this; }
00309 
00316         inline aeVector4 operator-() const { return aeVector4(-x, -y, -z, -w); }
00317 
00326         inline void set(float nx, float ny, float nz, float nw) {
00327                 x = nx;
00328                 y = ny;
00329                 z = nz;
00330                 w = nw;
00331         }
00332 
00338         inline void set(const aeVector4 &v) {
00339                 x = v.x;
00340                 y = v.y;
00341                 z = v.z;
00342                 w = v.w;
00343         }
00344 
00351         void cross(const aeVector4 &v1, const aeVector4 &v2);
00352 
00359         float magnitude() const;
00360 
00368         inline aeVector4 unit() const { return this->normalize(); }
00369 
00376         aeVector4 normalize() const;
00377 };
00378 
00379 #endif // __AELIB_AEGEOM_VECTOR4_H__

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