# 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  

uv.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_UV_H
00027 #define NL_UV_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/stream.h"
00031 
00032 
00033 namespace NLMISC 
00034 {
00035 
00036 
00037 // ***************************************************************************
00042 /* *** IMPORTANT ********************
00043  * *** IF YOU MODIFY THE STRUCTURE OF THIS CLASS, PLEASE INCREMENT IDriver::InterfaceVersion TO INVALIDATE OLD DRIVER DLL
00044  * **********************************
00045  */
00046 class   CUV
00047 {
00048 public:
00049         float   U,V;
00050 
00051 public:
00052         CUV() {}
00053         CUV(float u, float v) : U(u), V(v) {}
00054         // modify uv's
00055         void set(float u, float v) { U = u; V = v; }
00056         // bin operators.
00057         CUV     operator+(const CUV &v) const
00058                 { return CUV(U+v.U, V+v.V);}
00059         // binary -
00060         CUV     operator-(const CUV &v) const
00061                 { return CUV(U-v.U, V-v.V);}
00062         // unary -
00063         CUV operator-() const 
00064                 { return CUV(-U, -V); } 
00065         // = operators.
00066         CUV     &operator*=(float f)
00067                 { U*=f;V*=f; return *this;}
00068         CUV     &operator+=(const CUV &v)
00069                 { U+=v.U;V+=v.V; return *this;}
00070         CUV     &operator-=(const CUV &v)
00071                 { U-=v.U;V-=v.V; return *this;}
00073         bool    operator<(const CUV &o) const
00074         {
00075                 if(U!=o.U)
00076                         return U<o.U;
00077                 return V<o.V;
00078         }
00079         bool    operator==(const CUV &c) const {return (U==c.U) && (V==c.V);}
00080         bool    operator!=(const CUV &c) const {return !(*this==c);}
00081 
00082         void    serial(NLMISC::IStream &f)      {f.serial(U,V);}
00083 };
00084 
00085 
00086 inline CUV operator * (float f, const CUV &uv)
00087 {
00088         return CUV(uv.U * f, uv.V * f);
00089 }
00090 
00091 
00092 inline CUV operator * (const CUV &uv, float f)
00093 {
00094         return f * uv;
00095 }
00096 
00097 
00098 
00099 // ***************************************************************************
00106 class   CUVW
00107 {
00108 public:
00109         float   U,V,W;
00110 
00111 public:
00112         CUVW() {}
00113         CUVW(float u, float v, float w) : U(u), V(v), W(w) {}
00114         // bin operators.
00115         CUVW    operator+(const CUVW &v) const
00116                 { return CUVW(U+v.U, V+v.V, W+v.W);}
00117         CUVW    operator-(const CUVW &v) const
00118                 { return CUVW(U-v.U, V-v.V, W-v.W);}
00119         CUVW    operator*(float f) const
00120                 { return CUVW(U*f, V*f, W*f);}
00121         // = operators.
00122         CUVW    &operator*=(float f)
00123                 { U*=f;V*=f; W*=f; return *this;}
00124         CUVW    &operator+=(const CUVW &v)
00125                 { U+=v.U;V+=v.V; W+=v.W; return *this;}
00126         CUVW    &operator-=(const CUVW &v)
00127                 { U-=v.U;V-=v.V; W-=v.W; return *this;}
00129         bool    operator<(const CUVW &o) const
00130         {
00131                 if(U!=o.U)
00132                         return U<o.U;
00133                 if(V!=o.V)
00134                         return V<o.V;
00135                 return W<o.W;
00136         }
00137         bool    operator==(const CUVW &c) const {return (U==c.U) && (V==c.V) && (W==c.W);}
00138         bool    operator!=(const CUVW &c) const {return !(*this==c);}
00139 
00140         void    serial(NLMISC::IStream &f)      {f.serial(U,V,W);}
00141 
00142         // Convert to a standard UV. The W coordinate is lost of course..
00143         operator CUV() const { return CUV(U, V); }
00144 };
00145 
00146 
00147 } // NLMISC
00148 
00149 
00150 #endif // NL_UV_H
00151 
00152 /* End of uv.h */