public Vector3f getSurfaceNormal(float x, float z, Vector3f store) { x /= stepScale.x; z /= stepScale.z; float col = FastMath.floor(x); float row = FastMath.floor(z);  if (col < 0 || row < 0 || col >= size - 1 || row >= size - 1) { return null; } float intOnX = x - col, intOnZ = z - row;  if (store == null) store = new Vector3f();  Vector3f topLeft = store, topRight = calcVec1, bottomLeft = calcVec2, bottomRight = calcVec3;  int focalSpot = (int) (col + row * size);    BufferUtils.populateFromBuffer(topLeft, normBuf, focalSpot);   BufferUtils.populateFromBuffer(topRight, normBuf, focalSpot + 1);   BufferUtils.populateFromBuffer(bottomLeft, normBuf, focalSpot + size);    BufferUtils.populateFromBuffer(bottomRight, normBuf, focalSpot + size + 1);   topLeft.interpolate(topRight, intOnX); bottomLeft.interpolate(bottomRight, intOnX); topLeft.interpolate(bottomLeft, intOnZ); return topLeft.normalizeLocal(); }
public Vector3f getSurfaceNormal(Vector2f position, Vector3f store) { return getSurfaceNormal(position.x, position.y, store); }
    public Vector3f getSurfaceNormal(float x, float z, Vector3f store) {        x /= stepScale.x;        z /= stepScale.z;        float col = FastMath.floor(x);        float row = FastMath.floor(z);        if (col < 0 || row < 0 || col >= size - 1 || row >= size - 1) { return null; }        float intOnX = x - col, intOnZ = z - row;        if (store == null) store = new Vector3f();        Vector3f topLeft = store, topRight = calcVec1, bottomLeft = calcVec2, bottomRight = calcVec3;        int focalSpot = (int) (col + row * size);        // find the heightmap point closest to this position (but will always        // be to the left ( < x) and above (< z) of the spot.        BufferUtils.populateFromBuffer(topLeft, normBuf, focalSpot);        // now find the next point to the right of topLeft's position...        BufferUtils.populateFromBuffer(topRight, normBuf, focalSpot + 1);        // now find the next point below topLeft's position...        BufferUtils.populateFromBuffer(bottomLeft, normBuf, focalSpot + size);        // now find the next point below and to the right of topLeft's        // position...        BufferUtils.populateFromBuffer(bottomRight, normBuf, focalSpot + size                + 1);        // Use linear interpolation to find the height.        topLeft.interpolate(topRight, intOnX);        bottomLeft.interpolate(bottomRight, intOnX);        topLeft.interpolate(bottomLeft, intOnZ);        return topLeft.normalizeLocal();    }