Java Code Examples for com.jme3.math.FastMath#sign()

The following examples show how to use com.jme3.math.FastMath#sign() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FaultHeightMap.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void addCircleFault(float[][] tempBuffer, Random random, float faultHeight, float range) {
    float radius = random.nextFloat() * (maxRadius - minRadius) + minRadius;
    int intRadius = (int) FastMath.floor(radius);
    // Allox circle center to be out of map if not by more than radius.
    // Unlucky cases will put them in the far corner, with the circle
    // entirely outside heightmap
    int x = random.nextInt(size + 2 * intRadius) - intRadius;
    int y = random.nextInt(size + 2 * intRadius) - intRadius;

    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
            float dist;
            if (i != x || j != y) {
                int dx = i - x;
                int dy = j - y;
                float dmag = FastMath.sqrt(FastMath.sqr(dx) + FastMath.sqr(dy));
                float rx = x + dx / dmag * radius;
                float ry = y + dy / dmag * radius;
                dist = FastMath.sign(dmag - radius)
                    * FastMath.sqrt(FastMath.sqr(i - rx) + FastMath.sqr(j - ry));
            } else {
                dist = 0;
            }
            tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range);
        }
    }
}
 
Example 2
Source File: FaultHeightMap.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void addCircleFault(float[][] tempBuffer, Random random, float faultHeight, float range) {
    float radius = random.nextFloat() * (maxRadius - minRadius) + minRadius;
    int intRadius = (int) FastMath.floor(radius);
    // Allox circle center to be out of map if not by more than radius.
    // Unlucky cases will put them in the far corner, with the circle
    // entirely outside heightmap
    int x = random.nextInt(size + 2 * intRadius) - intRadius;
    int y = random.nextInt(size + 2 * intRadius) - intRadius;

    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
            float dist;
            if (i != x || j != y) {
                int dx = i - x;
                int dy = j - y;
                float dmag = FastMath.sqrt(FastMath.sqr(dx) + FastMath.sqr(dy));
                float rx = x + dx / dmag * radius;
                float ry = y + dy / dmag * radius;
                dist = FastMath.sign(dmag - radius)
                    * FastMath.sqrt(FastMath.sqr(i - rx) + FastMath.sqr(j - ry));
            } else {
                dist = 0;
            }
            tempBuffer[i][j] += calcHeight(dist, random, faultHeight, range);
        }
    }
}