Game Development Reference
In-Depth Information
q 11
q 12
q 13
q 14
q 12
q 22
q 23
q 24
q 13
q 23
q 33
q 34
q 14
q 24
q 34
q 44
K p =
The quadric matrix for the vertex is defined as the sum of each plane
quadric.
Implementation
Now we will look at how this algorithm can be implemented. We start by
creating a structure to store the information we need for a vertex pair.
Since the rest of our code uses point indices into a point list to describe
each vertex, we use two indices to indicate the number of each vertex in
the vertex pair. The next member is a VECTOR storing the ( x , y , z )
location of the contraction target for this pair. Finally, we store the
numerical value for the error for this vertex pair.
typedef struct stQUADRICPAIR{
unsigned short v1, v2;
//point indices
VECTOR v;
//location for contraction target
double error;
//Stores quadric error
}QUADRICPAIR;
The function call to reduce polygons takes a single parameter, which is
the target total polygons. The purpose of the function is to take an
arbitrary mesh containing more polygons than the target and reduce the
polygon total to that passed as a parameter. If you examine the function,
you will see that after checking whether the target polygon total is less
than the current total and marking any morph targets as invalid, a copy of
the original mesh is created using the function call CreatePatchInfo .
The function proceeds by creating quadric matrices for each vertex in
the mesh. We do this using a CQuadric class. This class has member
variables to represent the quadric matrix and constructors to create a
quadric matrix from the plane variables a , b , c and d . Member functions
are available to create the matrix from three points or three quadrics. A
member function, QEM , returns the error for a vertex and a member
function, CreateValidPairsArray , can create an array of quadric pairs that
forms the basis of the algorithm.
Search Nedrilad ::




Custom Search