add matrix multiply for projection that outputs 2d values.

This commit is contained in:
Campbell Barton
2013-05-08 12:55:36 +00:00
parent 7d4eee2b18
commit 89c8de1f48
4 changed files with 24 additions and 8 deletions

View File

@@ -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;
}
}

View File

@@ -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]);

View File

@@ -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;

View File

@@ -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--);
}
}