PDA

View Full Version : Calculating normals for heightmap



Exempt
08-17-2013, 05:12 PM
Edit: I have this solved now. :) If anyone is interested...
vector3d class or more or less float x, y, z with a few functions to help deal with vectors... which are hard to understand but I found a really great site to help explain this http://www.fundza.com/vectors/normalize/index.html
This looks pretty decent I think.
http://i42.tinypic.com/2u9honr.png


float vector3d::length()
{
return sqrt(x*x + y*y + z*z);
}

void vector3d::normalize()
{
float len = length();
if(len != 0)
{
x /= len;
y /= len;
z /= len;
}
}

Output

Points
2 0 0
2 0 1
3 0 0
Normals
1 0 0
0.894427 0 0.447214
1 0 0

Points
3 0 0
2 0 1
3 0 1
Normals
1 0 0
0.894427 0 0.447214
0.948683 0 0.316228

Points
3 0 0
3 0 1
4 0 0
Normals
1 0 0
0.948683 0 0.316228
1 0 0


...Well crap, I have the normals now what.. lol. Guess I'll have to figure out how to combine this with the rest of the data... then it's textures next I think...I hope, I wanna see some nice grassy hills and a mountain... then a tree.