D:/WorkDir/SugoiProjects/SugoiTools/include/SugoiTools/cl_vector3.h

00001 /* LICENSE_BEGIN
00002 SutoiTools library supply support for debugging, testing and 
00003 setting good bases for you application. It is part of the 
00004 SugoiEngine project.
00005 Copyright (C) 2006 Allusse Yannick (yannick dot allusse at laposte dot net)
00006 
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 LICENSE_END
00022 */
00023 
00024 /* \file SG_TLS_cl_vector3.h
00025  * \brief Basic template vector class of any type and size 3.
00026  * \author Yannick Allusse
00027 */
00028 
00029 
00030 #ifndef CL_VECTORS_TMPL_3_h
00031 #define CL_VECTORS_TMPL_3_h
00032 
00033 #include "SugoiTools\cl_vectors_template.h"
00034 
00035 #if SG_TLS_MEMORY_MANAGER
00036           #include "SugoiTools\debug_new.h"
00037 #endif 
00038 
00039 
00040 namespace SGE{
00041 
00042           
00043 template <typename TType> class CL_Vector3D;
00044 typedef CL_Vector3D<float>              CL_Vector3Df;
00045 typedef CL_Vector3D<int>                CL_Vector3Di;
00046 typedef CL_Vector3D<double>             CL_Vector3Dd;
00047 
00048 
00049 //=========================================================
00050 //=========================================================
00051 //        CL_Vector3D
00052 //=========================================================
00053 //=========================================================
00061 template <typename TType> class CL_Vector3D : public CLT_Vector<TType>
00062 {
00063 public :
00065           TType &x; 
00066           TType &y; 
00067           TType &z; 
00068 
00069 //Contructors / Destructors   =================================
00070           _SG_TLS_INLINE CL_Vector3D();
00071           _SG_TLS_INLINE CL_Vector3D(const CLT_Vector<TType> &_Vec);
00072           _SG_TLS_INLINE CL_Vector3D(const CL_Vector3D<TType> &       _Vec);
00073           _SG_TLS_INLINE CL_Vector3D(const TType *          _Val);
00074           _SG_TLS_INLINE CL_Vector3D(const TType            _Val);
00075           _SG_TLS_INLINE CL_Vector3D(const TType _x, const TType _y, const TType _z);
00076                                                   ~CL_Vector3D();
00077 //==========================================================
00078           _SG_TLS_INLINE void           Set(const TType _x, const TType _y, const TType _z);
00079           _SG_TLS_INLINE CL_Vector3D<TType> & operator= (const CL_Vector3D<TType> & _Vec2);
00080           _SG_TLS_INLINE CL_Vector3D<TType> & operator= (const TType  * _Val);
00081           _SG_TLS_INLINE CL_Vector3D<TType> & operator= (const TType  _Val);
00082 //===========================================================
00083 
00084           _SG_TLS_INLINE const TType                                  operator %	(const CL_Vector3D<TType> &) const;          
00085           _SG_TLS_INLINE const CL_Vector3D<TType> operator ^	(const CL_Vector3D<TType> &) const;           
00086           _SG_TLS_INLINE const CL_Vector3D<TType>&          operator ^= (const CL_Vector3D<TType> &);
00087 
00088           _SG_TLS_INLINE const TType                                  operator !	() const;// Distance from [0, 0, 0]
00089           _SG_TLS_INLINE const CL_Vector3D<TType> operator |          (const TType &) const;       // Sets distance from [0, 0, 0]
00090           _SG_TLS_INLINE                CL_Vector3D<TType>& operator |= (const TType &);
00091 //===========================================================
00092 
00093           _SG_TLS_INLINE const TType                                  Angle               (const CL_Vector3D<TType> &) const;                 // Calculates angle between this and another point
00094           _SG_TLS_INLINE const CL_Vector3D<TType> Reflection          (const CL_Vector3D<TType> &) const;             // Mirrors the direction of this point to [0, 0, 0] using the line from [0, 0, 0] to the other point
00095           _SG_TLS_INLINE const CL_Vector3D<TType> Rotate              (const TType &, const CL_Vector3D<TType> &) const; // Rotates and stuff
00096 
00097 #ifdef NX_FOUNDATION_NXVEC3
00098           _SG_TLS_INLINE  CL_Vector3D<TType> &operator=     (const NxVec3 &_NxVec);
00099 #endif
00100 };
00101 
00102 
00103 
00104 //============================================================================
00105 //CL_Vector3D START===========================================================
00106 //============================================================================
00111 template <typename TType> CL_Vector3D<TType>::CL_Vector3D() : CLT_Vector<TType>(3,0.), x( CLT_Vector<TType>::vec[0]), y( CLT_Vector<TType>::vec[1]),z( CLT_Vector<TType>::vec[2])
00112 {}
00113 
00118 template <typename TType> CL_Vector3D<TType>::CL_Vector3D(const CLT_Vector<TType> &_Vec) : CLT_Vector<TType>(_Vec), x( CLT_Vector<TType>::vec[0]), y( CLT_Vector<TType>::vec[1]),z( CLT_Vector<TType>::vec[2])
00119 {}
00120 
00121 
00127 template <typename TType> CL_Vector3D<TType>::CL_Vector3D(const CL_Vector3D<TType> &_Vec) : CLT_Vector<TType>(_Vec), x( CLT_Vector<TType>::vec[0]), y( CLT_Vector<TType>::vec[1]),z( CLT_Vector<TType>::vec[2])
00128 {}
00129 
00135 template <typename TType> CL_Vector3D<TType>::CL_Vector3D(const TType * _Val)  :CLT_Vector<TType>(3,_Val), x( CLT_Vector<TType>::vec[0]), y( CLT_Vector<TType>::vec[1]),z( CLT_Vector<TType>::vec[2])
00136 {}
00137 
00143 template <typename TType> CL_Vector3D<TType>::CL_Vector3D(const TType _Val):CLT_Vector<TType>(3,_Val), x( CLT_Vector<TType>::vec[0]), y( CLT_Vector<TType>::vec[1]),z( CLT_Vector<TType>::vec[2])
00144 {}
00145 
00150 template <typename TType> CL_Vector3D<TType>::CL_Vector3D(const TType _x, const TType _y, const TType _z):CLT_Vector<TType>(3,0.), x( CLT_Vector<TType>::vec[0]), y( CLT_Vector<TType>::vec[1]),z( CLT_Vector<TType>::vec[2])
00151 {
00152           Set(_x, _y, _z);
00153 }
00154 
00159 template <typename TType> CL_Vector3D<TType>::~CL_Vector3D(){}
00160 
00168 template <typename TType> void CL_Vector3D<TType>::Set(const TType _x, const TType _y, const TType _z)
00169 {
00170           x = _x;
00171           y = _y;
00172           z = _z;
00173 }
00174 
00175 template <typename TType> CL_Vector3D<TType> & CL_Vector3D<TType>::operator= (const CL_Vector3D<TType> & _Vec2)
00176 {
00177           VECTOR_OP_EQUAL(this, _Vec2.vec[i], , GetDim());
00178           return (*this);
00179 }
00180 template <typename TType> CL_Vector3D<TType> & CL_Vector3D<TType>::operator= (const TType * _Val)
00181 {
00182           SG_Assert(_Val, "Given Value is NULL");
00183           VECTOR_OP_EQUAL(this, _Val[i], , GetDim());
00184           return(*this);
00185 }
00186 template <typename TType> CL_Vector3D<TType> & CL_Vector3D<TType>::operator= (const TType _Val)
00187 {
00188           VECTOR_OP_EQUAL(this, _Val, , GetDim());
00189           return(*this);
00190 }
00191 
00192 
00193 #ifdef NX_FOUNDATION_NXVEC3
00194 
00195 template <typename TType> CL_Vector3D<TType> & CL_Vector3D<TType>::operator=	(const NxVec3 &_NxVec)
00196 {
00197           Set (_NxVec.x ,_NxVec.y, _NxVec.z);
00198           return *this;
00199 }
00200 #endif
00201 //==================================================================
00202 //Arithmetic operators START =====================================
00203 //==================================================================
00204 
00205 
00210 template <typename TType> const TType CL_Vector3D<TType>::operator % (const CL_Vector3D<TType> &v) const
00211  {
00212   return x*v.x + y*v.y + z*v.z;
00213  }
00214 
00219 template <typename TType> const CL_Vector3D<TType> CL_Vector3D<TType>::operator ^ (const CL_Vector3D<TType> &v) const
00220  {
00221   return CL_Vector3D(y*v.z-v.y*z, z*v.x-v.z*x, x*v.y-v.x*y);
00222  }
00223 
00228 template <typename TType> const CL_Vector3D<TType> & CL_Vector3D<TType>::operator ^= (const CL_Vector3D<TType> &v)
00229  {   return (*this = *this ^ v);  }
00230 
00235 template <typename TType> const TType CL_Vector3D<TType>::operator !() const
00236  {
00237   return sqrt(x*x + y*y + z*z);
00238  }
00239 
00240 
00243 template <typename TType> const CL_Vector3D<TType> CL_Vector3D<TType>::operator | (const TType &_v) const
00244 {
00245   return ((*this) * (_v / !(*this)));
00246   //return (*this * (l / !*this));
00247 }
00248 
00249 template <typename TType> CL_Vector3D<TType> & CL_Vector3D<TType>::operator |= (const TType &_v)
00250 {
00251   return (*this = *this | _v);
00252 }
00253 
00254 //Arithmetique operators END =====================================
00255 template <typename TType> const TType CL_Vector3D<TType>::Angle(const CL_Vector3D<TType> &_v) const
00256  {
00257   return acos(*this % _v) * 57.2957795130823208767981548141052;
00258  }
00259 
00260 template <typename TType> const CL_Vector3D<TType> CL_Vector3D<TType>::Reflection(const CL_Vector3D<TType> &_v) const
00261  {
00262   const CL_Vector3D n(*this | 1.0);
00263 //  return (n - v * 2.0 * (n % v)) * !this;
00264   return (n - _v * 2.0 * (n % _v)) * !*this;
00265  }
00266 
00267 
00268 
00269 template <typename TType> const CL_Vector3D<TType> CL_Vector3D<TType>::Rotate(const TType &a, const CL_Vector3D<TType> &v) const
00270  {
00271   const double s = sin(0.0174532925199432957692369076848861*a);
00272   const double c = cos(0.0174532925199432957692369076848861*a);
00273   //return CL_Vector3D(this * c + ((v * this) * (1.0 - c)) * v + (this ^ v) * s);
00274   return CL_Vector3D(*this * c + ((v * *this) * (1.0 - c)) * v + (*this ^ v) * s);
00275  }
00276 //============================================================================
00277 //CL_Vector3D END================================================================
00278 //============================================================================
00279 
00280 
00281 };//namespace SGE
00282 
00283 #if SG_TLS_MEMORY_MANAGER
00284           #include "SugoiTools\debug_new_off.h"//Must be the last....
00285 #endif 
00286 
00287 
00288 
00289 #endif//CL_VECTORS_TMPL_3_h

Generated on Mon Mar 19 23:15:10 2007 for SugoiTools by  doxygen 1.4.6-NO