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 "../IOData/datatypes.h"
00038 #include "mat2.h"
00039 #include "mat3.h"
00040
00041 template<typename Type>
00042 class CL_Mat2;
00043
00044 template<typename Type>
00045 class CL_Mat3;
00046
00047 template<typename Type>
00048 class CL_Mat4;
00049
00050 class CL_Angle;
00051
00056 template<typename Type>
00057 class CL_Mat4
00058 {
00061
00062 public:
00064 CL_Mat4()
00065 {
00066 for (int i=0; i<16; i++)
00067 matrix[i] = 0;
00068 }
00069
00071 CL_Mat4(const CL_Mat4<Type> ©)
00072 {
00073 for (int i=0; i<16; i++)
00074 matrix[i] = copy.matrix[i];
00075 }
00076
00078 CL_Mat4(const CL_Mat2<Type> ©);
00079
00081 CL_Mat4(const CL_Mat3<Type> ©);
00082
00084 CL_Mat4(const float *init_matrix)
00085 {
00086 for (int i=0; i<16; i++)
00087 matrix[i] = (Type) init_matrix[i];
00088 }
00089
00091 CL_Mat4(const double *init_matrix)
00092 {
00093 for (int i=0; i<16; i++)
00094 matrix[i] = (Type) init_matrix[i];
00095 }
00096
00098 CL_Mat4(const cl_int64 *init_matrix)
00099 {
00100 for (int i=0; i<16; i++)
00101 matrix[i] = (Type) init_matrix[i];
00102 }
00103
00105 CL_Mat4(const cl_int32 *init_matrix)
00106 {
00107 for (int i=0; i<16; i++)
00108 matrix[i] = (Type) init_matrix[i];
00109 }
00110
00112 CL_Mat4(const cl_int16 *init_matrix)
00113 {
00114 for (int i=0; i<16; i++)
00115 matrix[i] = (Type) init_matrix[i];
00116 }
00117
00119 CL_Mat4(const cl_int8 *init_matrix)
00120 {
00121 for (int i=0; i<16; i++)
00122 matrix[i] = (Type) init_matrix[i];
00123 }
00124
00128 static CL_Mat4<Type> null();
00129
00132 static CL_Mat4<Type> identity();
00133
00138 static CL_Mat4<Type> frustum(Type left, Type right, Type bottom, Type top, Type z_near, Type z_far);
00139
00144 static CL_Mat4<Type> perspective(
00145 Type field_of_view_y_degrees,
00146 Type aspect,
00147 Type z_near,
00148 Type z_far);
00149
00154 static CL_Mat4<Type> ortho(Type left, Type right, Type bottom, Type top, Type z_near, Type z_far);
00155
00160 static CL_Mat4<Type> ortho_2d(Type left, Type right, Type bottom, Type top);
00161
00171 static CL_Mat4<Type> rotate(const CL_Angle &angle, Type x, Type y, Type z, bool normalize = true);
00172
00179 static CL_Mat4<Type> scale(Type x, Type y, Type z);
00180
00188 static CL_Mat4<Type> translate(Type x, Type y, Type z);
00189
00203 static CL_Mat4<Type> look_at(
00204 Type eye_x, Type eye_y, Type eye_z,
00205 Type center_x, Type center_y, Type center_z,
00206 Type up_x, Type up_y, Type up_z);
00207
00215 static CL_Mat4<Type> multiply(const CL_Mat4<Type> &matrix_1, const CL_Mat4<Type> &matrix_2);
00216
00224 static CL_Mat4<Type> add(const CL_Mat4<Type> &matrix_1, const CL_Mat4<Type> &matrix_2);
00225
00233 static CL_Mat4<Type> subtract(const CL_Mat4<Type> &matrix_1, const CL_Mat4<Type> &matrix_2);
00234
00239 static CL_Mat4<Type> adjoint(const CL_Mat4<Type> &matrix);
00240
00246 static CL_Mat4<Type> inverse(const CL_Mat4<Type> &matrix);
00247
00251
00252 public:
00254 Type matrix[16];
00255
00257 Type get_origin_x() const { return matrix[12]; }
00258
00260 Type get_origin_y() const { return matrix[13]; }
00261
00263 Type get_origin_z() const { return matrix[14]; }
00264
00268
00269 public:
00277 CL_Mat4<Type> &multiply(const CL_Mat4<Type> &mult);
00278
00286 CL_Mat4<Type> &add(const CL_Mat4<Type> &add_matrix);
00287
00295 CL_Mat4<Type> &subtract(const CL_Mat4<Type> &sub_matrix);
00296
00306 CL_Mat4<Type> &scale_self(Type x, Type y, Type z);
00307
00318 CL_Mat4<Type> &translate_self(Type x, Type y, Type z);
00319
00323 double det() const;
00324
00328 CL_Mat4<Type> &adjoint();
00329
00334 CL_Mat4<Type> &inverse();
00335
00339
00340 public:
00342 operator Type const*() const { return matrix; }
00343
00345 operator Type *() { return matrix; }
00346
00348 Type &operator[](int i) { return matrix[i]; }
00349
00351 const Type &operator[](int i) const { return matrix[i]; }
00352
00354 Type &operator[](unsigned int i) { return matrix[i]; }
00355
00357 const Type &operator[](unsigned int i) const { return matrix[i]; }
00358
00360 CL_Mat4<Type> &operator =(const CL_Mat4<Type> ©) {memcpy(matrix, copy.matrix, sizeof(matrix)); return *this; }
00361
00363 CL_Mat4<Type> &operator =(const CL_Mat3<Type> ©);
00364
00366 CL_Mat4<Type> &operator =(const CL_Mat2<Type> ©);
00367
00369 CL_Mat4<Type> operator *(const CL_Mat4<Type> &mult) const { CL_Mat4<Type> result = mult; result.multiply(*this); return result; }
00370
00372 CL_Mat4<Type> operator +(const CL_Mat4<Type> &add_matrix) const { CL_Mat4<Type> result = add_matrix; result.add(*this); return result; }
00373
00375 CL_Mat4<Type> operator -(const CL_Mat4<Type> &sub_matrix) const { CL_Mat4<Type> result = sub_matrix; result.subtract(*this); return result; }
00376
00378 bool operator==(const CL_Mat4<Type> &other)
00379 {
00380 for (int i=0; i<16; i++)
00381 if (matrix[i] != other.matrix[i]) return false;
00382 return true;
00383 }
00384
00386 bool operator!=(const CL_Mat4<Type> &other) { return !((*this) == other); }
00387
00391
00392 private:
00394 };
00395
00396 typedef CL_Mat4<int> CL_Mat4i;
00397 typedef CL_Mat4<float> CL_Mat4f;
00398 typedef CL_Mat4<double> CL_Mat4d;
00399