00001 /*------------------------------------------------------------------------------ 00002 00003 Octree Component, version 2.1 00004 Copyright (c) 2004-2007, Harrison Ainsworth / HXA7241. 00005 00006 http://www.hxa7241.org/ 00007 00008 ------------------------------------------------------------------------------*/ 00009 00010 /*------------------------------------------------------------------------------ 00011 00012 Copyright (c) 2004-2007, Harrison Ainsworth / HXA7241. 00013 00014 Redistribution and use in source and binary forms, with or without modification, 00015 are permitted provided that the following conditions are met: 00016 00017 * Redistributions of source code must retain the above copyright notice, this 00018 list of conditions and the following disclaimer. 00019 * Redistributions in binary form must reproduce the above copyright notice, this 00020 list of conditions and the following disclaimer in the documentation and/or 00021 other materials provided with the distribution. 00022 * The name of the author may not be used to endorse or promote products derived 00023 from this software without specific prior written permission. 00024 00025 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 00026 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00027 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00028 SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00030 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00031 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00032 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00033 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00034 OF SUCH DAMAGE. 00035 00036 ------------------------------------------------------------------------------*/ 00037 00038 00039 #ifndef Vector3r_h 00040 #define Vector3r_h 00041 00042 00043 #include "Primitives.h" 00044 00045 00046 00047 00048 namespace hxa7241_graphics 00049 { 00050 using namespace hxa7241; 00051 00052 00061 class Vector3r 00062 { 00064 public: 00065 Vector3r(); 00066 Vector3r( real x, 00067 real y, 00068 real z ); 00069 // explicit Vector3r( const real xyz[3] ); 00070 00071 ~Vector3r(); 00072 Vector3r( const Vector3r& ); 00073 Vector3r& operator=( const Vector3r& ); 00074 00075 00077 Vector3r& set( real x, 00078 real y, 00079 real z ); 00080 // Vector3r& set( const real xyz[3] ); 00081 // 00082 // Vector3r& setX( real ); 00083 // Vector3r& setY( real ); 00084 // Vector3r& setZ( real ); 00085 // real& operator[]( int ); 00086 00087 // Vector3r& negateEq (); 00088 // Vector3r& absEq (); 00089 // Vector3r& unitizeEq(); 00090 // Vector3r& crossEq ( const Vector3r& ); 00091 00092 Vector3r& operator+=( const Vector3r& ); 00093 Vector3r& operator-=( const Vector3r& ); 00094 Vector3r& operator*=( const Vector3r& ); 00095 Vector3r& operator/=( const Vector3r& ); 00096 Vector3r& operator*=( real ); 00097 Vector3r& operator/=( real ); 00098 00099 // Vector3r& clampMinEq( const Vector3r& ); 00100 // Vector3r& clampMaxEq( const Vector3r& ); 00101 // Vector3r& clampEq ( const Vector3r& min, 00102 // const Vector3r& max ); 00103 // Vector3r& clamp01Eq (); 00104 00105 00107 // void get( real& x, 00108 // real& y, 00109 // real& z ) const; 00110 // void get( real xyz[3] ) const; 00111 00112 real getX() const; 00113 real getY() const; 00114 real getZ() const; 00115 real operator[]( int ) const; 00116 00117 // real sum() const; 00118 // real average() const; 00119 // real smallest() const; 00120 // real largest() const; 00121 00122 real length() const; 00123 // real dot( const Vector3r& ) const; 00124 // real distance ( const Vector3r& ) const; 00125 // real distance2( const Vector3r& ) const; 00126 00127 // Vector3r operator-() const; 00128 // Vector3r abs() const; 00129 // Vector3r unitized() const; 00130 // Vector3r cross( const Vector3r& ) const; 00131 00132 Vector3r operator+( const Vector3r& ) const; 00133 Vector3r operator-( const Vector3r& ) const; 00134 Vector3r operator*( const Vector3r& ) const; 00135 Vector3r operator/( const Vector3r& ) const; 00136 Vector3r operator*( real ) const; 00137 Vector3r operator/( real ) const; 00138 00139 bool operator==( const Vector3r& ) const; 00140 bool operator!=( const Vector3r& ) const; 00141 bool isZero() const; 00142 00143 // // returning vectors of -1.0 or 0.0 or +1.0 00144 // Vector3r sign () const; 00145 // Vector3r compare( const Vector3r& ) const; 00146 // 00147 // // returning vectors of static_cast<real>(bool) 00148 // Vector3r equal ( const Vector3r& ) const; 00149 // Vector3r operator> ( const Vector3r& ) const; 00150 // Vector3r operator>=( const Vector3r& ) const; 00151 // Vector3r operator< ( const Vector3r& ) const; 00152 // Vector3r operator<=( const Vector3r& ) const; 00153 00154 // Vector3r clampedMin( const Vector3r& ) const; 00155 // Vector3r clampedMax( const Vector3r& ) const; 00156 // Vector3r clamped ( const Vector3r& min, 00157 // const Vector3r& max ) const; 00158 // Vector3r clamped01 () const; 00159 00160 friend Vector3r operator*( real, const Vector3r& ); 00161 friend Vector3r operator/( real, const Vector3r& ); 00162 00163 00165 static const Vector3r& ZERO(); 00166 static const Vector3r& HALF(); 00167 static const Vector3r& ONE(); 00168 // static const Vector3r& EPSILON(); 00169 // static const Vector3r& ALMOST_ONE(); 00170 // static const Vector3r& MIN(); 00171 // static const Vector3r& MAX(); 00172 // static const Vector3r& SMALL(); 00173 // static const Vector3r& LARGE(); 00174 // static const Vector3r& X(); 00175 // static const Vector3r& Y(); 00176 // static const Vector3r& Z(); 00177 00178 00180 private: 00181 real xyz_m[3]; 00182 }; 00183 00184 00185 00186 00187 00188 00189 00190 00191 // friends 00192 Vector3r operator*( real, const Vector3r& ); 00193 Vector3r operator/( real, const Vector3r& ); 00194 00195 00196 00197 00199 /* 00200 * These are certain. Leave others to the compiler. 00201 */ 00202 00203 00205 /*inline 00206 Vector3r::Vector3r 00207 ( 00208 const real xyz[3] 00209 ) 00210 { 00211 Vector3r::set( xyz ); 00212 }*/ 00213 00214 00215 inline 00216 Vector3r::~Vector3r() 00217 { 00218 } 00219 00220 00221 inline 00222 Vector3r::Vector3r 00223 ( 00224 const Vector3r& other 00225 ) 00226 { 00227 Vector3r::operator=( other ); 00228 } 00229 00230 00231 00232 00234 inline 00235 real Vector3r::getX() const 00236 { 00237 return xyz_m[0]; 00238 } 00239 00240 00241 inline 00242 real Vector3r::getY() const 00243 { 00244 return xyz_m[1]; 00245 } 00246 00247 00248 inline 00249 real Vector3r::getZ() const 00250 { 00251 return xyz_m[2]; 00252 } 00253 00254 00255 inline 00256 real Vector3r::operator[] 00257 ( 00258 const int i 00259 ) const 00260 { 00261 // careful ! 00262 return xyz_m[i]; 00263 } 00264 00265 00266 }//namespace 00267 00268 00269 00270 00271 #endif//Vector3r_h