4、地形排列的边界拼接算法
z = -1.f * (float) (tile-1);
for (i=0; i<tile; i++) {
x = -1.f * (float) (tile-1);
for (j=0; j<tile; j++) {
glPushMatrix ();
glTranslatef (x, 0.f, z);
draw2DFractArrayAsLines (surfFA, size);
glPopMatrix ();
x += 2.f;
}
z += 2.f;
} 5、地形绘制
bool RenderScene()
{
int size = 1 << iterations;
GLfloat black[4] = {0.f, 0.f, 0.f, 1.f};
GLfloat white[4] = {1.f, 1.f, 1.f, 1.f};
// Handle inverted colors.
if (colorInvert)
glClearColor (black[0], black[1], black[2], black[3]);
else
glClearColor (white[0], white[1], white[2], white[3]);
// Handle non line mode renderMode settings.
if (renderMode == twoDR_clouds)
return (renderCloudMap ());
else if (renderMode == twoDR_teximage)
return (renderTeximageMap ());
else if (renderMode == twoDR_rendered)
return (renderFullImage ());
// Shouldn''''''''''''''''''''''''''''''''t take too long, unless drawing huge
// AA scenes, but what the heck...
CWaitCursor hourglass;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
if (arrayIs2D)
// Needs to be identical to the same call in renderFullScene.
gluPerspective (60., aspectRatio, .1, 15.0);
else
glOrtho (-aspectRatio, aspectRatio, -1., 1., 1., -1.);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
if (arrayIs2D) {
glTranslatef (0.f, yTrans, zTrans);
glRotatef (yRot, 0.f, 1.f, 0.f);
}
glPushAttrib (0xffffffff);
glDisable (GL_DEPTH_TEST);
glDisable (GL_LIGHTING);
if (colorInvert)
glColor4fv (white);
else
glColor4fv (black);
if (aaLines) {
glEnable (GL_LINE_SMOOTH);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else {
glDisable (GL_LINE_SMOOTH);
glDisable (GL_BLEND);
}
glClear (GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
if (arrayIs2D) {
float x, z;
UINT i, j;
// validate surface
if (surfFA && surfFAdirty) {
freeFractArray (surfFA);
surfFA = NULL;
}
if (!surfFA) {
surfFA = alloc2DFractArray (size);
if (surfFA==NULL) return (FALSE);
fill2DFractArray (surfFA, size, randomSeed,
DEF_HEIGHT_SCALE, surfaceH);
surfFAdirty = FALSE;
}
z = -1.f * (float) (tile-1);
for (i=0; i<tile; i++) {
x = -1.f * (float) (tile-1);
for (j=0; j<tile; j++) {
glPushMatrix ();
glTranslatef (x, 0.f, z);
draw2DFractArrayAsLines (surfFA, size);
glPopMatrix ();
x += 2.f;
}
z += 2.f;
}
}
else {
float x;
UINT i;
float *fa;
// Always validate and free 1D array.
// We won''''''''''''''''''''''''''''''''t be doing any realtime transformations on it.
fa = alloc1DFractArray (size);
if (fa==NULL) return (FALSE);
fill1DFractArray (fa, size, randomSeed,
DEF_HEIGHT_SCALE, surfaceH);
x = -1.f * (float) (tile-1);
for (i=0; i<tile; i++) {
glPushMatrix ();
glTranslatef (x, 0.f, 0.f);
draw1DFractArrayAsLines (fa, size);
glPopMatrix ();
x += 2.f;
}
freeFractArray (fa);
}
glFlush();
glPopAttrib ();
return (TRUE);
}