# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

vector.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_VECTOR_H
00027 #define NL_VECTOR_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 
00031 #include <math.h>
00032 #include <string>
00033 
00034 #include "nel/misc/stream.h"
00035 
00036 namespace       NLMISC
00037 {
00038 
00039 class IStream;
00040 
00041 // ======================================================================================================
00048 class CVector
00049 {
00050 public:         // Attributes.
00051         float   x,y,z;
00052 
00053 public:         // const.
00055         static const    CVector         Null;
00057         static const    CVector         I;
00059         static const    CVector         J;
00061         static const    CVector         K;
00062 
00063 public:         // Methods.
00065 
00066 
00067         CVector() {}
00069         CVector(float   _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
00071         CVector(const CVector &v) : x(v.x), y(v.y), z(v.z) {}
00073 
00075 
00076         CVector &operator+=(const CVector &v);
00077         CVector &operator-=(const CVector &v);
00078         CVector &operator*=(float f);
00079         CVector &operator/=(float f);
00080         CVector operator+(const CVector &v) const;
00081         CVector operator-(const CVector &v) const;
00082         CVector operator*(float f) const;
00083         CVector operator/(float f) const;
00084         CVector operator-() const;
00086 
00088 
00089 
00090         float   operator*(const CVector &v) const;
00094         CVector operator^(const CVector &v) const;
00096         float   norm() const;
00098         float   sqrnorm() const;
00100         void    normalize();
00102         CVector normed() const;
00104 
00106 
00107         void    set(float _x, float _y, float _z);
00108         bool    operator==(const CVector &v) const;
00109         bool    operator!=(const CVector &v) const;
00110         bool    isNull() const;
00112         bool    operator<(const CVector &v) const;
00122         void    sphericToCartesian(float r, float theta,float phi);
00128         void    cartesianToSpheric(float &r, float &theta,float &phi) const;
00130         void    minof(const CVector &a, const CVector &b);
00132         void    maxof(const CVector &a, const CVector &b);
00134         void    serial(IStream &f);
00136 
00138         std::string     asString() const;
00139 
00140         // friends.
00141         friend  CVector operator*(float f, const CVector &v0);
00142 };
00143 
00144 
00145 }
00146 
00147 
00148 #include "nel/misc/vector_inline.h"
00149 
00150 
00151 #endif // NL_VECTOR_H
00152 
00153 /* End of vector.h */