Blender  V2.59
BLI_math_matrix.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BLI_math_matrix.h 36792 2011-05-20 10:09:03Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  
00023  * The Original Code is: some of this file.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  * */
00027 
00028 #ifndef BLI_MATH_MATRIX_H
00029 #define BLI_MATH_MATRIX_H
00030 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 /********************************* Init **************************************/
00040 
00041 #define MAT4_UNITY {{ 1.0, 0.0, 0.0, 0.0},\
00042                                         { 0.0, 1.0, 0.0, 0.0},\
00043                                         { 0.0, 0.0, 1.0, 0.0},\
00044                                         { 0.0, 0.0, 0.0, 1.0}}
00045 
00046 #define MAT3_UNITY {{ 1.0, 0.0, 0.0},\
00047                                         { 0.0, 1.0, 0.0},\
00048                                         { 0.0, 0.0, 1.0}}
00049 
00050 void zero_m3(float R[3][3]);
00051 void zero_m4(float R[4][4]);
00052 
00053 void unit_m3(float R[3][3]);
00054 void unit_m4(float R[4][4]);
00055 
00056 void copy_m3_m3(float R[3][3], float A[3][3]);
00057 void copy_m4_m4(float R[4][4], float A[4][4]);
00058 void copy_m3_m4(float R[3][3], float A[4][4]);
00059 void copy_m4_m3(float R[4][4], float A[3][3]);
00060 
00061 void swap_m3m3(float A[3][3], float B[3][3]);
00062 void swap_m4m4(float A[4][4], float B[4][4]);
00063 
00064 /******************************** Arithmetic *********************************/
00065 
00066 void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
00067 void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
00068 
00069 void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
00070 void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
00071 void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);
00072 void mul_m4_m4m3(float R[4][4], float A[4][4], float B[3][3]);
00073 void mul_m3_m3m4(float R[3][3], float A[3][3], float B[4][4]);
00074 
00075 void mul_serie_m3(float R[3][3],
00076         float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3],
00077         float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]);
00078 void mul_serie_m4(float R[4][4],
00079         float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4],
00080         float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]);
00081 
00082 void mul_m4_v3(float M[4][4], float r[3]);
00083 void mul_v3_m4v3(float r[3], float M[4][4], float v[3]);
00084 void mul_mat3_m4_v3(float M[4][4], float r[3]);
00085 void mul_m4_v4(float M[4][4], float r[4]);
00086 void mul_v4_m4v4(float r[4], float M[4][4], float v[4]);
00087 void mul_project_m4_v3(float M[4][4], float vec[3]);
00088 
00089 void mul_m3_v3(float M[3][3], float r[3]);
00090 void mul_v3_m3v3(float r[3], float M[3][3], float a[3]);
00091 void mul_transposed_m3_v3(float M[3][3], float r[3]);
00092 void mul_m3_v3_double(float M[3][3], double r[3]);
00093 
00094 void mul_m3_fl(float R[3][3], float f);
00095 void mul_m4_fl(float R[4][4], float f);
00096 void mul_mat3_m4_fl(float R[4][4], float f);
00097 
00098 int invert_m3(float R[3][3]);
00099 int invert_m3_m3(float R[3][3], float A[3][3]);
00100 int invert_m4(float R[4][4]);
00101 int invert_m4_m4(float R[4][4], float A[4][4]);
00102 
00103 /****************************** Linear Algebra *******************************/
00104 
00105 void transpose_m3(float R[3][3]);
00106 void transpose_m4(float R[4][4]);
00107 
00108 void normalize_m3(float R[3][3]);
00109 void normalize_m3_m3(float R[3][3], float A[3][3]);
00110 void normalize_m4(float R[4][4]);
00111 void normalize_m4_m4(float R[4][4], float A[4][4]);
00112 
00113 void orthogonalize_m3(float R[3][3], int axis);
00114 void orthogonalize_m4(float R[4][4], int axis);
00115 
00116 int is_orthogonal_m3(float mat[3][3]);
00117 int is_orthogonal_m4(float mat[4][4]);
00118 
00119 void adjoint_m3_m3(float R[3][3], float A[3][3]);
00120 void adjoint_m4_m4(float R[4][4], float A[4][4]);
00121 
00122 float determinant_m2(
00123         float a, float b,
00124         float c, float d);
00125 float determinant_m3(
00126         float a, float b, float c,
00127         float d, float e, float f,
00128         float g, float h, float i);
00129 float determinant_m4(float A[4][4]);
00130 
00131 void svd_m4(float U[4][4], float s[4], float V[4][4], float A[4][4]);
00132 void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon);
00133 
00134 /****************************** Transformations ******************************/
00135 
00136 void scale_m3_fl(float R[3][3], float scale);
00137 void scale_m4_fl(float R[4][4], float scale);
00138 
00139 float mat3_to_scale(float M[3][3]);
00140 float mat4_to_scale(float M[4][4]);
00141 
00142 void size_to_mat3(float R[3][3], const float size[3]);
00143 void size_to_mat4(float R[4][4], const float size[3]);
00144 
00145 void mat3_to_size(float r[3], float M[3][3]);
00146 void mat4_to_size(float r[3], float M[4][4]);
00147 
00148 void translate_m4(float mat[4][4], float tx, float ty, float tz);
00149 void rotate_m4(float mat[4][4], const char axis, const float angle);
00150 
00151 
00152 void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[][3]);
00153 void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]);
00154 
00155 void loc_eul_size_to_mat4(float R[4][4],
00156         const float loc[3], const float eul[3], const float size[3]);
00157 void loc_eulO_size_to_mat4(float R[4][4],
00158         const float loc[3], const float eul[3], const float size[3], const short order);
00159 void loc_quat_size_to_mat4(float R[4][4],
00160         const float loc[3], const float quat[4], const float size[3]);
00161 void loc_axisangle_size_to_mat4(float R[4][4],
00162         const float loc[3], const float axis[4], const float angle, const float size[3]);
00163 
00164 void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t);
00165 void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t);
00166 
00167 int is_negative_m3(float mat[3][3]);
00168 int is_negative_m4(float mat[4][4]);
00169 
00170 /*********************************** Other ***********************************/
00171 
00172 void print_m3(const char *str, float M[3][3]);
00173 void print_m4(const char *str, float M[3][4]);
00174 
00175 #ifdef __cplusplus
00176 }
00177 #endif
00178 
00179 #endif /* BLI_MATH_MATRIX_H */
00180