diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-08 16:55:36 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-08 16:55:36 +0400 |
commit | 89c8de1f48607a5d887b44966be220ed9bf93285 (patch) | |
tree | 270d805e57d96f64c395df8505b2100d22dddf2e | |
parent | 7d4eee2b1879e7e1224787761d3ef3bfe4a891d6 (diff) |
add matrix multiply for projection that outputs 2d values.
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 5 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_matrix.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 18 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_uvproject.c | 7 |
4 files changed, 24 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 96417cdf44c..7581aa745ff 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -118,8 +118,9 @@ static const char *cmpcode_to_str(int code) /* thresh is threshold for comparing vertices, uvs, vertex colors, * weights, etc.*/ -static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, float thresh) +static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, const float thresh) { + const float thresh_sq = thresh * thresh; CustomDataLayer *l1, *l2; int i, i1 = 0, i2 = 0, tot, j; @@ -225,7 +226,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2 int ltot = m1->totloop; for (j = 0; j < ltot; j++, lp1++, lp2++) { - if (len_v2v2(lp1->uv, lp2->uv) > thresh) + if (len_squared_v2v2(lp1->uv, lp2->uv) > thresh_sq) return MESHCMP_LOOPUVMISMATCH; } } diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index ada2d43b81f..e408b223923 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -88,11 +88,13 @@ void mul_serie_m4(float R[4][4], void mul_m4_v3(float M[4][4], float r[3]); void mul_v3_m4v3(float r[3], float M[4][4], const float v[3]); +void mul_v2_m4v3(float r[2], float M[4][4], const float v[3]); void mul_v2_m2v2(float r[2], float M[2][2], const float v[2]); void mul_mat3_m4_v3(float M[4][4], float r[3]); void mul_m4_v4(float M[4][4], float r[4]); void mul_v4_m4v4(float r[4], float M[4][4], const float v[4]); void mul_project_m4_v3(float M[4][4], float vec[3]); +void mul_v2_project_m4_v3(float r[2], float M[4][4], const float vec[3]); void mul_m3_v3(float M[3][3], float r[3]); void mul_v3_m3v3(float r[3], float M[3][3], const float a[3]); diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index d9063b80f13..fa85e015ee8 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -344,6 +344,15 @@ void mul_v3_m4v3(float r[3], float mat[4][4], const float vec[3]) r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; } +void mul_v2_m4v3(float r[2], float mat[4][4], const float vec[3]) +{ + float x; + + x = vec[0]; + r[0] = x * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; + r[1] = x * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; +} + void mul_v2_m2v2(float r[2], float mat[2][2], const float vec[2]) { float x; @@ -375,6 +384,15 @@ void mul_project_m4_v3(float mat[4][4], float vec[3]) vec[2] /= w; } +void mul_v2_project_m4_v3(float r[2], float mat[4][4], const float vec[3]) +{ + const float w = mul_project_m4_v3_zfac(mat, vec); + mul_v2_m4v3(r, mat, vec); + + r[0] /= w; + r[1] /= w; +} + void mul_v4_m4v4(float r[4], float mat[4][4], const float v[4]) { float x, y, z; diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index 962ff161ebc..45901f4a303 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -321,12 +321,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, do { unsigned int lidx = mp->loopstart + fidx; unsigned int vidx = mloop[lidx].v; - float tco[3]; - - copy_v3_v3(tco, coords[vidx]); - mul_project_m4_v3(best_projector->projmat, tco); - copy_v2_v2(mloop_uv[lidx].uv, tco); - + mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]); } while (fidx--); } } |