[ODE] Methods of handling terrain

Sergey Beloshitsky sergey at rostok-games.com.ua
Fri Feb 18 18:44:47 MST 2005


here is my code i have 1024x1024 points
trimesh modelled terrain works good for me
// for making terrain as trimesh but not as TerrainY;
const unsigned int terrain_size = 1024; // 1024 - is heightmap size
const unsigned int num_nodes = terrain_size/4;
const unsigned int step_size = terrain_size/num_nodes;

Vector3* vBuffer = tw_new Vector3[num_nodes*num_nodes];
unsigned int* iBuffer = tw_new unsigned 
int[(num_nodes-1)*(num_nodes-1)*2*3]; /// num cells(points-1) for 2 
triangles of 3 points

size_t numPoints = num_nodes*num_nodes;
for(int y=0;y<num_nodes;y++)
for(int x=0;x<num_nodes;x++)
{
vBuffer[y*num_nodes+x].x = (int)(x*step_size-512);
vBuffer[y*num_nodes+x].y = 
m_pTerrain->GetLandscapeHeight((int)(x*step_size-512),(int)(y*step_size-512));
vBuffer[y*num_nodes+x].z = (int)(y*step_size-512);
}
i=0;
dVector3 v1,v2,norm;
for(int y=0;y<num_nodes-1;y++)
for(int x=0;x<num_nodes-1;x++)
{
iBuffer[i++] = (y+1)*num_nodes+x;
iBuffer[i++] = y*num_nodes+x+1;
iBuffer[i++] = y*num_nodes+x;

iBuffer[i++] = (y+1)*num_nodes+x;
iBuffer[i++] = (y+1)*num_nodes+x+1;
iBuffer[i++] = y*num_nodes+x+1;
}

-- 
Шукай в телефоні мій слід...



More information about the ODE mailing list