Game Development Reference
In-Depth Information
Vector3 DeformableMD5::detailForce( int mesh, int vertex) {
int i;
Vector3 q, p;
Ve r t ex vertices = meshes[mesh].finalVertices;
int neighbors[MAX NEIGHBORS];
int numNeighbors = getNeighbors(mesh,vertex,neighbors);
/ if there are less than 3 particles in the neighborhood,
the particle is isolated
/
if (numNeighbors < 3) return vecCreate(0.0f,0.0f,0.0f);
/
/
Vector3 cm = vecZero(); Vector3 cm 0 = vecZero();
float masses = 0;
for (i=0;i < numNeighbors; i++) {
Ve r t ex v = &vertices[neighbors[i]];
masses += v −> mass;
vecScale(&cm, 1.0f/(masses)); vecScale(&cm 0, 1.0f/(masses));
/ calculate optimal rotation R /
Matrix3x3 A pq = matZero();
for (i=0;i
calculate centers of mass
{
Ve r t ex v = &vertices[neighbors[i]];
q=v
<
numNeighbors; i++)
−>
restPos
cm 0;
p=v −> pos cm;
for ( int j=0;j
<
3; j++) for ( int k=0;k
<
3; k++)
{
A pq[j][k] += v −> mass pk q[j];
}
} Matrix3x3 R = getRotationalPart (A pq);
/ calculate the position that preserves
best laplacian coordinates /
Vector3 diff = vertices[vertex].restPos cm 0;
matMult(&R, &diff);
Vector3 force = diff + cm vertices[vertex].pos;
vecScale(force, 1/(timeStep
timeStep));
return force;
}
Listing 14.2. The shape-matching algorithm for surface detail preservation on a model
definition using SSD.