OK, so now ive got my water texture rendering properly and i’ve fixed a few other issues, Im trying to enable lighting on my scene.
Ive successfully enabled it, and set some default light properties which arent great (but should be ok for now).
So first thing is im trying to create some normals for my heightmap, at the moment ive calcualted one normal for one iteration of my triangle strip loop. Im getting some ugly effects
This is probably becuase Im only doing one normal when i need 3 or 4 for my 3 triangle strips.
heres my heightmap rendering code so far:
for (int mapZ = 1; mapZ < MapHeight; mapZ+=averageSmoother)
{
if (mapX>1 & mapZ>=1 & mapX<=MapWidth-5 & mapZ<=MapHeight-5)
{
gl.glBegin(gl.GL_TRIANGLE_STRIP);
vertexHeight = BMPHeightMapStore[mapX][mapZ];
//Vector A
vectA.x=mapX-mapX;
vectA.y=vertexHeight-(BMPHeightMapStore[mapX][mapZ+averageSmoother]); //current v height - next v height
vectA.z=mapZ-(mapZ+averageSmoother);
//Vector B
vectB.x=mapX-mapX;
vectB.y=(BMPHeightMapStore[mapX][mapZ+averageSmoother])-(BMPHeightMapStore[mapX+averageSmoother][mapZ]);
vectB.z=(float) mapZ+averageSmoother-mapZ;
//Calculate normal vector from cross product of A & B
Vector3f.cross(vectNormal, vectA, vectB);
gl.glNormal3f(vectNormal.x, vectNormal.y, vectNormal.z);
gl.glTexCoord2f((float)mapX / MapWidth, (float)mapZ / MapHeight);
gl.glVertex3f((float)mapX,vertexHeight,(float)mapZ);
vertexHeight = BMPHeightMapStore[mapX][mapZ+averageSmoother];
gl.glTexCoord2f((float)mapX / MapWidth, (float)(mapZ+averageSmoother) / MapHeight);
gl.glVertex3f((float) mapX,vertexHeight,(float) mapZ+averageSmoother);
vertexHeight = BMPHeightMapStore[mapX+averageSmoother][mapZ];
gl.glTexCoord2f((float)(mapX+averageSmoother) / MapWidth, (float)mapZ / MapHeight);
gl.glVertex3f((float) mapX+averageSmoother,vertexHeight,(float)mapZ);
vertexHeight = BMPHeightMapStore[mapX+averageSmoother][mapZ+averageSmoother];
gl.glTexCoord2f((float)(mapX+averageSmoother) / MapWidth, (float)(mapZ+averageSmoother) / MapHeight);
gl.glVertex3f((float)mapX+averageSmoother,vertexHeight,(float)mapZ+averageSmoother);
gl.glEnd();
// gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT);
// gl.glColor3f(0.0f, 1.0f, 0.0f);
// gl.glBegin(GL.GL_LINES);
// gl.glVertex3f(vectNormal.x, vectNormal.y, vectNormal.z);
// gl.glVertex3f((vectNormal.x)+2, (vectNormal.y)+2, (vectNormal.z)+2);
// gl.glEnd();
// gl.glPopAttrib();
}
}
}
As you can see I was also trying to draw a line along the normal so I could see if they were pointing in the correct direction, however this didnt work (no visible lines :()
What I really want to know now is :
a) Is my code for calculating one normal ok?
b1) If I create normals for all verticies will the ugly square shading sort itsself out - or am I stuck with it because of the resolution of my mesh?
b2) If it will help - To create normals for the other 3(?) verticities i assume I can just use the next 2 verticies listed (i.e instead of vertex 0 and 1, i can use 1 and 2, and then 2 and 3?) is this correct?
Normals do my brain in!
Thanks in advance
Regards
Wills