Game Development Reference
In-Depth Information
Table 16.1 Distances and squared distances
Distance
Distance squared
0.01
0.0001
0.1
0.01
1
1
10
100
100
10 000
The distance between two points in 3D space is easily calculated from an
extension to Pythagoras' theorem.
double x,y, z;
x = (x1 - x2);
y = (y1 - y2);
z = (z1 - z2);
dist = sqrt(x * x +y *y + z * z);
Unfortunately, square roots are computationally expensive. But we are
only interested in staying inside a parameter, so we can use the squared
distance (see Table 16.1).
QUADRICPAIR *CQuadric::CreateValidPairsArray(OBJECTINFO &oi,
int &qpTotal, double distance)
{
POLYGON *ply = oi.plys;
int qpMax = oi.numpolygons*4, i, n,m, j;
QUADRICPAIR *qp = new QUADRICPAIR[qpMax], *qptmp;
BOOL found;
double vsqdist, sqdist = distance * distance;
qpTotal = 0;
if (!qp) return NULL;
for(i=0; i<oi.numpolygons; i++){
found = FALSE;
for(n=0; n<ply->numverts; n++){
m = (n==(ply->numverts-1))?0:n+1
for (j=0; j<qpTotal; j++){
 
Search Nedrilad ::




Custom Search