Non square terrain

Just realised it would have been better posted in the user code section.



The method for generating Normals is a bit long winded.

The technique is interesting though and was suggested to me by my friend Ono Sendai from Indigo renderer.



That is just take the cross product of the vertex above and below and the vertex left and right of the vertex needing a normal.

it's a very common technique and one i think is used in nvidias normalmapper etc.



since it's done on an axis aligned grid it can actually be simplified to:


public void generateNormals() {
   for (int i = width; i < heightData.length - width; i++) {
      final int z = i / width;
      final int x = i - z * width;

      int xHeight = xyHeightMapAccess(x - 1, z) - xyHeightMapAccess(x + 1, z);
      int zHeight = xyHeightMapAccess(x, z - 1) - xyHeightMapAccess(x, z + 1);

      normals[i] = new Vector3f(xHeight, 1.0f, zHeight).normalizeLocal();
   }
}



probably more than twice as fast.
not handling the edges specifically but you get the point...

Nice one Mr Coder.  :smiley:

But the code has bugs that i just found. So its retracted for now.

Just read my last post. I meant i found bugs in my code not yours :D.

hehehe phuuu good for me s  XD