MCPcopy Create free account
hub / github.com/SFML/SFML / computeNormal

Function computeNormal

examples/island/Island.cpp:224–236  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Compute a compressed representation of the surface normal based on the given coordinates, and the elevation of the 4 adjacent neighbours. ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

222///
223////////////////////////////////////////////////////////////
224sf::Vector2f computeNormal(float left, float right, float bottom, float top)
225{
226 const sf::Vector3f deltaX(1, 0, (std::pow(right, heightFlatten) - std::pow(left, heightFlatten)) * heightFactor);
227 const sf::Vector3f deltaY(0, 1, (std::pow(top, heightFlatten) - std::pow(bottom, heightFlatten)) * heightFactor);
228
229 sf::Vector3f crossProduct = deltaX.cross(deltaY);
230
231 // Scale cross product to make z component 1.0f so we can drop it
232 crossProduct /= crossProduct.z;
233
234 // Return "compressed" normal
235 return {crossProduct.x, crossProduct.y};
236}
237
238
239////////////////////////////////////////////////////////////

Callers 1

computeVertexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected