normals and GL_TRIANGLE_STRIP

How do I generate normals from the vertexes below?:

glBegin(GL_TRIANGLE_STRIP);
fVertexes[0][0] = (i+1-fSize/2)/2;
fVertexes[0][1] = m_fWater[i+1][j+1]-2;
fVertexes[0][2] = (j+1-fSize)/2;
fVertexes[1][0] = (i-fSize/2)/2;
fVertexes[1][1] = m_fWater[i][j+1]-2;
fVertexes[1][2] = (j+1-fSize)/2;
fVertexes[2][0] = (i+1-fSize/2)/2;
fVertexes[2][1] = m_fWater[i+1][j]-2;
fVertexes[2][2] = (j-fSize)/2;
fVertexes[3][0] = (i-fSize/2)/2;
fVertexes[3][1] = m_fWater[i][j]-2;
fVertexes[3][2] = (j-fSize)/2;

glTexCoord2f(m_fTransWaterX+tx+td, m_fTransWaterZ+ty+td);
glVertex3f(fVertexes[0][0],fVertexes[0][1],fVertexes[0][2]);
glTexCoord2f(m_fTransWaterX+tx, m_fTransWaterZ+ty+td);
glVertex3f(fVertexes[1][0],fVertexes[1][1],fVertexes[1][2]);
glTexCoord2f(m_fTransWaterX+tx+td, m_fTransWaterZ+ty);
glVertex3f(fVertexes[2][0],fVertexes[2][1],fVertexes[2][2]);
glTexCoord2f(m_fTransWaterX+tx, m_fTransWaterZ+ty);
glVertex3f(fVertexes[3][0],fVertexes[3][1],fVertexes[3][2]);
glEnd();

[This message has been edited by dcd (edited 02-06-2003).]

This is a heightmap, right?

To get a normal of vertex[x, z], make a vector from vertex[x-1, z] to vertex[x+1, z], and another vector from vertex[x, z-1] to vertex[x, z+1]. The normal is the normalized cross product of these two vectors.

-Ilkka

Actually it is just a water texture with a water algorithm applied to the y axis. I have a calculateNormals() function that takes 3 vertices, but I don’t think it will work in this case. What I am doing is creating a triangle strip out of two triangles out of 4 vertices like:

2 1
|\ |
|
|
4 3

Does what you proposed still work for this scenario? Or do I have to calculate the normal for each triangle and then average them?

Thanks for your help.

[This message has been edited by dcd (edited 02-06-2003).]

So in fact it is a heightmap, when you think of it. Yes, this will work with it too.

Calculating normals by averaging face normals isn’t an absolute solution you should use everywhere. I kept doing it for years, but it actually gives quite bad results sometimes. It’s just a general technique that can be used with arbitary models. For heightmaps you don’t need it.

-Ilkka