Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-03 02:14:20 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-03 02:14:20 +0400
commit06c3d5bd09e104d070d9e6c97e4baa265094240c (patch)
tree4f2c500b06e67c06f7186b381245016acc2221fe /source/blender
parent20620a988a8919116c69b618af04a15535f89c4b (diff)
de-duplicate dominant axis calculation, exact same checks were in 6 different places.
added function: axis_dominant_v3(...)
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_math_geom.h2
-rw-r--r--source/blender/blenlib/intern/math_geom.c30
-rw-r--r--source/blender/blenlib/intern/scanfill.c16
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c13
-rw-r--r--source/blender/render/intern/source/rayshade.c12
-rw-r--r--source/blender/render/intern/source/render_texture.c10
-rw-r--r--source/blender/render/intern/source/shadeinput.c10
7 files changed, 32 insertions, 61 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index a2a4ffdc830..d494d63f56b 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -260,6 +260,8 @@ MINLINE void madd_sh_shfl(float r[9], const float sh[3], const float f);
float form_factor_hemi_poly(float p[3], float n[3],
float v1[3], float v2[3], float v3[3], float v4[3]);
+void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3]);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 9d42ee347d4..382448ebb1c 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -133,7 +133,8 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3])
float *cur, *prev;
int a, px=0, py=1;
- /* first: find dominant axis: 0==X, 1==Y, 2==Z */
+ /* first: find dominant axis: 0==X, 1==Y, 2==Z
+ * don't use 'axis_dominant_v3()' because we need max axis too */
x= fabsf(normal[0]);
y= fabsf(normal[1]);
z= fabsf(normal[2]);
@@ -1689,6 +1690,18 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], int (*callback)(int, int,
/****************************** Interpolation ********************************/
+/* get the 2 dominant axis values, 0==X, 1==Y, 2==Z */
+void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3])
+{
+ const float xn= fabsf(axis[0]);
+ const float yn= fabsf(axis[1]);
+ const float zn= fabsf(axis[2]);
+
+ if (zn >= xn && zn >= yn) { *axis_a= 0; *axis_b= 1; }
+ else if (yn >= xn && yn >= zn) { *axis_a= 0; *axis_b= 2; }
+ else { *axis_a= 1; *axis_b= 2; }
+}
+
static float tri_signed_area(const float v1[3], const float v2[3], const float v3[3], const int i, const int j)
{
return 0.5f*((v1[i]-v2[i])*(v2[j]-v3[j]) + (v1[j]-v2[j])*(v3[i]-v2[i]));
@@ -1696,17 +1709,10 @@ static float tri_signed_area(const float v1[3], const float v2[3], const float v
static int barycentric_weights(const float v1[3], const float v2[3], const float v3[3], const float co[3], const float n[3], float w[3])
{
- float xn, yn, zn, a1, a2, a3, asum;
- short i, j;
-
- /* find best projection of face XY, XZ or YZ: barycentric weights of
- the 2d projected coords are the same and faster to compute */
- xn= fabsf(n[0]);
- yn= fabsf(n[1]);
- zn= fabsf(n[2]);
- if(zn>=xn && zn>=yn) {i= 0; j= 1;}
- else if(yn>=xn && yn>=zn) {i= 0; j= 2;}
- else {i= 1; j= 2;}
+ float a1, a2, a3, asum;
+ int i, j;
+
+ axis_dominant_v3(&i, &j, n);
a1= tri_signed_area(v2, v3, co, i, j);
a2= tri_signed_area(v3, v1, co, i, j);
diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c
index 41b1fea32a6..369984c1719 100644
--- a/source/blender/blenlib/intern/scanfill.c
+++ b/source/blender/blenlib/intern/scanfill.c
@@ -96,7 +96,7 @@ ListBase fillvertbase = {NULL, NULL};
ListBase filledgebase = {NULL, NULL};
ListBase fillfacebase = {NULL, NULL};
-static short cox, coy;
+static int cox, coy;
/* **** FUBCTIONS FOR QSORT *************************** */
@@ -825,19 +825,7 @@ int BLI_edgefill(short mat_nr)
if(len==0.0f) return 0; /* no fill possible */
- norm[0]= fabs(norm[0]);
- norm[1]= fabs(norm[1]);
- norm[2]= fabs(norm[2]);
-
- if(norm[2]>=norm[0] && norm[2]>=norm[1]) {
- cox= 0; coy= 1;
- }
- else if(norm[1]>=norm[0] && norm[1]>=norm[2]) {
- cox= 0; coy= 2;
- }
- else {
- cox= 1; coy= 2;
- }
+ axis_dominant_v3(&cox, &coy, norm);
/* STEP 1: COUNT POLYS */
eve= fillvertbase.first;
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index c565e2fc305..830dc224c94 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1342,16 +1342,9 @@ static int cube_project_exec(bContext *C, wmOperator *op)
if(efa->f & SELECT) {
tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
normal_tri_v3( no,efa->v1->co, efa->v2->co, efa->v3->co);
-
- no[0]= fabs(no[0]);
- no[1]= fabs(no[1]);
- no[2]= fabs(no[2]);
-
- cox=0; coy= 1;
- if(no[2]>=no[0] && no[2]>=no[1]);
- else if(no[1]>=no[0] && no[1]>=no[2]) coy= 2;
- else { cox= 1; coy= 2; }
-
+
+ axis_dominant_v3(&cox, &coy, no);
+
tf->uv[0][0]= 0.5f+0.5f*cube_size*(loc[cox] + efa->v1->co[cox]);
tf->uv[0][1]= 0.5f+0.5f*cube_size*(loc[coy] + efa->v1->co[coy]);
dx = floor(tf->uv[0][0]);
diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c
index 1a58a665e0a..b8c4b05de50 100644
--- a/source/blender/render/intern/source/rayshade.c
+++ b/source/blender/render/intern/source/rayshade.c
@@ -485,18 +485,12 @@ void makeraytree(Render *re)
/* if(shi->osatex) */
static void shade_ray_set_derivative(ShadeInput *shi)
{
- float detsh, t00, t10, t01, t11, xn, yn, zn;
+ float detsh, t00, t10, t01, t11;
int axis1, axis2;
/* find most stable axis to project */
- xn= fabs(shi->facenor[0]);
- yn= fabs(shi->facenor[1]);
- zn= fabs(shi->facenor[2]);
-
- if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
- else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
- else { axis1= 1; axis2= 2; }
-
+ axis_dominant_v3(&axis1, &axis2, shi->facenor);
+
/* compute u,v and derivatives */
if(shi->obi->flag & R_TRANSFORMED) {
float v1[3], v2[3], v3[3];
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index 9459745cdbc..ae48b0f777f 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -3494,17 +3494,11 @@ void render_realtime_texture(ShadeInput *shi, Image *ima)
static void textured_face_generate_uv(float *uv, float *normal, float *hit, float *v1, float *v2, float *v3)
{
- float detsh, t00, t10, t01, t11, xn, yn, zn;
+ float detsh, t00, t10, t01, t11;
int axis1, axis2;
/* find most stable axis to project */
- xn= fabs(normal[0]);
- yn= fabs(normal[1]);
- zn= fabs(normal[2]);
-
- if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
- else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
- else { axis1= 1; axis2= 2; }
+ axis_dominant_v3(&axis1, &axis2, normal);
/* compute u,v and derivatives */
t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c
index f2a053e89d9..dd026740c33 100644
--- a/source/blender/render/intern/source/shadeinput.c
+++ b/source/blender/render/intern/source/shadeinput.c
@@ -756,17 +756,11 @@ void shade_input_set_uv(ShadeInput *shi)
}
else {
/* most of this could become re-used for faces */
- float detsh, t00, t10, t01, t11, xn, yn, zn;
+ float detsh, t00, t10, t01, t11;
int axis1, axis2;
/* find most stable axis to project */
- xn= fabs(shi->facenor[0]);
- yn= fabs(shi->facenor[1]);
- zn= fabs(shi->facenor[2]);
-
- if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
- else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
- else { axis1= 1; axis2= 2; }
+ axis_dominant_v3(&axis1, &axis2, shi->facenor);
/* compute u,v and derivatives */
t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];