
Finally got normals working for the height map. Brad helped me a ton with the math, thanks brad :). After making sure I had the right points its was pretty simple.
Here is an example to calculate normals for a grid in OpenFrameworks. Obviously this can be applied to any other language.

The image above we have four points on a plane. We need three of those points:
ofxVec3f p2(x2, y2, z2);
ofxVec3f p3(x3, y3, z3);
We now need a vector from p1 to p2 and p1 to p3.
ofxVec3f v2 = p1 - p3;
We need the cross product of v1 and v2. This will give us our normal vector. Next we normalize that vector scale it and add p1.
normalVec.normalize();
normalVec *= 50.0;
normalVec += p1;
Now render from p1 to normal vector.
glVertex3f(normalVec.x, normalVec.y, normalVec.z);
glVertex3f(p1.x, p1.y, p1.z);
September 22nd, 2009 at 11:50 pm
Sorry I’m not so clear with those math stuff…
But you say “a vector from p1 to p2″, isn’t it should be p2 – p1 instead of p1 – p2?