About Cal Normal Vec in RacingGame's Landscape
When I was reading a RacingGame's source file which named Landscape.cs, I found myself puzzled by the following codes:
it's in Landscape's Construction, which is to Calculate the Normal Vectors for each Vertexs of the Landscape.
// Step 2: Calculate all edge vectors (for normals and tangents)
// This involves quite complicated optimizations and mathematics,
// hard to explain with just a comment. Read my book :D
Vector3 edge1 = pos - CalcLandscapePos( x, y + 1, heights );
Vector3 edge2 = pos - CalcLandscapePos( x + 1, y, heights );
Vector3 edge3 = pos - CalcLandscapePos( x - 1, y + 1, heights );
Vector3 edge4 = pos - CalcLandscapePos( x + 1, y + 1, heights );
Vector3 edge5 = pos - CalcLandscapePos( x - 1, y - 1, heights );
// Step 3: Calculate normal based on the edges (interpolate
// from 3 cross products we build from our edges).
vertices[index].normal = Vector3.Normalize(
Vector3.Cross( edge2, edge1 ) +
Vector3.Cross( edge4, edge3 ) +
Vector3.Cross( edge3, edge5 ) );
the Comment says: "This involves quite complicated optimizations and mathematics." But I found the sampling was dissymmetric and I couldn't see the mathematics base of this method.
the Comment also says: "Read my book". But I hadn't found any explain about this in "Professional XNA Game Programing". Is there an other book which explains this method?
I am a Chinese student, and I am writing something to explain the codes of RacingGame.(I hope that won't make me a pirate.) As a collage student, my experience is limited, but I like game developing and I already have my own game project which called "SmartTank".
if you see this topic, plz tell me how to find the answer. anybody who knows the answer plz let me know too. Thanks a lot.