![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * D o u b l e - V e c t o r O p e r a t i o n s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1994,2002 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: FXDVec.h,v 1.9 2002/03/12 07:11:30 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXDVEC_H 00025 #define FXDVEC_H 00026 00027 namespace FX { 00028 00029 00030 /// Double-precision vector class 00031 class FXAPI FXDVec { 00032 protected: 00033 FXdouble v[3]; 00034 public: 00035 00036 /// Default constructor 00037 FXDVec(){} 00038 00039 /// Copy constructor 00040 FXDVec(const FXDVec& w){v[0]=w.v[0];v[1]=w.v[1];v[2]=w.v[2];} 00041 00042 /// Initialize with components 00043 FXDVec(FXdouble x,FXdouble y,FXdouble z){v[0]=x;v[1]=y;v[2]=z;} 00044 00045 /// Initialize with color 00046 FXDVec(FXColor color); 00047 00048 /// Return a non-const reference to the ith element 00049 FXdouble& operator[](FXint i){return v[i];} 00050 00051 /// Return a const reference to the ith element 00052 const FXdouble& operator[](FXint i) const {return v[i];} 00053 00054 /// Assign color 00055 FXDVec& operator=(FXColor color); 00056 00057 /// Assignment 00058 FXDVec& operator=(const FXDVec& w){v[0]=w.v[0];v[1]=w.v[1];v[2]=w.v[2];return *this;} 00059 00060 /// Assigning operators 00061 FXDVec& operator+=(const FXDVec& a){v[0]+=a.v[0];v[1]+=a.v[1];v[2]+=a.v[2];return *this;} 00062 FXDVec& operator-=(const FXDVec& a){v[0]-=a.v[0];v[1]-=a.v[1];v[2]-=a.v[2];return *this;} 00063 FXDVec& operator*=(FXdouble n){v[0]*=n;v[1]*=n;v[2]*=n;return *this;} 00064 FXDVec& operator/=(FXdouble n){v[0]/=n;v[1]/=n;v[2]/=n;return *this;} 00065 00066 /// Conversions 00067 operator FXdouble*(){return v;} 00068 operator const FXdouble*() const {return v;} 00069 00070 /// Convert to color 00071 operator FXColor() const; 00072 00073 /// Other operators 00074 friend FXDVec operator-(const FXDVec& a){return FXDVec(-a.v[0],-a.v[1],-a.v[2]);} 00075 friend FXDVec operator!(const FXDVec& a){return a.v[0]==0.0 && a.v[1]==0.0 && a.v[2]==0.0;} 00076 friend FXDVec operator+(const FXDVec& a,const FXDVec& b){return FXDVec(a.v[0]+b.v[0],a.v[1]+b.v[1],a.v[2]+b.v[2]);} 00077 friend FXDVec operator-(const FXDVec& a,const FXDVec& b){return FXDVec(a.v[0]-b.v[0],a.v[1]-b.v[1],a.v[2]-b.v[2]);} 00078 friend FXDVec operator*(const FXDVec& a,FXdouble n){return FXDVec(a.v[0]*n,a.v[1]*n,a.v[2]*n);} 00079 friend FXDVec operator*(FXdouble n,const FXDVec& a){return FXDVec(n*a.v[0],n*a.v[1],n*a.v[2]);} 00080 friend FXDVec operator/(const FXDVec& a,FXdouble n){return FXDVec(a.v[0]/n,a.v[1]/n,a.v[2]/n);} 00081 friend FXDVec operator/(FXdouble n,const FXDVec& a){return FXDVec(n/a.v[0],n/a.v[1],n/a.v[2]);} 00082 00083 /// Dot and cross products 00084 friend FXdouble operator*(const FXDVec& a,const FXDVec& b){return a.v[0]*b.v[0]+a.v[1]*b.v[1]+a.v[2]*b.v[2];} 00085 friend FXDVec operator^(const FXDVec& a,const FXDVec& b){return FXDVec(a.v[1]*b.v[2]-a.v[2]*b.v[1], a.v[2]*b.v[0]-a.v[0]*b.v[2], a.v[0]*b.v[1]-a.v[1]*b.v[0]);} 00086 00087 /// Equality tests 00088 friend int operator==(const FXDVec& a,const FXDVec& b){return a.v[0]==b.v[0] && a.v[1]==b.v[1] && a.v[2]==b.v[2];} 00089 friend int operator==(const FXDVec& a,FXdouble n){return a.v[0]==n && a.v[1]==n && a.v[2]==n;} 00090 friend int operator==(FXdouble n,const FXDVec& a){return n==a.v[0] && n==a.v[1] && n==a.v[2];} 00091 friend int operator!=(const FXDVec& a,const FXDVec& b){return a.v[0]!=b.v[0] || a.v[1]!=b.v[1] || a.v[2]!=b.v[2];} 00092 friend int operator!=(const FXDVec& a,FXdouble n){return a.v[0]!=n || a.v[1]!=n || a.v[2]!=n;} 00093 friend int operator!=(FXdouble n,const FXDVec& a){return n!=a.v[0] || n!=a.v[1] || n!=a.v[2];} 00094 00095 /// Other functions 00096 friend FXAPI FXdouble len(const FXDVec& a); 00097 friend FXAPI FXDVec normalize(const FXDVec& a); 00098 friend FXAPI FXDVec lo(const FXDVec& a,const FXDVec& b); 00099 friend FXAPI FXDVec hi(const FXDVec& a,const FXDVec& b); 00100 00101 /// Save to a stream 00102 friend FXAPI FXStream& operator<<(FXStream& store,const FXDVec& v); 00103 00104 /// Load from a stream 00105 friend FXAPI FXStream& operator>>(FXStream& store,FXDVec& v); 00106 }; 00107 00108 } 00109 00110 #endif