Triple Post! ... I am having a problem with the terrain clipping together. for some reason there are small gaps between the terrain.
CODE:
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include <iostream>
using namespace std;
int GetDist(int id)
{
float totx = pow(dbCameraPositionX()-dbObjectPositionX(id),2);
float totz = pow(dbCameraPositionZ()-dbObjectPositionZ(id),2);
return sqrt(totx+totz);
}
void GetLodDat(int HeightID, int imgSize)
{
// this function will create 16 low quality bitmaps and 16 high
// use these bmps to create terrain and save the mesh to load in game
dbLoadBitmap("map.bmp",HeightID);
int id = 1;
int low = imgSize/8;
int high = imgSize/4;
char file[20];
for(int y = 1; y< 5; y++)
{
int startx = 0;
int starty = 0;
for(int x = 1; x<5; x++)
{
//far
dbCreateBitmap((id-id)+1,low,low);
dbCopyBitmap(HeightID,high*(y-1),high*(x-1),high*y,high*x,id,0,0,low,low);
dbSetCurrentBitmap((id-id)+1);
dbGetImage(100+id,0,0,low,low);
sprintf(file,"terrain/l%i",id);
strcat(file,".bmp");
dbSaveImage(file,100+id);
//Close
dbDeleteBitmap((id-id)+1);
dbCreateBitmap((id-id)+1,high,high);
dbCopyBitmap(HeightID,high*(y-1),high*(x-1),high*y,high*x,(id-id)+1,0,0,high,high);
dbSetCurrentBitmap((id-id)+1);
dbGetImage(200+id,0,0,high,high);
sprintf(file,"terrain/h%i",id);
strcat(file,".bmp");
dbSaveImage(file,200+id);
file[0] = 0;
id++;
}
}
}
void BuildTerrainLod()
{
int id = 1;
char file[40];
for(int x= 1; x < 5; x++)
{
for(int y = 1; y< 5; y++)
{
sprintf(file,"terrain/h%i",id);
strcat(file,".bmp");
dbSetupTerrain();
dbMakeObjectTerrain(id);
dbSetTerrainHeightMap(id,file);
dbSetTerrainLight ( id, 0, -10, 0, 1, 1, 1, 0.5 ); // set the light
dbSetTerrainTexture ( id, 2200,2200 );
dbSetTerrainScale(id,1,0.25,1);
dbBuildTerrain(id);
dbSetObjectTexture(id,1,0);
//dbLoadObject(file,id);
//dbSetObjectLight(id,0);
//dbMakeObjectCube(id,50);
dbPositionObject(id,(x*128)-64,0,(-y*128)-64);
float dist = GetDist(id);
if(dist>128) dbExcludeObjectOn(id);
id++;
file[0] = 0;
}
}
}
void UpdateLod()
{
bool fara;
for(int id = 1; id < 17; id++)
{
float dist = GetDist(id);
if(dist<256)
{
dbExcludeObjectOff(id);
}
else dbExcludeObjectOn(id);
}
}
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDir("media\\");
dbSetDisplayMode(1600,900,32,1,4,0);
//GetLodDat(50,512);
//SaveMesh();
//dbSetCurrentBitmap(0);
dbLoadImage("grass.png",2200);
BuildTerrainLod();
dbPositionCamera(0,60,-75);
// our main loop
while ( LoopGDK ( ) )
{
dbPrint(dbGetTerrainXSize(1)*1.0);
dbControlCameraUsingArrowKeys(0,1,1);
UpdateLod();
// update the screen
dbSync ( );
}
// return back to windows
return;
}
I have also attached a picture to show the problem.