user3014884
user3014884

Reputation: 1

android open gl es 2.0 height map (pragmatic programmers) book

I'm relatively new to Open GL ES 2.0 for Android and have a question specifically about height maps. On page 239 it explains how to Generate indices from a bitmap image. page 12 of this PDF http://media.pragprog.com/titles/kbogla/heightmap.pdf. Why is it necessary to subtract one from width and height. I have looked through google, read this page multiple times the example given is a 3x3 heightmap where (width - 1) * (height - 1) * 2 * 3 = 24 elements <- this is stumbling me.

Upvotes: 0

Views: 229

Answers (1)

NigelK
NigelK

Reputation: 8480

Here's a representation of a 3 x 3 heightmap, having 9 vertices:

enter image description here

Every group of 4 vertices in the height map needs 2 triangles and each triangle needs 3 indices to define it, so 6 indices in total. I've illustrated that in the first group above.

As you can see, there are 4 of these groups to do, hence 6 x 4 = 24 indices in all. Hence the number of groups to index is (width -1) x (height -1) with 6 indices per group.

Upvotes: 1

Related Questions