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 #ifdef BLI_MATH_INLINE
36 #include "intern/math_vector_inline.c"
39 /************************************* Init ***********************************/
41 MINLINE void zero_v2(float r[2]);
42 MINLINE void zero_v3(float r[3]);
43 MINLINE void zero_v4(float r[4]);
45 MINLINE void copy_v2_v2(float r[2], const float a[2]);
46 MINLINE void copy_v3_v3(float r[3], const float a[3]);
47 MINLINE void copy_v4_v4(float r[4], const float a[4]);
49 MINLINE void swap_v2_v2(float a[2], float b[2]);
50 MINLINE void swap_v3_v3(float a[3], float b[3]);
51 MINLINE void swap_v4_v4(float a[4], float b[4]);
53 /********************************* Arithmetic ********************************/
55 MINLINE void add_v2_v2(float r[2], const float a[2]);
56 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]);
57 MINLINE void add_v3_v3(float r[3], const float a[3]);
58 MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]);
60 MINLINE void sub_v2_v2(float r[2], const float a[2]);
61 MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]);
62 MINLINE void sub_v3_v3(float r[3], const float a[3]);
63 MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]);
65 MINLINE void mul_v2_fl(float r[2], float f);
66 MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f);
67 MINLINE void mul_v3_fl(float r[3], float f);
68 MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f);
69 MINLINE void mul_v2_v2(float r[2], const float a[2]);
70 MINLINE void mul_v3_v3(float r[3], const float a[3]);
71 MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]);
73 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
74 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
75 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f);
76 MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f);
77 MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]);
79 MINLINE void negate_v3(float r[3]);
80 MINLINE void negate_v3_v3(float r[3], const float a[3]);
82 MINLINE float dot_v2v2(const float a[2], const float b[2]);
83 MINLINE float dot_v3v3(const float a[3], const float b[3]);
85 MINLINE float cross_v2v2(const float a[2], const float b[2]);
86 MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]);
88 MINLINE void star_m3_v3(float R[3][3],float a[3]);
90 /*********************************** Length **********************************/
92 MINLINE float len_v2(const float a[2]);
93 MINLINE float len_v2v2(const float a[2], const float b[2]);
94 MINLINE float len_v3(const float a[3]);
95 MINLINE float len_v3v3(const float a[3], const float b[3]);
97 MINLINE float normalize_v2(float r[2]);
98 MINLINE float normalize_v2_v2(float r[2], const float a[2]);
99 MINLINE float normalize_v3(float r[3]);
100 MINLINE float normalize_v3_v3(float r[3], const float a[3]);
102 /******************************* Interpolation *******************************/
104 void interp_v2_v2v2(float r[2], const float a[2], const float b[2], const float t);
105 void interp_v2_v2v2v2(float r[2], const float a[2], const float b[2], const float c[3], const float t[3]);
106 void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t);
107 void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3]);
108 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]);
109 void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t);
111 void mid_v3_v3v3(float r[3], float a[3], float b[3]);
113 /********************************* Comparison ********************************/
115 MINLINE int is_zero_v3(float a[3]);
116 MINLINE int is_one_v3(float a[3]);
118 MINLINE int equals_v3v3(float a[3], float b[3]);
119 MINLINE int compare_v3v3(float a[3], float b[3], float limit);
120 MINLINE int compare_len_v3v3(float a[3], float b[3], float limit);
122 MINLINE int compare_v4v4(float a[4], float b[4], float limit);
124 /********************************** Angles ***********************************/
125 /* - angle with 2 arguments is angle between vector */
126 /* - angle with 3 arguments is angle between 3 points at the middle point */
127 /* - angle_normalized_* is faster equivalent if vectors are normalized */
129 float angle_v2v2(float a[2], float b[2]);
130 float angle_v2v2v2(float a[2], float b[2], float c[2]);
131 float angle_normalized_v2v2(float a[2], float b[2]);
132 float angle_v3v3(float a[2], float b[2]);
133 float angle_v3v3v3(float a[2], float b[2], float c[2]);
134 float angle_normalized_v3v3(const float v1[3], const float v2[3]);
135 void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
136 void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
138 /********************************* Geometry **********************************/
140 void project_v3_v3v3(float r[3], float p[3], float n[3]);
141 void reflect_v3_v3v3(float r[3], float v[3], float n[3]);
142 void ortho_basis_v3v3_v3(float r1[3], float r2[3], float a[3]);
143 void bisect_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]);
145 /*********************************** Other ***********************************/
147 void print_v2(char *str, float a[2]);
148 void print_v3(char *str, float a[3]);
149 void print_v4(char *str, float a[4]);
151 MINLINE void normal_short_to_float_v3(float r[3], const short n[3]);
152 MINLINE void normal_float_to_short_v3(short r[3], const float n[3]);
154 void minmax_v3_v3v3(float r[3], float min[3], float max[3]);
160 #endif /* BLI_MATH_VECTOR */