4 void quadsquare::EnableEdgeVertex(
int index,
bool IncrementCount,
const quadcornerdata &cd )
8 if ( (
EnabledFlags&(1<<index) ) && IncrementCount ==
false )
return;
12 if ( IncrementCount ==
true && (index == 0 || index == 3) )
39 bool SameParent = ( (index-ci)&2 ) ?
true :
false;
41 ci = ci^1^( (index&1)<<1 );
45 if (SameParent)
break;
49 p = p->EnableDescendant( ct, stack, *pcd );
53 if ( IncrementCount ==
true && (index == 0 || index == 3) )
63 int ChildIndex = path[count];
65 EnableChild( ChildIndex, cd );
68 SetupCornerData( &q, cd, ChildIndex );
69 return Child[ChildIndex]->EnableDescendant( count, path, q );
71 return Child[ChildIndex];
78 if (
Child[index] == 0) {
80 SetupCornerData( &q, cd, index );
85 void quadsquare::EnableChild(
int index,
const quadcornerdata &cd )
93 EnableEdgeVertex( index,
true, cd );
94 EnableEdgeVertex( (index+1)&3,
true, cd );
95 if (
Child[index] == 0)
96 CreateChild( index, cd );
100 void quadsquare::NotifyChildDisable(
const quadcornerdata &cd,
int index )
108 if (index&2) s =
this;
109 else s = GetFarNeighbor( 1, cd );
112 if (index == 1 || index == 2) s = GetFarNeighbor( 2, cd );
129 float dx = fabs( x-Viewer.i );
130 float dy = fabs( y-Viewer.j );
131 float dz = fabs( z-Viewer.k );
135 return (error*DetailThreshold) > d;
144 float half = size*0.5;
145 float dx = fabs( x+half-Viewer.i )-half;
146 float dy = fabs( (miny+maxy)*0.5-Viewer.j )-(maxy-
miny)*0.5;
147 float dz = fabs( z+half-Viewer.k )-half;
151 return (error*DetailThreshold) > d;
174 static unsigned int calculatestage(
unsigned int numstages,
unsigned int whichstage )
176 unsigned int stage = 0;
180 int tmp = 1<<(whichstage%4);
181 stage += ( tmp<<( (count++)*4 ) );
192 unsigned int transformedstage = 0;
193 while ( ( tmp = ( stage&(1|2|4|8) ) ) != 0 ) {
195 transformedstage <<= 4;
196 transformedstage |= ( (*updateorder)(tmp) );
198 return transformedstage;
267 const Vector &ViewerLocation,
269 unsigned short numstages,
270 unsigned short whichstage,
273 DetailThreshold = Detail;
278 const Vector &ViewerLocation,
280 unsigned int whichChildren )
286 int half = 1<<cd.
Level;
319 SetupCornerData( &q, cd, 1 );
320 Child[1]->UpdateAux( q, ViewerLocation,
Error[3], whichChildren>>4 );
323 SetupCornerData( &q, cd, 0 );
324 Child[0]->UpdateAux( q, ViewerLocation,
Error[2], whichChildren>>4 );
327 SetupCornerData( &q, cd, 2 );
328 Child[2]->UpdateAux( q, ViewerLocation,
Error[4], whichChildren>>4 );
331 SetupCornerData( &q, cd, 3 );
332 Child[3]->UpdateAux( q, ViewerLocation,
Error[5], whichChildren>>4 );
337 SetupCornerData( &q, cd, 1 );
338 Child[1]->UpdateAux( q, ViewerLocation,
Error[3], 0 );
341 SetupCornerData( &q, cd, 0 );
342 Child[0]->UpdateAux( q, ViewerLocation,
Error[2], 0 );
345 SetupCornerData( &q, cd, 2 );
346 Child[2]->UpdateAux( q, ViewerLocation,
Error[4], 0 );
349 SetupCornerData( &q, cd, 3 );
350 Child[3]->UpdateAux( q, ViewerLocation,
Error[5], 0 );
376 return vec*( scale/vec.Magnitude() );
383 return Vector( tmp.i*normalscale.i, tmp.j*normalscale.j, tmp.k*normalscale.k );
403 if (e > maxerror) maxerror = e;
408 for (i = 0; i < 4; i++) {
410 if (y <
MinY)
MinY = (
unsigned short) y;
411 if (y >
MaxY)
MaxY = (
unsigned short) y;
415 if (e > maxerror) maxerror = e;
416 Error[0] = (
unsigned short) e;
418 if (e > maxerror) maxerror = e;
419 Error[1] = (
unsigned short) e;
421 for (i = 0; i < 4; i++) {
423 if (y <
MinY)
MinY = (
unsigned short) y;
424 if (y >
MaxY)
MaxY = (
unsigned short) y;
427 for (i = 0; i < 4; i++) {
430 SetupCornerData( &q, cd, i );
438 (
unsigned short) (fabs( (
double) ( (
Vertex[0].
Y
441 if (
Error[i+2] > maxerror) maxerror =
Error[i+2];
446 float OneOverSize = 1.0/(2<<cd.
Level);
450 (Vertex[4].Y-Vertex[2].Y)*OneOverSize,
458 V = &vertexs[Vertex[1].vertindex];
462 s = GetFarNeighbor( 1, cd );
467 V = &vertexs[Vertex[2].vertindex];
469 (Vertex[0].Y-v)*OneOverSize,
471 s = GetFarNeighbor( 2, cd );
476 V = &vertexs[Vertex[3].vertindex];
480 s = GetFarNeighbor( 3, cd );
485 V = &vertexs[Vertex[4].vertindex];
487 (v-Vertex[0].Y)*OneOverSize,