/////////////////////////////////////////////////////// Compute a compressed representation of the surface normal based on the given coordinates, and the elevation of the 4 adjacent neighbours. ///////////////////////////////////////////////////////
| 222 | /// |
| 223 | //////////////////////////////////////////////////////////// |
| 224 | sf::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 | //////////////////////////////////////////////////////////// |