Game Development Reference

In-Depth Information

q13 = a*c;

q14 = a*d;

q22 = b*b;

q23 = b*c;

q24 = b*d;

q33 = c*c;

q34 = c*d;

q44 = d*d;

v.x = 0.0; v.y = 0.0; v.z = 0.0;

valid = TRUE;

deleted = FALSE;

}

The function that is used in the
ReducePolygons
function to create plane

quadrics is the member function
CreateFromPoints
. This function will

create the quadric directly from any three points in the plane. The algebra

was shown earlier in the chapter. By passing the three points in the

triangular polygon we can construct a plane quadric. Summing these

plane quadrics for the polygons meeting at a vertex gives the vertex

quadric. Since we are interested in vertex quadrics, we must build these

from plane quadrics. The speed of the
ReducePolygons
function could be

improved by creating an array of plane quadrics so that the fundamental

quadric is calculated only once.

BOOL CQuadric::CreateFromPoints(POINT3D &p1, POINT3D &p2, POINT3D
↵

&p3)

{

double a, b, c, d, k,m, n,s, v, w;

k = p2.x/p3.x;

m = p1.x/p2.x;

n = (p1.y - m*p2.y)/(p2.y - k*p3.y);

s = (p1.z - m*p2.z - n*(p2.z - k*p3.z))/(n + k*n - 1 +m);

v = (s*(m - 1) - p1.z + m*p2.z)/(p1.y - m*p2.y);

w = (v*p1.y + p1.z +s)/p1.x;

c = sqrt(1.0/(1 + w*w + v*v));

a = -c*w;

b = c*v;

d = c*s;

q11 = a*a;

q12 = a*b;

q13 = a*c;

Search Nedrilad ::

Custom Search