Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXVec4d.h

00001 /******************************************************************************** 00002 * * 00003 * D o u b l e - P r e c i s i o n 4 - E l e m e n t V e c t o r * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1994,2004 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXVec4d.h,v 1.5.2.1 2004/06/04 04:32:23 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXVEC4D_H 00025 #define FXVEC4D_H 00026 00027 00028 namespace FX { 00029 00030 00031 /// Double-precision 4-element vector 00032 class FXAPI FXVec4d { 00033 public: 00034 FXdouble x; 00035 FXdouble y; 00036 FXdouble z; 00037 FXdouble w; 00038 public: 00039 00040 /// Default constructor 00041 FXVec4d(){} 00042 00043 /// Copy constructor 00044 FXVec4d(const FXVec4d& v){x=v.x;y=v.y;z=v.z;w=v.w;} 00045 00046 /// Initialize with 3-vector 00047 FXVec4d(const FXVec3d& v){x=v.x;y=v.y;z=v.z;w=1.0;} 00048 00049 // Initialize from array of floats 00050 FXVec4d(const FXdouble v[]){x=v[0];y=v[1];z=v[2];w=v[3];} 00051 00052 /// Initialize with components 00053 FXVec4d(FXdouble xx,FXdouble yy,FXdouble zz,FXdouble ww=1.0){x=xx;y=yy;z=zz;w=ww;} 00054 00055 /// Initialize with color 00056 FXVec4d(FXColor color); 00057 00058 /// Return a non-const reference to the ith element 00059 FXdouble& operator[](FXint i){return (&x)[i];} 00060 00061 /// Return a const reference to the ith element 00062 const FXdouble& operator[](FXint i) const {return (&x)[i];} 00063 00064 /// Assign color 00065 FXVec4d& operator=(FXColor color); 00066 00067 /// Assignment 00068 FXVec4d& operator=(const FXVec3d& v){x=v.x;y=v.y;z=v.z;w=1.0;return *this;} 00069 FXVec4d& operator=(const FXVec4d& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;} 00070 00071 /// Assignment from array of floats 00072 FXVec4d& operator=(const FXdouble v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;} 00073 00074 /// Assigning operators 00075 FXVec4d& operator*=(FXdouble n){x*=n;y*=n;z*=n;w*=n;return *this;} 00076 FXVec4d& operator/=(FXdouble n){x/=n;y/=n;z/=n;w/=n;return *this;} 00077 FXVec4d& operator+=(const FXVec4d& v){x+=v.x;y+=v.y;z+=v.z;w+=v.w;return *this;} 00078 FXVec4d& operator-=(const FXVec4d& v){x-=v.x;y-=v.y;z-=v.z;w-=v.w;return *this;} 00079 00080 /// Conversion 00081 operator FXdouble*(){return &x;} 00082 operator const FXdouble*() const {return &x;} 00083 operator FXVec3d&(){return *reinterpret_cast<FXVec3d*>(this);} 00084 operator const FXVec3d&() const {return *reinterpret_cast<const FXVec3d*>(this);} 00085 00086 /// Convert to color 00087 operator FXColor() const; 00088 00089 /// Unary 00090 friend FXAPI FXVec4d operator+(const FXVec4d& v){return v;} 00091 friend FXAPI FXVec4d operator-(const FXVec4d& v){return FXVec4d(-v.x,-v.y,-v.z,-v.w);} 00092 00093 /// Adding 00094 friend FXAPI FXVec4d operator+(const FXVec4d& a,const FXVec4d& b){return FXVec4d(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);} 00095 00096 /// Substracting 00097 friend FXAPI FXVec4d operator-(const FXVec4d& a,const FXVec4d& b){return FXVec4d(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);} 00098 00099 /// Scaling 00100 friend FXAPI FXVec4d operator*(const FXVec4d& a,FXdouble n){return FXVec4d(a.x*n,a.y*n,a.z*n,a.w*n);} 00101 friend FXAPI FXVec4d operator*(FXdouble n,const FXVec4d& a){return FXVec4d(n*a.x,n*a.y,n*a.z,n*a.w);} 00102 friend FXAPI FXVec4d operator/(const FXVec4d& a,FXdouble n){return FXVec4d(a.x/n,a.y/n,a.z/n,a.w/n);} 00103 friend FXAPI FXVec4d operator/(FXdouble n,const FXVec4d& a){return FXVec4d(n/a.x,n/a.y,n/a.z,n/a.w);} 00104 00105 /// Dot product 00106 friend FXAPI FXdouble operator*(const FXVec4d& a,const FXVec4d& b){return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w;} 00107 00108 /// Test if zero 00109 friend FXAPI int operator!(const FXVec4d& a){return a.x==0.0 && a.y==0.0 && a.z==0.0 && a.w==0.0;} 00110 00111 /// Equality tests 00112 friend FXAPI int operator==(const FXVec4d& a,const FXVec4d& b){return a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w;} 00113 friend FXAPI int operator!=(const FXVec4d& a,const FXVec4d& b){return a.x!=b.x || a.y!=b.y || a.z!=b.z || a.w!=b.w;} 00114 00115 friend FXAPI int operator==(const FXVec4d& a,FXdouble n){return a.x==n && a.y==n && a.z==n && a.w==n;} 00116 friend FXAPI int operator!=(const FXVec4d& a,FXdouble n){return a.x!=n || a.y!=n || a.z!=n || a.w!=n;} 00117 00118 friend FXAPI int operator==(FXdouble n,const FXVec4d& a){return n==a.x && n==a.y && n==a.z && n==a.w;} 00119 friend FXAPI int operator!=(FXdouble n,const FXVec4d& a){return n!=a.x || n!=a.y || n!=a.z || n!=a.w;} 00120 00121 /// Inequality tests 00122 friend FXAPI int operator<(const FXVec4d& a,const FXVec4d& b){return a.x<b.x && a.y<b.y && a.z<b.z && a.w<b.w;} 00123 friend FXAPI int operator<=(const FXVec4d& a,const FXVec4d& b){return a.x<=b.x && a.y<=b.y && a.z<=b.z && a.w<=b.w;} 00124 friend FXAPI int operator>(const FXVec4d& a,const FXVec4d& b){return a.x>b.x && a.y>b.y && a.z>b.z && a.w>b.w;} 00125 friend FXAPI int operator>=(const FXVec4d& a,const FXVec4d& b){return a.x>=b.x && a.y>=b.y && a.z>=b.z && a.w>=b.w;} 00126 00127 friend FXAPI int operator<(const FXVec4d& a,FXdouble n){return a.x<n && a.y<n && a.z<n && a.w<n;} 00128 friend FXAPI int operator<=(const FXVec4d& a,FXdouble n){return a.x<=n && a.y<=n && a.z<=n && a.w<=n;} 00129 friend FXAPI int operator>(const FXVec4d& a,FXdouble n){return a.x>n && a.y>n && a.z>n && a.w>n;} 00130 friend FXAPI int operator>=(const FXVec4d& a,FXdouble n){return a.x>=n && a.y>=n && a.z>=n && a.w>=n;} 00131 00132 friend FXAPI int operator<(FXdouble n,const FXVec4d& a){return n<a.x && n<a.y && n<a.z && n<a.w;} 00133 friend FXAPI int operator<=(FXdouble n,const FXVec4d& a){return n<=a.x && n<=a.y && n<=a.z && n<=a.w;} 00134 friend FXAPI int operator>(FXdouble n,const FXVec4d& a){return n>a.x && n>a.y && n>a.z && n>a.w;} 00135 friend FXAPI int operator>=(FXdouble n,const FXVec4d& a){return n>=a.x && n>=a.y && n>=a.z && n>=a.w;} 00136 00137 /// Length and square of length 00138 friend FXAPI FXdouble len2(const FXVec4d& a){ return a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w; } 00139 friend FXAPI FXdouble len(const FXVec4d& a){ return sqrt(len2(a)); } 00140 00141 /// Normalize vector 00142 friend FXAPI FXVec4d normalize(const FXVec4d& a); 00143 00144 /// Lowest or highest components 00145 friend FXAPI FXVec4d lo(const FXVec4d& a,const FXVec4d& b){return FXVec4d(FXMIN(a.x,b.x),FXMIN(a.y,b.y),FXMIN(a.z,b.z),FXMIN(a.w,b.w));} 00146 friend FXAPI FXVec4d hi(const FXVec4d& a,const FXVec4d& b){return FXVec4d(FXMAX(a.x,b.x),FXMAX(a.y,b.y),FXMAX(a.z,b.z),FXMAX(a.w,b.w));} 00147 00148 /// Save to a stream 00149 friend FXAPI FXStream& operator<<(FXStream& store,const FXVec4d& v); 00150 00151 /// Load from a stream 00152 friend FXAPI FXStream& operator>>(FXStream& store,FXVec4d& v); 00153 }; 00154 00155 } 00156 00157 #endif

Copyright © 1997-2004 Jeroen van der Zijp