Blender V2.61 - r43446

BLI_math_matrix.h

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