Blender V2.61 - r43446
|
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_GEOM_H 00027 #define BLI_MATH_GEOM_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_geom_inline.c" 00041 #endif 00042 00043 /********************************** Polygons *********************************/ 00044 00045 void cent_tri_v3(float r[3], const float a[3], const float b[3], const float c[3]); 00046 void cent_quad_v3(float r[3], const float a[3], const float b[3], const float c[3], const float d[3]); 00047 00048 float normal_tri_v3(float r[3], const float a[3], const float b[3], const float c[3]); 00049 float normal_quad_v3(float r[3], const float a[3], const float b[3], const float c[3], const float d[3]); 00050 00051 float area_tri_v2(const float a[2], const float b[2], const float c[2]); 00052 float area_tri_signed_v2(const float v1[2], const float v2[2], const float v3[2]); 00053 float area_tri_v3(const float a[3], const float b[3], const float c[3]); 00054 float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]); 00055 float area_poly_v3(int nr, float verts[][3], const float normal[3]); 00056 00057 /********************************* Distance **********************************/ 00058 00059 float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2]); 00060 float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]); 00061 void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2]); 00062 00063 float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3]); 00064 float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]); 00065 float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); 00066 float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]); 00067 float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]); 00068 void closest_to_line_segment_v3(float r[3], const float p[3], const float l1[3], const float l2[3]); 00069 void closest_to_plane_v3(float r[3], const float plane_co[3], const float plane_no_unit[3], const float pt[3]); 00070 00071 00072 float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3]); 00073 float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2]); 00074 00075 /******************************* Intersection ********************************/ 00076 00077 /* TODO int return value consistency */ 00078 00079 /* line-line */ 00080 #define ISECT_LINE_LINE_COLINEAR -1 00081 #define ISECT_LINE_LINE_NONE 0 00082 #define ISECT_LINE_LINE_EXACT 1 00083 #define ISECT_LINE_LINE_CROSS 2 00084 00085 int isect_line_line_v2(const float a1[2], const float a2[2], const float b1[2], const float b2[2]); 00086 int isect_line_line_v2_int(const int a1[2], const int a2[2], const int b1[2], const int b2[2]); 00087 int isect_line_sphere_v3(const float l1[3], const float l2[3], const float sp[3], const float r, float r_p1[3], float r_p2[3]); 00088 int isect_line_sphere_v2(const float l1[2], const float l2[2], const float sp[2], const float r, float r_p1[2], float r_p2[2]); 00089 int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[2], const float v4[2], float vi[2]); 00090 00091 /* Returns the number of point of interests 00092 * 0 - lines are colinear 00093 * 1 - lines are coplanar, i1 is set to intersection 00094 * 2 - i1 and i2 are the nearest points on line 1 (v1, v2) and line 2 (v3, v4) respectively 00095 * */ 00096 00097 int isect_line_line_v3(const float v1[3], const float v2[3], 00098 const float v3[3], const float v4[3], 00099 float i1[3], float i2[3]); 00100 int isect_line_line_strict_v3(const float v1[3], const float v2[3], 00101 const float v3[3], const float v4[3], 00102 float vi[3], float *r_lambda); 00103 00104 /*if clip is nonzero, will only return true if lambda is >= 0.0 00105 (i.e. intersection point is along positive d)*/ 00106 int isect_ray_plane_v3(const float p1[3], const float d[3], 00107 const float v0[3], const float v1[3], const float v2[3], 00108 float *r_lambda, const int clip); 00109 00119 int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], 00120 const float plane_co[3], const float plane_no[3], const short no_flip); 00121 00133 void isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3], 00134 const float plane_a_co[3], const float plane_a_no[3], 00135 const float plane_b_co[3], const float plane_b_no[3]); 00136 00137 /* line/ray triangle */ 00138 int isect_line_tri_v3(const float p1[3], const float p2[3], 00139 const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]); 00140 int isect_ray_tri_v3(const float p1[3], const float d[3], 00141 const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]); 00142 int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], 00143 const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float threshold); 00144 int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], 00145 const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float epsilon); 00146 00147 /* point in polygon */ 00148 int isect_point_quad_v2(const float p[2], const float a[2], const float b[2], const float c[2], const float d[2]); 00149 00150 int isect_point_tri_v2(const float v1[2], const float v2[2], const float v3[2], const float pt[2]); 00151 int isect_point_tri_v2_int(const int x1, const int y1, const int x2, const int y2, const int a, const int b); 00152 int isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]); 00153 00154 void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], 00155 const float pt[2], float r_uv[2]); 00156 void isect_point_face_uv_v2(const int isquad, const float v0[2], const float v1[2], const float v2[2], 00157 const float v3[2], const float pt[2], float r_uv[2]); 00158 00159 /* other */ 00160 int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius, 00161 const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float ipoint[3]); 00162 00163 int isect_axial_line_tri_v3(const int axis, const float co1[3], const float co2[3], 00164 const float v0[3], const float v1[3], const float v2[3], float *r_lambda); 00165 00166 int isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3]); 00167 00168 int clip_line_plane(float p1[3], float p2[3], const float plane[4]); 00169 00170 void plot_line_v2v2i(const int p1[2], const int p2[2], int (*callback)(int, int, void *), void *userData); 00171 00172 /****************************** Interpolation ********************************/ 00173 00174 /* tri or quad, d can be NULL */ 00175 void interp_weights_face_v3(float w[4], 00176 const float a[3], const float b[3], const float c[3], const float d[3], const float p[3]); 00177 void interp_weights_poly_v3(float w[], float v[][3], const int n, const float p[3]); 00178 00179 void interp_cubic_v3(float x[3], float v[3], 00180 const float x1[3], const float v1[3], const float x2[3], const float v2[3], const float t); 00181 00182 int interp_sparse_array(float *array, const int list_size, const float invalid); 00183 00184 void barycentric_transform(float pt_tar[3], float const pt_src[3], 00185 const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3], 00186 const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3]); 00187 00188 void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], 00189 const float co[2], float w[3]); 00190 00191 void resolve_tri_uv(float r_uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2]); 00192 void resolve_quad_uv(float uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]); 00193 00194 /***************************** View & Projection *****************************/ 00195 00196 void lookat_m4(float mat[4][4], float vx, float vy, 00197 float vz, float px, float py, float pz, float twist); 00198 void polarview_m4(float mat[4][4], float dist, float azimuth, 00199 float incidence, float twist); 00200 00201 void perspective_m4(float mat[4][4], const float left, const float right, 00202 const float bottom, const float top, const float nearClip, const float farClip); 00203 void orthographic_m4(float mat[4][4], const float left, const float right, 00204 const float bottom, const float top, const float nearClip, const float farClip); 00205 void window_translate_m4(float winmat[][4], float perspmat[][4], 00206 const float x, const float y); 00207 00208 int box_clip_bounds_m4(float boundbox[2][3], 00209 const float bounds[4], float winmat[4][4]); 00210 void box_minmax_bounds_m4(float min[3], float max[3], 00211 float boundbox[2][3], float mat[4][4]); 00212 00213 /********************************** Mapping **********************************/ 00214 00215 void map_to_tube(float *u, float *v, const float x, const float y, const float z); 00216 void map_to_sphere(float *u, float *v, const float x, const float y, const float z); 00217 00218 /********************************** Normals **********************************/ 00219 00220 void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3], 00221 float n4[3], const float f_no[3], const float co1[3], const float co2[3], 00222 const float co3[3], const float co4[3]); 00223 00224 /********************************* Tangents **********************************/ 00225 00226 typedef struct VertexTangent { 00227 struct VertexTangent *next; 00228 float tang[3], uv[2]; 00229 } VertexTangent; 00230 00231 float *find_vertex_tangent(VertexTangent *vtang, const float uv[2]); 00232 void sum_or_add_vertex_tangent(void *arena, VertexTangent **vtang, 00233 const float tang[3], const float uv[2]); 00234 void tangent_from_uv(float uv1[2], float uv2[2], float uv3[2], 00235 float co1[3], float co2[3], float co3[3], float n[3], float tang[3]); 00236 00237 /******************************** Vector Clouds ******************************/ 00238 00239 void vcloud_estimate_transform(int list_size, float (*pos)[3], float *weight, 00240 float (*rpos)[3], float *rweight, 00241 float lloc[3],float rloc[3],float lrot[3][3],float lscale[3][3]); 00242 00243 /****************************** Spherical Harmonics *************************/ 00244 00245 /* Uses 2nd order SH => 9 coefficients, stored in this order: 00246 0 = (0,0), 00247 1 = (1,-1), 2 = (1,0), 3 = (1,1), 00248 4 = (2,-2), 5 = (2,-1), 6 = (2,0), 7 = (2,1), 8 = (2,2) */ 00249 00250 MINLINE void zero_sh(float r[9]); 00251 MINLINE void copy_sh_sh(float r[9], const float a[9]); 00252 MINLINE void mul_sh_fl(float r[9], const float f); 00253 MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9]); 00254 00255 MINLINE float eval_shv3(float r[9], const float v[3]); 00256 MINLINE float diffuse_shv3(float r[9], const float v[3]); 00257 MINLINE void vec_fac_to_sh(float r[9], const float v[3], const float f); 00258 MINLINE void madd_sh_shfl(float r[9], const float sh[3], const float f); 00259 00260 /********************************* Form Factor *******************************/ 00261 00262 float form_factor_hemi_poly(float p[3], float n[3], 00263 float v1[3], float v2[3], float v3[3], float v4[3]); 00264 00265 void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3]); 00266 00267 #ifdef __cplusplus 00268 } 00269 #endif 00270 00271 #endif /* BLI_MATH_GEOM_H */ 00272