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
00033
00034 #pragma once
00035
00036 #include "../api_core.h"
00037 #include "cl_math.h"
00038 #include "vec1.h"
00039 #include "vec2.h"
00040 #include "vec3.h"
00041
00042 template<typename Type>
00043 class CL_Vec1;
00044
00045 template<typename Type>
00046 class CL_Vec2;
00047
00048 template<typename Type>
00049 class CL_Vec3;
00050
00051 template<typename Type>
00052 class CL_Vec4;
00053
00054 template<typename Type>
00055 class CL_Mat2;
00056
00057 template<typename Type>
00058 class CL_Mat3;
00059
00060 template<typename Type>
00061 class CL_Mat4;
00062
00063 template<typename Type>
00064 class CL_Sizex;
00065
00066 template<typename Type>
00067 class CL_Pointx;
00068
00069 class CL_Angle;
00070
00077 template<typename Type>
00078 class CL_Vec4
00079 {
00080 public:
00081 typedef Type datatype;
00082
00083 union { Type x; Type s; Type r; };
00084 union { Type y; Type t; Type g; };
00085 union { Type z; Type u; Type b; };
00086 union { Type w; Type v; Type a; };
00087
00088 CL_Vec4() : x(0), y(0), z(0), w(0) { }
00089 CL_Vec4(const CL_Vec1<Type> ©) { x = copy.x; y = 0; z = 0; w = 0; }
00090 CL_Vec4(const CL_Vec2<Type> ©) { x = copy.x; y = copy.y; z = 0; w = 0; }
00091 CL_Vec4(const CL_Vec3<Type> ©) { x = copy.x; y = copy.y; z = copy.z; w = 0; }
00092 CL_Vec4(const Type &p1, const Type &p2 = 0, const Type &p3 = 0, const Type &p4 = 0) : x(p1), y(p2), z(p3), w(p4) { }
00093
00099 static CL_Vec4<Type> normalize3(const CL_Vec4<Type> &vector);
00100
00106 static CL_Vec4<Type> normalize4(const CL_Vec4<Type> &vector);
00107
00114 static Type dot3(const CL_Vec4<Type>& vector1, const CL_Vec4<Type>& vector2) { return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z; }
00115
00122 static Type dot4(const CL_Vec4<Type>& vector1, const CL_Vec4<Type>& vector2) { return vector1.x*vector2.x + vector1.y*vector2.y + vector1.z*vector2.z + vector1.w*vector2.w; }
00123
00129 static CL_Vec4<Type> cross3(const CL_Vec4<Type>& vector1, const CL_Vec4<Type>& vector2);
00130
00140 static CL_Vec4<Type> rotate3(const CL_Vec4<Type>& vector, const CL_Angle &angle, const CL_Vec4<Type>& axis);
00141
00148 static CL_Vec4<Type> round(const CL_Vec4<Type>& vector);
00149
00152
00153 public:
00159 Type length3() const;
00160
00166 Type length4() const;
00167
00172 CL_Vec4<Type> &normalize3();
00173
00178 CL_Vec4<Type> &normalize4();
00179
00186 Type dot3(const CL_Vec4<Type>& vector) const {return x*vector.x + y*vector.y + z*vector.z;}
00187
00194 Type dot4(const CL_Vec4<Type>& vector) const {return x*vector.x + y*vector.y + z*vector.z + w*vector.w;}
00195
00201 CL_Angle angle3(const CL_Vec4<Type>& vector) const;
00202
00208 Type distance3(const CL_Vec4<Type>& vector) const;
00209
00215 Type distance4(const CL_Vec4<Type>& vector) const;
00216
00223 CL_Vec4<Type> &cross3(const CL_Vec4<Type>& vector);
00224
00233 CL_Vec4<Type> &rotate3(const CL_Angle &angle, const CL_Vec4<Type>& axis);
00234
00240 CL_Vec4<Type> &round();
00241
00245
00246 public:
00247 const Type &operator[](unsigned int i) const { return ((Type *) this)[i]; }
00248 Type &operator[](unsigned int i) { return ((Type *) this)[i]; }
00249 operator Type *() { return (Type *) this; }
00250 operator Type * const() const { return (Type * const) this; }
00251
00253 void operator += (const CL_Vec4<Type>& vector) { x+= vector.x; y+= vector.y; z+= vector.z; w+= vector.w; }
00254
00256 void operator += ( Type value) { x+= value; y+= value; z+= value; w+= value; }
00257
00259 CL_Vec4<Type> operator + (const CL_Vec4<Type>& vector) const {return CL_Vec4<Type>(vector.x + x, vector.y + y, vector.z + z, vector.w + w);}
00260
00262 CL_Vec4<Type> operator + (Type value) const {return CL_Vec4<Type>(value + x, value + y, value + z, value + w);}
00263
00265 void operator -= (const CL_Vec4<Type>& vector) { x-= vector.x; y-= vector.y; z-= vector.z; w-= vector.w; }
00266
00268 void operator -= ( Type value) { x-= value; y-= value; z-= value; w-= value; }
00269
00271 CL_Vec4<Type> operator - (const CL_Vec4<Type>& vector) const {return CL_Vec4<Type>(x - vector.x, y - vector.y, z - vector.z, w - vector.w);}
00272
00274 CL_Vec4<Type> operator - (Type value) const {return CL_Vec4<Type>(x - value, y - value, z - value, w - value);}
00275
00277 void operator *= (const CL_Vec4<Type>& vector) { x*= vector.x; y*= vector.y; z*= vector.z; w*= vector.w; }
00278
00280 void operator *= ( Type value) { x*= value; y*= value; z*= value; w*= value; }
00281
00283 CL_Vec4<Type> operator * (const CL_Vec4<Type>& vector) const {return CL_Vec4<Type>(vector.x * x, vector.y * y, vector.z * z, vector.w * w);}
00284
00286 CL_Vec4<Type> operator * (Type value) const {return CL_Vec4<Type>(value * x, value * y, value * z, value * w);}
00287
00289 void operator /= (const CL_Vec4<Type>& vector) { x/= vector.x; y/= vector.y; z/= vector.z; w/= vector.w; }
00290
00292 void operator /= ( Type value) { x/= value; y/= value; z/= value; w/= value; }
00293
00295 CL_Vec4<Type> operator / (const CL_Vec4<Type>& vector) const {return CL_Vec4<Type>(x / vector.x, y / vector.y, z / vector.z, w / vector.w);}
00296
00298 CL_Vec4<Type> operator / (Type value) const {return CL_Vec4<Type>(x / value, y / value, z / value, w / value);}
00299
00301 CL_Vec4<Type> &operator = (const CL_Vec4<Type>& vector) { x = vector.x; y = vector.y; z = vector.z; w = vector.w; return *this; }
00302
00304 bool operator == (const CL_Vec4<Type>& vector) const {return ((x == vector.x) && (y == vector.y) && (z == vector.z) && (w == vector.w));}
00305
00307 bool operator != (const CL_Vec4<Type>& vector) const {return ((x != vector.x) || (y != vector.y) || (z != vector.z) || (w != vector.w));}
00309 };
00310
00311 template<typename Type>
00312 CL_Vec4<Type> operator * (const CL_Vec4<Type>& v, const CL_Mat4<Type>& matrix)
00313 {
00314 return CL_Vec4<Type>(
00315 matrix[0*4+0]*v.x + matrix[0*4+1]*v.y + matrix[0*4+2]*v.z + matrix[0*4+3]*v.w,
00316 matrix[1*4+0]*v.x + matrix[1*4+1]*v.y + matrix[1*4+2]*v.z + matrix[1*4+3]*v.w,
00317 matrix[2*4+0]*v.x + matrix[2*4+1]*v.y + matrix[2*4+2]*v.z + matrix[2*4+3]*v.w,
00318 matrix[3*4+0]*v.x + matrix[3*4+1]*v.y + matrix[3*4+2]*v.z + matrix[3*4+3]*v.w);
00319 }
00320
00321 template<typename Type>
00322 CL_Vec4<Type> operator * (const CL_Mat4<Type>& matrix, const CL_Vec4<Type>& v)
00323 {
00324 return CL_Vec4<Type>(
00325 matrix[0*4+0]*v.x + matrix[1*4+0]*v.y + matrix[2*4+0]*v.z + matrix[3*4+0]*v.w,
00326 matrix[0*4+1]*v.x + matrix[1*4+1]*v.y + matrix[2*4+1]*v.z + matrix[3*4+1]*v.w,
00327 matrix[0*4+2]*v.x + matrix[1*4+2]*v.y + matrix[2*4+2]*v.z + matrix[3*4+2]*v.w,
00328 matrix[0*4+3]*v.x + matrix[1*4+3]*v.y + matrix[2*4+3]*v.z + matrix[3*4+3]*v.w);
00329 }
00330
00331 typedef CL_Vec4<unsigned char> CL_Vec4ub;
00332 typedef CL_Vec4<char> CL_Vec4b;
00333 typedef CL_Vec4<unsigned short> CL_Vec4us;
00334 typedef CL_Vec4<short> CL_Vec4s;
00335 typedef CL_Vec4<unsigned int> CL_Vec4ui;
00336 typedef CL_Vec4<int> CL_Vec4i;
00337 typedef CL_Vec4<float> CL_Vec4f;
00338 typedef CL_Vec4<double> CL_Vec4d;
00339