mat3.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Mark Page
00028 **    Harry Storbacka
00029 */
00030 
00033 
00034 #pragma once
00035 
00036 #include "../api_core.h"
00037 #include "mat2.h"
00038 #include "mat4.h"
00039 #include "../IOData/datatypes.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_Mat3
00058 {
00061 
00062 public:
00064         CL_Mat3() { }
00065 
00067         CL_Mat3(const CL_Mat3<Type> &copy)
00068         {
00069                 for (int i=0; i<9; i++)
00070                         matrix[i] = copy.matrix[i];
00071         }
00072 
00074         CL_Mat3(const CL_Mat2<Type> &copy);
00075 
00077         CL_Mat3(const CL_Mat4<Type> &copy);
00078 
00080         CL_Mat3(const float *init_matrix)
00081         {
00082                 for (int i=0; i<9; i++)
00083                         matrix[i] = (Type) init_matrix[i];
00084         }
00085 
00087         CL_Mat3(Type m00, Type m01, Type m02, Type m10, Type m11, Type m12, Type m20, Type m21, Type m22)
00088         {
00089                 matrix[0 * 3 + 0] = m00; matrix[0 * 3 + 1] = m01; matrix[0 * 3 + 2] = m02;
00090                 matrix[1 * 3 + 0] = m10; matrix[1 * 3 + 1] = m11; matrix[1 * 3 + 2] = m12;
00091                 matrix[2 * 3 + 0] = m20; matrix[2 * 3 + 1] = m21; matrix[2 * 3 + 2] = m22;
00092         }
00093 
00095         CL_Mat3(const double *init_matrix)
00096         {
00097                 for (int i=0; i<9; i++)
00098                         matrix[i] = (Type) init_matrix[i];
00099         }
00100 
00102         CL_Mat3(const cl_int64 *init_matrix)
00103         {
00104                 for (int i=0; i<9; i++)
00105                         matrix[i] = (Type) init_matrix[i];
00106         }
00107 
00109         CL_Mat3(const cl_int32 *init_matrix)
00110         {
00111                 for (int i=0; i<9; i++)
00112                         matrix[i] = (Type) init_matrix[i];
00113         }
00114 
00116         CL_Mat3(const cl_int16 *init_matrix)
00117         {
00118                 for (int i=0; i<9; i++)
00119                         matrix[i] = (Type) init_matrix[i];
00120         }
00121 
00123         CL_Mat3(const cl_int8 *init_matrix)
00124         {
00125                 for (int i=0; i<9; i++)
00126                         matrix[i] = (Type) init_matrix[i];
00127         }
00128 
00129         static CL_Mat3<Type> null();
00130 
00131         static CL_Mat3<Type> identity();
00132 
00142         static CL_Mat3<Type> rotate(const CL_Angle &angle, Type x, Type y, Type z, bool normalize = true);
00143 
00151         static CL_Mat3<Type> multiply(const CL_Mat3<Type> &matrix_1, const CL_Mat3<Type> &matrix_2);
00152 
00160         static CL_Mat3<Type> add(const CL_Mat3<Type> &matrix_1, const CL_Mat3<Type> &matrix_2);
00161 
00169         static CL_Mat3<Type> subtract(const CL_Mat3<Type> &matrix_1, const CL_Mat3<Type> &matrix_2);
00170 
00175         static CL_Mat3<Type> adjoint(const CL_Mat3<Type> &matrix);
00176 
00182         static CL_Mat3<Type> inverse(const CL_Mat3<Type> &matrix);
00183 
00187 
00188 public:
00189         Type matrix[9];
00190 
00194 
00195 public:
00203         CL_Mat3<Type> &multiply(const CL_Mat3<Type> &mult);
00204 
00212         CL_Mat3<Type> &add(const CL_Mat3<Type> &add_matrix);
00213 
00221         CL_Mat3<Type> &subtract(const CL_Mat3<Type> &sub_matrix);
00222 
00224         double det() const;
00225 
00229         CL_Mat3<Type> &adjoint();
00230 
00234         CL_Mat3<Type> &inverse();
00235 
00239 
00240 public:
00242         operator Type const*() const { return matrix; }
00243 
00245         operator Type *() { return matrix; }
00246 
00248         Type &operator[](int i) { return matrix[i]; }
00249 
00251         const Type &operator[](int i) const { return matrix[i]; }
00252 
00254         Type &operator[](unsigned int i) { return matrix[i]; }
00255 
00257         const Type &operator[](unsigned int i) const { return matrix[i]; }
00258 
00260         CL_Mat3<Type> &operator =(const CL_Mat3<Type> &copy) {memcpy(matrix, copy.matrix, sizeof(matrix)); return *this; }
00261 
00263         CL_Mat3<Type> &operator =(const CL_Mat4<Type> &copy);
00264 
00266         CL_Mat3<Type> &operator =(const CL_Mat2<Type> &copy);
00267 
00269         CL_Mat3<Type> operator *(const CL_Mat4<Type> &mult) const { CL_Mat3<Type> result = mult; result.multiply(*this); return result; }
00270 
00272         CL_Mat3<Type> operator +(const CL_Mat4<Type> &add_matrix) const { CL_Mat3<Type> result = add_matrix; result.add(*this); return result; }
00273 
00275         CL_Mat3<Type> operator -(const CL_Mat4<Type> &sub_matrix) const { CL_Mat3<Type> result = sub_matrix; result.subtract(*this); return result; }
00276 
00278         bool operator==(const CL_Mat3<Type> &other)
00279         {
00280                 for (int i=0; i<9; i++)
00281                         if (matrix[i] != other.matrix[i]) return false;
00282                 return true;
00283         }
00284 
00286         bool operator!=(const CL_Mat3<Type> &other) { return !((*this) == other); }
00287 
00291 
00292 private:
00294 };
00295 
00296 typedef CL_Mat3<int> CL_Mat3i;
00297 typedef CL_Mat3<float> CL_Mat3f;
00298 typedef CL_Mat3<double> CL_Mat3d;
00299 

Generated on Thu Dec 3 02:39:30 2009 for ClanLib by  doxygen 1.4.6