Page principale | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe

C:/Projects/ngn/include/vector3d.h

00001 /***************************************************************************
00002  *            vector3d.h
00003  *
00004  *  Tue Sep  7 14:43:33 2004
00005  *  Copyright  2004  thierry schartz
00006  *  thierry.schartz@bluebottle.com
00007  ****************************************************************************/
00008 /*
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU Library General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 #ifndef VECTOR3D_H
00024 #define VECTOR3D_H
00025 
00026 #include <math.h>
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #pragma intrinsic( acos )
00030 #endif
00031 
00032 
00033 #include <iostream>
00034 #include "build.h"
00035 
00036 namespace ngn
00037 {
00038         namespace core
00039         {
00043                 class NGN_API Vector3df
00044         {
00045         public:
00047                 Vector3df()
00048                         {
00049                                 x = y = z = 0.0f;
00050                         }
00051                         // copy constructor
00052                         Vector3df( const Vector3df& other )
00053                         {
00054                                 x = other.x;
00055                                 y = other.y;
00056                                 z = other.z;
00057                         }
00058                         // overloaded constructor
00059                 Vector3df(float X, float Y, float Z ) 
00060                 { 
00061                         x = X; 
00062                                 y = Y; 
00063                                 z = Z;
00064                 }
00066                         Vector3df crossProduct( const Vector3df& v )
00067                         {
00068                                 Vector3df vNormal;      
00069                                 vNormal.x = ((y * v.z) - (z * v.y));
00070                                 vNormal.y = ((z * v.x) - (x * v.z));
00071                                 vNormal.z = ((x * v.y) - (y * v.x));
00072                                 return vNormal;
00073                         }
00075                         float magnitude()
00076                         {
00077                                 return (float)sqrt( (x*x) + (y*y) + (z*z) );
00078                         }
00080                         Vector3df normalize()
00081                         {
00082                                 float magnitude = this->magnitude();    
00083                                 Vector3df v = *this / magnitude;
00084                                 return v;               
00085                         }
00087                         Vector3df vector( const Vector3df& v )
00088                         {
00089                                 return *this - v;
00090                         }
00092                         float dotProduct( const Vector3df& V )
00093                         {
00094                                 return ( ( x*V.x) + (y*V.y) + (z*V.z) );
00095                         }
00097                         double angle( Vector3df& v )
00098                         {
00099                                 float dot = dotProduct( v );               
00100                                 float vectorsMagnitude = v.magnitude() * magnitude();
00101                                 double angle = acos( dot / vectorsMagnitude );
00102                                 return( angle );
00103                         }
00105                         void incX( float step = 1.0f )
00106                 {
00107                         x = x + step;
00108                         }
00110                         void incY( float step = 1.0f )
00111                 {
00112                         y = y + step;
00113                         }
00115                         void incZ( float step = 1.0f )
00116                 {
00117                         z = z + step;
00118                         }
00120                         void decX( float step = 1.0f )
00121                 {
00122                         x = x - step;
00123                         }
00125                         void decY( float step = 1.0f )
00126                 {
00127                         y = y - step;
00128                         }
00130                         void decZ( float step = 1.0f )
00131                 {
00132                         z = z - step;
00133                         }
00135                         Vector3df operator+(Vector3df vVector)
00136                 {
00137                         return Vector3df(vVector.x + x, vVector.y + y, vVector.z + z);
00138                 }
00139                         void operator++()
00140                 {
00141                          x = x + 1.0f;
00142                                  y = y + 1.0f;
00143                                  z = z + 1.0f;
00144                 }
00145                         Vector3df operator-( Vector3df vVector )
00146                 {
00147                         return Vector3df(x - vVector.x, y - vVector.y, z - vVector.z);
00148                 }
00149                         void operator--()
00150                 {
00151                                 x = x - 1.0f;
00152                                 y = y - 1.0f;
00153                                 z = z - 1.0f;
00154                 }
00155                 Vector3df operator*(float num)
00156                 {
00157                         
00158                         return Vector3df(x * num, y * num, z * num);
00159                 }
00160                 Vector3df operator/(float num)
00161                 {
00162                         
00163                         return Vector3df(x / num, y / num, z / num);
00164                 }
00165                         bool operator<( const Vector3df& v )
00166                         {
00167                                 if( x < v.x && y < v.y && z < v.z )
00168                                         return true;
00169                                 else 
00170                                         return false;
00171                         }
00172                         bool operator>( const Vector3df& v )
00173                         {
00174                                 if( x > v.x && y > v.y && z > v.z )
00175                                         return true;
00176                                 else 
00177                                         return false;
00178                         }
00179                         bool operator==( const Vector3df& v )
00180                         {
00181                                 if( x == v.x && y == v.y && z == v.z )
00182                                         return true;
00183                                 else 
00184                                         return false;
00185                         }
00186                         bool operator!=( const Vector3df& v )
00187                         {
00188                                 if( x != v.x || y != v.y || z != v.z )
00189                                         return true;
00190                                 else 
00191                                         return false;
00192                         }
00193                         friend std::ostream& operator << (std::ostream & flow, const Vector3df& v )
00194                         {
00195                         return (flow << "(" << v.x << ","<< v.y << "," << v.z << ")" ) ; 
00196                         }
00197                         
00198                 
00199         
00200                 float x, y, z;  
00201          
00202                                                 
00203         };
00204         
00205 
00206         // integer 3D vector
00207         struct Vector3di
00208         {
00209                         int x, y, z;
00210             };
00211         
00212                         
00213                         
00214         }//core
00215 }//ngn
00216 #endif

Généré le Fri Nov 19 14:20:29 2004 pour NGN par  doxygen 1.3.9.1