Hey, so I'm currently working on a simple game that is 3D but seen only from the side with a slight angle (like "little big planet" or other similar games), where I need to generate basically a 2D Terrain (X and Y) but with a depth to it.
I've got it working for X and Y axis as a 2D terrain but I'm not sure how I can extend this to feature depth.
This is how I create my terrain:
this->vertices = new TexturedNormalVertex[TERRAIN_X * TERRAIN_Y];
this->indices = new int[(TERRAIN_X - 1) * (TERRAIN_Y - 1) * 6];
void Terrain::GenerateTerrain()
{
// Setup vertices
for(int x = 0; x < TERRAIN_X; x++)
{
for(int y = 0; y < TERRAIN_Y; y++)
{
float X = (float)x;
float Y = (float)y;
// HEIGHT
if(y > 0)
{
// RANDOMLY GENERATE THE TERRAIN SLOPE
srand((unsigned int)time(NULL));
float randomNumber1 = rand() % 3 + 0.0f;
srand((unsigned int)time(NULL));
float randomNumber2 = rand() % 7 + 1.0f;
srand((unsigned int)time(NULL));
float randomNumber3 = rand() % 10 + 2.0f;
float waveMagnitude = 20;
float waveLength = 20;
float offset = 0.0f;
float height = waveMagnitude / (randomNumber1 + 0.00001f) * sin(X / waveLength * randomNumber1 + randomNumber1 + 0.000001f);
height += waveMagnitude / randomNumber2 * sin(X / waveLength * randomNumber2 + randomNumber2);
height += waveMagnitude / randomNumber3 * sin(X / waveLength * randomNumber3 + randomNumber3);
Y = Y + (height + offset);
}
this->vertices[x + y * TERRAIN_X].pos = XMFLOAT3(X, Y, 1);
this->vertices[x + y * TERRAIN_X].texCoord = XMFLOAT2(X / TEXTURE_SCALING, Y / TEXTURE_SCALING);
this->vertices[x + y * TERRAIN_X].normal = XMFLOAT3(0, 0, -1);
this->vertices[x + y * TERRAIN_X].biTangent = XMFLOAT3(0, 0, 0);
this->vertices[x + y * TERRAIN_X].tangent = XMFLOAT3(0, 0, 0);
}
}
this->vertexCount = TERRAIN_X * TERRAIN_Y;
// Define terrain using indices
int counter = 0;
for(int y = 0; y < TERRAIN_Y - 1; y++)
{
for(int x = 0; x < TERRAIN_X - 1; x++)
{
int lowerLeft = x + y * TERRAIN_X;
int lowerRight = (x + 1) + y * TERRAIN_X;
int topLeft = x + (y + 1) * TERRAIN_X;
int topRight = (x + 1) + (y + 1) * TERRAIN_X;
indices[counter++] = topLeft;
indices[counter++] = lowerRight;
indices[counter++] = lowerLeft;
indices[counter++] = topLeft;
indices[counter++] = topRight;
indices[counter++] = lowerRight;
}
}
this->InitializeBuffer();
}