4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: some of this file.
25 * ***** END GPL LICENSE BLOCK *****
28 #ifndef BLI_MATH_MATRIX_H
29 #define BLI_MATH_MATRIX_H
31 /** \file BLI_math_matrix.h
39 /********************************* Init **************************************/
41 #define MAT4_UNITY {{ 1.0, 0.0, 0.0, 0.0},\
42 { 0.0, 1.0, 0.0, 0.0},\
43 { 0.0, 0.0, 1.0, 0.0},\
44 { 0.0, 0.0, 0.0, 1.0}}
46 #define MAT3_UNITY {{ 1.0, 0.0, 0.0},\
50 void zero_m3(float R[3][3]);
51 void zero_m4(float R[4][4]);
53 void unit_m3(float R[3][3]);
54 void unit_m4(float R[4][4]);
56 void copy_m3_m3(float R[3][3], float A[3][3]);
57 void copy_m4_m4(float R[4][4], float A[4][4]);
58 void copy_m3_m4(float R[3][3], float A[4][4]);
59 void copy_m4_m3(float R[4][4], float A[3][3]);
61 void swap_m3m3(float A[3][3], float B[3][3]);
62 void swap_m4m4(float A[4][4], float B[4][4]);
64 /******************************** Arithmetic *********************************/
66 void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
67 void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
69 void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
70 void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
71 void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);
72 void mul_m4_m4m3(float R[4][4], float A[4][4], float B[3][3]);
73 void mul_m3_m3m4(float R[3][3], float A[3][3], float B[4][4]);
75 void mul_serie_m3(float R[3][3],
76 float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3],
77 float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]);
78 void mul_serie_m4(float R[4][4],
79 float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4],
80 float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]);
82 void mul_m4_v3(float M[4][4], float r[3]);
83 void mul_v3_m4v3(float r[3], float M[4][4], float v[3]);
84 void mul_mat3_m4_v3(float M[4][4], float r[3]);
85 void mul_m4_v4(float M[4][4], float r[4]);
86 void mul_v4_m4v4(float r[4], float M[4][4], float v[4]);
87 void mul_project_m4_v4(float M[4][4], float r[3]);
89 void mul_m3_v3(float M[3][3], float r[3]);
90 void mul_v3_m3v3(float r[3], float M[3][3], float a[3]);
91 void mul_transposed_m3_v3(float M[3][3], float r[3]);
92 void mul_m3_v3_double(float M[3][3], double r[3]);
94 void mul_m3_fl(float R[3][3], float f);
95 void mul_m4_fl(float R[4][4], float f);
96 void mul_mat3_m4_fl(float R[4][4], float f);
98 int invert_m3(float R[3][3]);
99 int invert_m3_m3(float R[3][3], float A[3][3]);
100 int invert_m4(float R[4][4]);
101 int invert_m4_m4(float R[4][4], float A[4][4]);
103 /****************************** Linear Algebra *******************************/
105 void transpose_m3(float R[3][3]);
106 void transpose_m4(float R[4][4]);
108 void normalize_m3(float R[3][3]);
109 void normalize_m3_m3(float R[3][3], float A[3][3]);
110 void normalize_m4(float R[4][4]);
111 void normalize_m4_m4(float R[4][4], float A[4][4]);
113 void orthogonalize_m3(float R[3][3], int axis);
114 void orthogonalize_m4(float R[4][4], int axis);
116 int is_orthogonal_m3(float mat[3][3]);
117 int is_orthogonal_m4(float mat[4][4]);
119 void adjoint_m3_m3(float R[3][3], float A[3][3]);
120 void adjoint_m4_m4(float R[4][4], float A[4][4]);
122 float determinant_m2(
125 float determinant_m3(
126 float a, float b, float c,
127 float d, float e, float f,
128 float g, float h, float i);
129 float determinant_m4(float A[4][4]);
131 void svd_m4(float U[4][4], float s[4], float V[4][4], float A[4][4]);
132 void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon);
134 /****************************** Transformations ******************************/
136 void scale_m3_fl(float R[3][3], float scale);
137 void scale_m4_fl(float R[4][4], float scale);
139 float mat3_to_scale(float M[3][3]);
140 float mat4_to_scale(float M[4][4]);
142 void size_to_mat3(float R[3][3], const float size[3]);
143 void size_to_mat4(float R[4][4], const float size[3]);
145 void mat3_to_size(float r[3], float M[3][3]);
146 void mat4_to_size(float r[3], float M[4][4]);
148 void translate_m4(float mat[4][4], float tx, float ty, float tz);
149 void rotate_m4(float mat[4][4], const char axis, const float angle);
152 void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[][3]);
153 void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]);
155 void loc_eul_size_to_mat4(float R[4][4],
156 const float loc[3], const float eul[3], const float size[3]);
157 void loc_eulO_size_to_mat4(float R[4][4],
158 const float loc[3], const float eul[3], const float size[3], const short order);
159 void loc_quat_size_to_mat4(float R[4][4],
160 const float loc[3], const float quat[4], const float size[3]);
161 void loc_axisangle_size_to_mat4(float R[4][4],
162 const float loc[3], const float axis[4], const float angle, const float size[3]);
164 void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t);
165 void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t);
167 int is_negative_m3(float mat[3][3]);
168 int is_negative_m4(float mat[4][4]);
170 /*********************************** Other ***********************************/
172 void print_m3(const char *str, float M[3][3]);
173 void print_m4(const char *str, float M[3][4]);
179 #endif /* BLI_MATH_MATRIX_H */