|
Blender
V2.59
|
00001 /* 00002 * $Id: BLI_math_vector.h 37276 2011-06-06 22:10:05Z psy-fi $ 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_VECTOR_H 00029 #define BLI_MATH_VECTOR_H 00030 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif 00038 00039 #include "BLI_math_inline.h" 00040 00041 #ifdef BLI_MATH_INLINE_H 00042 #include "intern/math_vector_inline.c" 00043 #endif 00044 00045 /************************************* Init ***********************************/ 00046 00047 MINLINE void zero_v2(float r[2]); 00048 MINLINE void zero_v3(float r[3]); 00049 MINLINE void zero_v4(float r[4]); 00050 00051 MINLINE void copy_v2_v2(float r[2], const float a[2]); 00052 MINLINE void copy_v3_v3(float r[3], const float a[3]); 00053 MINLINE void copy_v4_v4(float r[4], const float a[4]); 00054 00055 MINLINE void swap_v2_v2(float a[2], float b[2]); 00056 MINLINE void swap_v3_v3(float a[3], float b[3]); 00057 MINLINE void swap_v4_v4(float a[4], float b[4]); 00058 00059 /********************************* Arithmetic ********************************/ 00060 00061 MINLINE void add_v3_fl(float r[3], float f); 00062 MINLINE void add_v4_fl(float r[4], float f); 00063 MINLINE void add_v2_v2(float r[2], const float a[2]); 00064 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]); 00065 MINLINE void add_v3_v3(float r[3], const float a[3]); 00066 MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]); 00067 00068 MINLINE void sub_v2_v2(float r[2], const float a[2]); 00069 MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]); 00070 MINLINE void sub_v3_v3(float r[3], const float a[3]); 00071 MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]); 00072 MINLINE void sub_v4_v4(float r[4], const float a[4]); 00073 MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]); 00074 00075 MINLINE void mul_v2_fl(float r[2], float f); 00076 MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f); 00077 MINLINE void mul_v3_fl(float r[3], float f); 00078 MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f); 00079 MINLINE void mul_v2_v2(float r[2], const float a[2]); 00080 MINLINE void mul_v3_v3(float r[3], const float a[3]); 00081 MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]); 00082 MINLINE void mul_v4_fl(float r[4], float f); 00083 00084 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f); 00085 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]); 00086 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f); 00087 MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f); 00088 MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]); 00089 MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f); 00090 00091 MINLINE void negate_v3(float r[3]); 00092 MINLINE void negate_v3_v3(float r[3], const float a[3]); 00093 MINLINE void negate_v4(float r[4]); 00094 MINLINE void negate_v4_v4(float r[4], const float a[3]); 00095 00096 MINLINE float dot_v2v2(const float a[2], const float b[2]); 00097 MINLINE float dot_v3v3(const float a[3], const float b[3]); 00098 00099 MINLINE float cross_v2v2(const float a[2], const float b[2]); 00100 MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]); 00101 00102 MINLINE void star_m3_v3(float R[3][3],float a[3]); 00103 00104 /*********************************** Length **********************************/ 00105 00106 MINLINE float len_v2(const float a[2]); 00107 MINLINE float len_v2v2(const float a[2], const float b[2]); 00108 MINLINE float len_squared_v2v2(const float a[3], const float b[3]); 00109 MINLINE float len_v3(const float a[3]); 00110 MINLINE float len_v3v3(const float a[3], const float b[3]); 00111 MINLINE float len_squared_v3v3(const float a[3], const float b[3]); 00112 00113 MINLINE float normalize_v2(float r[2]); 00114 MINLINE float normalize_v2_v2(float r[2], const float a[2]); 00115 MINLINE float normalize_v3(float r[3]); 00116 MINLINE float normalize_v3_v3(float r[3], const float a[3]); 00117 00118 /******************************* Interpolation *******************************/ 00119 00120 void interp_v2_v2v2(float r[2], const float a[2], const float b[2], const float t); 00121 void interp_v2_v2v2v2(float r[2], const float a[2], const float b[2], const float c[3], const float t[3]); 00122 void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t); 00123 void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3]); 00124 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]); 00125 void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t); 00126 void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3]); 00127 00128 void mid_v3_v3v3(float r[3], const float a[3], const float b[3]); 00129 00130 /********************************* Comparison ********************************/ 00131 00132 MINLINE int is_zero_v3(const float a[3]); 00133 MINLINE int is_zero_v4(const float a[4]); 00134 MINLINE int is_one_v3(const float a[3]); 00135 00136 MINLINE int equals_v2v2(const float *v1, const float *v2); 00137 MINLINE int equals_v3v3(const float a[3], const float b[3]); 00138 MINLINE int compare_v3v3(const float a[3], const float b[3], const float limit); 00139 MINLINE int compare_len_v3v3(const float a[3], const float b[3], const float limit); 00140 00141 MINLINE int compare_v4v4(const float a[4], const float b[4], const float limit); 00142 MINLINE int equals_v4v4(const float a[4], const float b[4]); 00143 00144 MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]); 00145 00146 /********************************** Angles ***********************************/ 00147 /* - angle with 2 arguments is angle between vector */ 00148 /* - angle with 3 arguments is angle between 3 points at the middle point */ 00149 /* - angle_normalized_* is faster equivalent if vectors are normalized */ 00150 00151 float angle_v2v2(const float a[2], const float b[2]); 00152 float angle_v2v2v2(const float a[2], const float b[2], const float c[2]); 00153 float angle_normalized_v2v2(const float a[2], const float b[2]); 00154 float angle_v3v3(const float a[3], const float b[3]); 00155 float angle_v3v3v3(const float a[3], const float b[3], const float c[3]); 00156 float angle_normalized_v3v3(const float v1[3], const float v2[3]); 00157 void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]); 00158 void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]); 00159 00160 /********************************* Geometry **********************************/ 00161 00162 void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]); 00163 void project_v3_v3v3(float r[3], const float p[3], const float n[3]); 00164 void reflect_v3_v3v3(float r[3], const float v[3], const float n[3]); 00165 void ortho_basis_v3v3_v3(float r1[3], float r2[3], const float a[3]); 00166 void bisect_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]); 00167 void rotate_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle); 00168 void rotate_normalized_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle); 00169 00170 /*********************************** Other ***********************************/ 00171 00172 void print_v2(const char *str, const float a[2]); 00173 void print_v3(const char *str, const float a[3]); 00174 void print_v4(const char *str, const float a[4]); 00175 00176 MINLINE void normal_short_to_float_v3(float r[3], const short n[3]); 00177 MINLINE void normal_float_to_short_v3(short r[3], const float n[3]); 00178 00179 void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]); 00180 00181 /***************************** Array Functions *******************************/ 00182 /* attempted to follow fixed length vertex functions. names could be improved*/ 00183 void range_vni(int *array, const int size, const int start); 00184 void negate_vn(float *array_tar, const int size); 00185 void negate_vn_vn(float *array_tar, const float *array_src, const int size); 00186 void mul_vn_fl(float *array, const int size, const float f); 00187 void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f); 00188 void add_vn_vn(float *array_tar, const float *array_src, const int size); 00189 void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); 00190 void sub_vn_vn(float *array_tar, const float *array_src, const int size); 00191 void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); 00192 void fill_vni(int *array_tar, const int size, const int val); 00193 void fill_vn(float *array_tar, const int size, const float val); 00194 00195 #ifdef __cplusplus 00196 } 00197 #endif 00198 00199 #endif /* BLI_MATH_VECTOR_H */ 00200