Question
Change the program to display 16 identical heightmaps arranged in a 4 x 4 grid. The edges of the heightmaps should be side by side
Change the program to display 16 identical heightmaps arranged in a 4 x 4 grid. The edges of the heightmaps should be side by side in X and Z coordinates. However, they will not touch in the Y direction because the heights will be different.
C++
The below code is what I have already, i am just not too sure how to make it show the 16 identical heightmaps arranged in a 4x4 grid. I know it has to do with the squares on the height map, but i am very confused.
const int HEIGHTMAP_SIZE = 12; float heights[HEIGHTMAP_SIZE + 1][HEIGHTMAP_SIZE + 1];
initDisplay(); for (unsigned int x = 0; x <= HEIGHTMAP_SIZE; x++) { for (unsigned int z = 0; z <= HEIGHTMAP_SIZE; z++) { heights[x][z] = (x % 2) * 0.5f - z * z * 0.05f; } } //TextureManager::activate("rainbow.bmp"); initHeightmapDisplayList();
void initHeightmapHeights() { for (unsigned int x0 = 0; x0 < HEIGHTMAP_SIZE; x0++) { unsigned int x1 = x0 + 1; float tex_x0 = (float)(x0) / HEIGHTMAP_SIZE; float tex_x1 = (float)(x1) / HEIGHTMAP_SIZE; glBegin(GL_TRIANGLE_STRIP); for (unsigned int z = 0; z <= HEIGHTMAP_SIZE; z++) { float tex_z = (float)(z) / HEIGHTMAP_SIZE; glTexCoord2d(tex_x1, tex_z); glVertex3d(x1, heights[x1][z], z); glTexCoord2d(tex_x0, tex_z); glVertex3d(x0, heights[x0][z], z); } glEnd(); } }
void initHeightmapDisplayList() { heightmap_list.begin(); glEnable(GL_TEXTURE_2D); TextureManager::activate("ground.bmp"); glColor3d(1.0, 1.0, 1.0); initHeightmapHeights(); glDisable(GL_TEXTURE_2D); heightmap_list.end(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started