# [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17513] branches/soc-2008-nicholasbishop/ source/blender/blenkernel/intern/multires.c: WIP: Moved calculating the TS matrix into it's own function, since it' s getting a bit complicated now.

Nicholas Bishop nicholasbishop at gmail.com
Thu Nov 20 07:00:55 CET 2008

```Revision: 17513
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17513
Author:   nicholasbishop
Date:     2008-11-20 07:00:55 +0100 (Thu, 20 Nov 2008)

Log Message:
-----------
WIP: Moved calculating the TS matrix into it's own function, since it's getting a bit complicated now.

Modified Paths:
--------------
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-11-20 05:55:42 UTC (rev 17512)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-11-20 06:00:55 UTC (rev 17513)
@@ -952,6 +952,52 @@
return -1;
}

+/* Calculate the TS matrix used for applying displacements.
+   Uses the undisplaced subdivided mesh's curvature to find a
+   smoothly normal and tangents. */
+static void calc_disp_mat(MultiresDisplacer *d, float mat[3][3])
+{
+	int u = multires_index_at_loc(d->face_index, d->x + 1, d->y, d, &d->edges_primary);
+	int v = multires_index_at_loc(d->face_index, d->x, d->y + 1, d, &d->edges_primary);
+	float norm[3], t1[3], t2[3], inv[3][3];
+	MVert *base = d->subco + d->subco_index;
+
+	printf("f=%d, x=%d, y=%d, i=%d, u=%d, v=%d ", d->face_index, d->x, d->y, d->subco_index, u, v);
+
+	norm[0] = base->no[0] / 32767.0f;
+	norm[1] = base->no[1] / 32767.0f;
+	norm[2] = base->no[2] / 32767.0f;
+
+	/* If either u or v is -2, it's on a boundary. In this
+	   case, back up by one row/column and use the same
+	   vector as the preceeding sub-edge. */
+
+	if(u == -2) {
+		u = multires_index_at_loc(d->face_index, d->x - 1, d->y, d, &d->edges_primary);
+		VecSubf(t1, base->co, d->subco[u].co);
+	}
+	else
+		VecSubf(t1, d->subco[u].co, base->co);
+
+	if(v == -2) {
+		v = multires_index_at_loc(d->face_index, d->x, d->y - 1, d, &d->edges_primary);
+		VecSubf(t2, base->co, d->subco[v].co);
+	}
+	else
+		VecSubf(t2, d->subco[v].co, base->co);
+
+	printf("uu=%d, vv=%d\n", u, v);
+
+	Normalize(t1);
+	Normalize(t2);
+	Mat3FromColVecs(mat, t1, t2, norm);
+
+	if(d->invert) {
+		Mat3Inv(inv, mat);
+		Mat3CpyMat3(mat, inv);
+	}
+}
+
static void multires_displace(MultiresDisplacer *d, float co[3])
{
float disp[3];
@@ -1028,8 +1074,8 @@
MultiresDisplacer d;
int i, S, x, y;

-	if(subco)
-		d.subco = subco;
+	d.subco = subco;
+	d.subco_index = 0;

for(i = 0; i < me->totface; ++i) {
const int numVerts = mface[i].v4 ? 4 : 3;
@@ -1039,7 +1085,7 @@
multires_displacer_anchor(&d, 1, 0);
multires_displace(&d, mvert->co);
++mvert;
-		++d.subco;
+		++d.subco_index;

/* Cross */
for(S = 0; S < numVerts; ++S) {
@@ -1047,7 +1093,7 @@
for(x = 1; x < gridFaces; ++x) {
multires_displace(&d, mvert->co);
++mvert;
-				++d.subco;
+				++d.subco_index;
}
}

@@ -1058,7 +1104,7 @@
for(x = 1; x < gridFaces; x++) {
multires_displace(&d, mvert->co);
++mvert;
-					++d.subco;
+					++d.subco_index;
}
multires_displacer_jump(&d);
}
@@ -1088,7 +1134,7 @@
}
}
++mvert;
-			++d.subco;
+			++d.subco_index;
}
}

@@ -1101,7 +1147,7 @@
multires_displace(&d, mvert->co);
}
++mvert;
-		++d.subco;
+		++d.subco_index;
}

if(!invert)

```