21 unsigned int*quadsquare::VertexAllocated;
22 unsigned int*quadsquare::VertexCount;
25 std::vector< TextureIndex >quadsquare::indices;
26 std::vector< unsigned int >*quadsquare::unusedvertices;
28 std::vector< TerrainTexture >*quadsquare::textures;
29 Vector quadsquare:: normalscale;
30 Vector quadsquare:: camerapos;
31 quadsquare*quadsquare::neighbor[4] = {NULL, NULL, NULL, NULL};
35 unsigned int half = 1<<pcd.
Level;
37 v[0].i = pcd.
xorg+half;
38 v[0].k = pcd.
zorg+half;
39 v[1].i = pcd.
xorg+half*2;
40 v[1].k = pcd.
zorg+half;
41 v[2].i = pcd.
xorg+half;
44 v[3].k = pcd.
zorg+half;
45 v[4].i = pcd.
xorg+half;
46 v[4].k = pcd.
zorg+half*2;
47 for (
unsigned int i = 0;
i < 5;
i++) {
73 res[0].
SetTex( 0.25*( ( ( (
float) in[0].Rem )+in[1].Rem+in[2].Rem+in[3].Rem )/256.+in[0].Tex+in[1].Tex+in[2].Tex+in[3].Tex ) );
74 res[1].
SetTex( 0.5*( ( ( (
float) in[0].Rem )+in[3].Rem )/256.+(in[3].Tex)+in[0].Tex ) );
75 res[2].
SetTex( 0.5*( ( ( (
float) in[0].Rem )+in[1].Rem )/256.+(in[0].Tex)+in[1].Tex ) );
76 res[3].
SetTex( 0.5*( ( ( (
float) in[1].Rem )+in[2].Rem )/256.+(in[1].Tex)+in[2].Tex ) );
77 res[4].
SetTex( 0.5*( ( ( (
float) in[2].Rem )+in[3].Rem )/256.+(in[2].Tex)+in[3].Tex ) );
93 res[0].
Y = (
unsigned short) ( 0.25*( ( (
float) in[0].
Y )+in[1].Y+in[2].Y+in[3].Y ) );
94 res[1].
Y = (
unsigned short) ( 0.5*( ( (
float) in[3].Y )+in[0].
Y ) );
95 res[2].
Y = (
unsigned short) ( 0.5*( ( (
float) in[0].
Y )+in[1].Y ) );
96 res[3].
Y = (
unsigned short) ( 0.5*( ( (
float) in[1].
Y )+in[2].Y ) );
97 res[4].
Y = (
unsigned short) ( 0.5*( ( (
float) in[2].
Y )+in[3].Y ) );
109 for (i = 0; i < 4; i++)
112 for (i = 0; i < 2; i++)
117 for (i = 0; i < 2; i++)
119 for (i = 0; i < 4; i++)
122 (
unsigned short) (fabs( (
double) ( (
Vertex[0].
Y
126 for (i = 1; i < 4; i++) {
128 if (y <
MinY)
MinY = (
unsigned short) y;
129 if (y >
MaxY)
MaxY = (
unsigned short) y;
145 for (i = 0; i < 5; i++) {
147 if ( unusedvertices->size() ) {
148 (*vertexs)[unusedvertices->back()] = v[i];
150 unusedvertices->pop_back();
153 if ( (*VertexCount)+1 >= (*VertexAllocated) ) {
154 (*VertexAllocated) *= 2;
155 (*vertexs) = (
GFXVertex*) realloc( (*vertexs), (*VertexAllocated)*
sizeof (
GFXVertex) );
157 (*vertexs)[*VertexCount] = v[i];
161 SetVertices( *vertexs, *pcd );
170 for (i = 0; i < 5; i++)
172 for (i = 0; i < 4; i++) {
198 for (
int i = 0; i < 4; i++)
209 int half = 1<<cd.
Level;
210 float lx = (x-cd.
xorg)/
float(half);
211 float lz = (z-cd.
zorg)/
float(half);
212 int ix = (
int) floor( lx );
213 int iz = (
int) floor( lz );
215 if (ix < 0)
return -FLT_MAX;
216 if (ix > 1)
return -FLT_MAX;
217 if (iz < 0)
return -FLT_MAX;
218 if (iz > 1)
return -FLT_MAX;
220 int index = ix^(iz^1)+(iz<<1);
224 SetupCornerData( &q, cd, index );
234 float s00, s01, s10, s11;
263 normal = (
Vector( 0, s10-s00, half ) ).Cross(
Vector( half, s01-s00, 0 ) );
264 return (s00*(1-lx)+s01*lx)*(1-lz)+(s10*(1-lx)+s11*lx)*lz;
276 return neighbor[dir];
280 bool SameParent = ( (dir-cd.
ChildIndex)&2 ) ?
true :
false;
285 if (p == 0)
return 0;
299 if (cd.
Parent == 0)
return NULL;
303 bool SameParent = ( (dir-cd.
ChildIndex)&2 ) ?
true :
false;
308 if (p == 0)
return 0;
316 Tex = (
unsigned char) t;
317 Rem = (
unsigned char) ( (t-
Tex)*256 );
326 unsigned int *VertexCount,
328 std::vector< unsigned int > *unvert,
330 std::vector< TerrainTexture > *tex,
334 normalscale = NormScale;
335 neighbor[0] = neighbors[0];
336 neighbor[1] = neighbors[1];
337 neighbor[2] = neighbors[2];
338 neighbor[3] = neighbors[3];
339 if (quadsquare::blendVertices == NULL) {
343 quadsquare::VertexAllocated = VertexAllocated;
344 quadsquare::VertexCount = VertexCount;
345 quadsquare::vertices = vertices;
346 quadsquare::unusedvertices = unvert;
347 nonlinear_trans = nlt;
349 if ( indices.size() < tex->size() )
350 while ( indices.size() < tex->size() )
359 memset( texturelookup, 0,
sizeof (
unsigned char)*256 );
360 for (i = 0; i < textures->size(); i++)
361 texturelookup[(*textures)[i].color] = i;
371 int BlockSize = 2<<cd.
Level;
381 int half = 1<<cd.
Level;
383 for (i = 0; i < 4; i++) {
385 SetupCornerData( &q, cd, i );
413 for (i = 0; i < 5; i++) {
428 SetVertices( vertexs, cd );
432 for (i = 0; i < 4; i++)
438 if (
Dirty) SetStatic( cd );
452 int ix = (
x-XOrigin)>>Scale;
453 int iz = (
z-ZOrigin)>>Scale;
454 int mask = (1<<Scale)-1;
455 int rx = (
x-XOrigin)&mask;
456 int rz = (
z-ZOrigin)&mask;
463 if ( ix >= (
int) (XSize-1) ) {
471 if ( iz >= (
int) (ZSize-1) ) {
475 float fx =
float(rx)/(mask+1);
476 float fz =
float(rz)/(mask+1);
477 float s00 = Data[ix+iz*RowWidth];
478 float s01 = Data[(ixpp)+iz*RowWidth];
479 float s10 = Data[ix+(izpp)*RowWidth];
480 float s11 = Data[(ixpp)+(izpp)*RowWidth];
481 float t00 = texturelookup[terrainmap[ix+iz*RowWidth]];
482 float t01 = texturelookup[terrainmap[(ixpp)+iz*RowWidth]];
483 float t10 = texturelookup[terrainmap[ix+(izpp)*RowWidth]];
484 float t11 = texturelookup[terrainmap[(ixpp)+(izpp)*RowWidth]];
485 texture = (t00*(1-fx)+t01*fx)*(1-fz)
486 +(t10*(1-fx)+t11*fx)*fz;
487 return (s00*(1-fx)+s01*fx)*(1-fz)
488 +(s10*(1-fx)+s11*fx)*fz;