vector.h

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

Generated on Thu Jan 7 08:26:23 2010 for NeL by  doxygen 1.6.1