00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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
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;
00089 _SG_TLS_INLINE const CL_Vector3D<TType> operator | (const TType &) const;
00090 _SG_TLS_INLINE CL_Vector3D<TType>& operator |= (const TType &);
00091
00092
00093 _SG_TLS_INLINE const TType Angle (const CL_Vector3D<TType> &) const;
00094 _SG_TLS_INLINE const CL_Vector3D<TType> Reflection (const CL_Vector3D<TType> &) const;
00095 _SG_TLS_INLINE const CL_Vector3D<TType> Rotate (const TType &, const CL_Vector3D<TType> &) const;
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
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
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
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
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
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
00274 return CL_Vector3D(*this * c + ((v * *this) * (1.0 - c)) * v + (*this ^ v) * s);
00275 }
00276
00277
00278
00279
00280
00281 };
00282
00283 #if SG_TLS_MEMORY_MANAGER
00284 #include "SugoiTools\debug_new_off.h"
00285 #endif
00286
00287
00288
00289 #endif//CL_VECTORS_TMPL_3_h