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_VECTOR
29 #define BLI_MATH_VECTOR
35 #include "BLI_math_inline.h"
37 #ifdef BLI_MATH_INLINE
38 #include "intern/math_vector_inline.c"
41 /************************************* Init ***********************************/
43 MINLINE void zero_v2(float r[2]);
44 MINLINE void zero_v3(float r[3]);
45 MINLINE void zero_v4(float r[4]);
47 MINLINE void copy_v2_v2(float r[2], const float a[2]);
48 MINLINE void copy_v3_v3(float r[3], const float a[3]);
49 MINLINE void copy_v4_v4(float r[4], const float a[4]);
51 MINLINE void swap_v2_v2(float a[2], float b[2]);
52 MINLINE void swap_v3_v3(float a[3], float b[3]);
53 MINLINE void swap_v4_v4(float a[4], float b[4]);
55 /********************************* Arithmetic ********************************/
57 MINLINE void add_v2_v2(float r[2], const float a[2]);
58 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]);
59 MINLINE void add_v3_v3(float r[3], const float a[3]);
60 MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]);
62 MINLINE void sub_v2_v2(float r[2], const float a[2]);
63 MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]);
64 MINLINE void sub_v3_v3(float r[3], const float a[3]);
65 MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]);
67 MINLINE void mul_v2_fl(float r[2], float f);
68 MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f);
69 MINLINE void mul_v3_fl(float r[3], float f);
70 MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f);
71 MINLINE void mul_v2_v2(float r[2], const float a[2]);
72 MINLINE void mul_v3_v3(float r[3], const float a[3]);
73 MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]);
75 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
76 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
77 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f);
78 MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f);
79 MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]);
80 MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f);
82 MINLINE void negate_v3(float r[3]);
83 MINLINE void negate_v3_v3(float r[3], const float a[3]);
85 MINLINE float dot_v2v2(const float a[2], const float b[2]);
86 MINLINE float dot_v3v3(const float a[3], const float b[3]);
88 MINLINE float cross_v2v2(const float a[2], const float b[2]);
89 MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]);
91 MINLINE void star_m3_v3(float R[3][3],float a[3]);
93 /*********************************** Length **********************************/
95 MINLINE float len_v2(const float a[2]);
96 MINLINE float len_v2v2(const float a[2], const float b[2]);
97 MINLINE float len_v3(const float a[3]);
98 MINLINE float len_v3v3(const float a[3], const float b[3]);
99 MINLINE float len_squared_v3v3(const float a[3], const float b[3]);
101 MINLINE float normalize_v2(float r[2]);
102 MINLINE float normalize_v2_v2(float r[2], const float a[2]);
103 MINLINE float normalize_v3(float r[3]);
104 MINLINE float normalize_v3_v3(float r[3], const float a[3]);
106 /******************************* Interpolation *******************************/
108 void interp_v2_v2v2(float r[2], const float a[2], const float b[2], const float t);
109 void interp_v2_v2v2v2(float r[2], const float a[2], const float b[2], const float c[3], const float t[3]);
110 void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t);
111 void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3]);
112 void interp_v3_v3v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3], const float w[4]);
113 void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t);
114 void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3]);
116 void mid_v3_v3v3(float r[3], float a[3], float b[3]);
118 /********************************* Comparison ********************************/
120 MINLINE int is_zero_v3(float a[3]);
121 MINLINE int is_one_v3(float a[3]);
123 MINLINE int equals_v3v3(float a[3], float b[3]);
124 MINLINE int compare_v3v3(float a[3], float b[3], float limit);
125 MINLINE int compare_len_v3v3(float a[3], float b[3], float limit);
127 MINLINE int compare_v4v4(float a[4], float b[4], float limit);
129 /********************************** Angles ***********************************/
130 /* - angle with 2 arguments is angle between vector */
131 /* - angle with 3 arguments is angle between 3 points at the middle point */
132 /* - angle_normalized_* is faster equivalent if vectors are normalized */
134 float angle_v2v2(float a[2], float b[2]);
135 float angle_v2v2v2(float a[2], float b[2], float c[2]);
136 float angle_normalized_v2v2(float a[2], float b[2]);
137 float angle_v3v3(float a[2], float b[2]);
138 float angle_v3v3v3(float a[2], float b[2], float c[2]);
139 float angle_normalized_v3v3(const float v1[3], const float v2[3]);
140 void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
141 void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
143 /********************************* Geometry **********************************/
145 void project_v3_v3v3(float r[3], float p[3], float n[3]);
146 void reflect_v3_v3v3(float r[3], float v[3], float n[3]);
147 void ortho_basis_v3v3_v3(float r1[3], float r2[3], float a[3]);
148 void bisect_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]);
150 /*********************************** Other ***********************************/
152 void print_v2(char *str, float a[2]);
153 void print_v3(char *str, float a[3]);
154 void print_v4(char *str, float a[4]);
156 MINLINE void normal_short_to_float_v3(float r[3], const short n[3]);
157 MINLINE void normal_float_to_short_v3(short r[3], const float n[3]);
159 void minmax_v3_v3v3(float r[3], float min[3], float max[3]);
165 #endif /* BLI_MATH_VECTOR */