Blender V2.61 - r43446

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