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

The following examples show how to use com.jme3.math.FastMath#abs() . 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: PerspectiveLodCalculator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This computes the "C" value in the geomipmapping paper.
 * See section "2.3.1.2 Pre-calculating d"
 * 
 * @param cam
 * @param pixelLimit
 * @return
 */
private float getCameraConstant(Camera cam, float pixelLimit){
    float n = cam.getFrustumNear();
    float t = FastMath.abs(cam.getFrustumTop());
    float A = n / t;
    float v_res = cam.getHeight();
    float T = (2f * pixelLimit) / v_res;
    return A / T;
}
 
Example 2
Source File: PerspectiveLodCalculator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This computes the "C" value in the geomipmapping paper.
 * See section "2.3.1.2 Pre-calculating d"
 * 
 * @param cam
 * @param pixelLimit
 * @return
 */
private float getCameraConstant(Camera cam, float pixelLimit){
    float n = cam.getFrustumNear();
    float t = FastMath.abs(cam.getFrustumTop());
    float A = n / t;
    float v_res = cam.getHeight();
    float T = (2f * pixelLimit) / v_res;
    return A / T;
}
 
Example 3
Source File: AndroidAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void update(float tpf) {
    float distance;
    float volume;

    // Loop over all mediaplayers
    for (AudioNode src : musicPlaying.keySet()) {

        MediaPlayer mp = musicPlaying.get(src);
        {
            // Calc the distance to the listener
            distanceVector.set(listenerPosition);
            distanceVector.subtractLocal(src.getLocalTranslation());
            distance = FastMath.abs(distanceVector.length());

            if (distance < src.getRefDistance()) {
                distance = src.getRefDistance();
            }
            if (distance > src.getMaxDistance()) {
                distance = src.getMaxDistance();
            }
            volume = src.getRefDistance() / distance;

            AndroidAudioData audioData = (AndroidAudioData) src.getAudioData();

            if (FastMath.abs(audioData.getCurrentVolume() - volume) > FastMath.FLT_EPSILON) {
                // Left / Right channel get the same volume by now, only positional
                mp.setVolume(volume, volume);

                audioData.setCurrentVolume(volume);
            }


        }
    }
}
 
Example 4
Source File: NoiseGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public float execute(float x, float y, float z, float e) {
    x = FastMath.abs(x);
    y = FastMath.abs(y);
    z = FastMath.abs(z);
    float t = x > y ? x : y;
    return z > t ? z : t;
}
 
Example 5
Source File: NoiseGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public float execute(MusgraveData musgraveData, float x, float y, float z) {
    float result, signal, weight;
    float pwHL = (float) Math.pow(musgraveData.lacunarity, -musgraveData.h);
    float pwr = pwHL;

    NoiseFunction abstractNoiseFunc = noiseFunctions.get(Integer.valueOf(musgraveData.noisebasis));
    if (abstractNoiseFunc == null) {
        abstractNoiseFunc = noiseFunctions.get(Integer.valueOf(0));
    }

    signal = musgraveData.offset - FastMath.abs(abstractNoiseFunc.executeSigned(x, y, z));
    signal *= signal;
    result = signal;
    weight = 1.0f;

    for (int i = 1; i < (int) musgraveData.octaves; ++i) {
        x *= musgraveData.lacunarity;
        y *= musgraveData.lacunarity;
        z *= musgraveData.lacunarity;
        weight = signal * musgraveData.gain;
        if (weight > 1.0f) {
            weight = 1.0f;
        } else if (weight < 0.0) {
            weight = 0.0f;
        }
        signal = musgraveData.offset - FastMath.abs(abstractNoiseFunc.executeSigned(x, y, z));
        signal *= signal;
        signal *= weight;
        result += signal * pwr;
        pwr *= pwHL;
    }
    return result;
}
 
Example 6
Source File: NoiseGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static float turbulence(float x, float y, float z, float noiseSize, int noiseDepth, int noiseBasis, boolean isHard) {
    NoiseFunction abstractNoiseFunc = noiseFunctions.get(Integer.valueOf(noiseBasis));
    if (abstractNoiseFunc == null) {
        abstractNoiseFunc = noiseFunctions.get(0);
        noiseBasis = 0;
    }

    if (noiseBasis == 0) {
        ++x;
        ++y;
        ++z;
    }
    if (noiseSize != 0.0) {
        noiseSize = 1.0f / noiseSize;
        x *= noiseSize;
        y *= noiseSize;
        z *= noiseSize;
    }

    float sum = 0, t, amp = 1, fscale = 1;
    for (int i = 0; i <= noiseDepth; ++i, amp *= 0.5, fscale *= 2) {
        t = abstractNoiseFunc.execute(fscale * x, fscale * y, fscale * z);
        if (isHard) {
            t = FastMath.abs(2.0f * t - 1.0f);
        }
        sum += t * amp;
    }

    sum *= (float) (1 << noiseDepth) / (float) ((1 << noiseDepth + 1) - 1);
    return sum;
}
 
Example 7
Source File: TangentBinormalGenerator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean approxEqual(Vector3f u, Vector3f v) {
    float tolerance = 1E-4f;
    return (FastMath.abs(u.x - v.x) < tolerance) &&
           (FastMath.abs(u.y - v.y) < tolerance) &&
           (FastMath.abs(u.z - v.z) < tolerance);
}
 
Example 8
Source File: TangentBinormalGenerator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean approxEqual(Vector2f u, Vector2f v) {
    float tolerance = 1E-4f;
    return (FastMath.abs(u.x - v.x) < tolerance) &&
           (FastMath.abs(u.y - v.y) < tolerance);
}
 
Example 9
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 4 votes vote down vote up
private static boolean approxEqual(Vector3f u, Vector3f v) {
	float tolerance = 1E-4f;
	return (FastMath.abs(u.x - v.x) < tolerance) && (FastMath.abs(u.y - v.y) < tolerance) && (FastMath.abs(u.z - v.z) < tolerance);
}
 
Example 10
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 4 votes vote down vote up
private static boolean approxEqual(Vector2f u, Vector2f v) {
	float tolerance = 1E-4f;
	return (FastMath.abs(u.x - v.x) < tolerance) && (FastMath.abs(u.y - v.y) < tolerance);
}
 
Example 11
Source File: TextureGeneratorWood.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public float execute(float x) {
    return 1.0f - 2.0f * FastMath.abs((float) Math.floor(x * FastMath.INV_TWO_PI + 0.5f) - x * FastMath.INV_TWO_PI);
}
 
Example 12
Source File: NoiseGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public float execute(float x, float y, float z, float e) {
    return FastMath.abs(x) + FastMath.abs(y) + FastMath.abs(z);
}
 
Example 13
Source File: TextureGeneratorVoronoi.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void getPixel(TexturePixel pixel, float x, float y, float z) {
    // for voronoi we need to widen the range a little
    NoiseGenerator.NoiseFunctions.voronoi(x * 4, y * 4, z * 4, da, pa, mexp, distanceType);
    pixel.intensity = weightSum * FastMath.abs(voronoiWeights[0] * da[0] + voronoiWeights[1] * da[1] + voronoiWeights[2] * da[2] + voronoiWeights[3] * da[3]);
    if (pixel.intensity > 1.0f) {
        pixel.intensity = 1.0f;
    } else if (pixel.intensity < 0.0f) {
        pixel.intensity = 0.0f;
    }

    if (colorBand != null) {// colorband ALWAYS goes first and covers the color (if set)
        int colorbandIndex = (int) (pixel.intensity * 1000.0f);
        pixel.red = colorBand[colorbandIndex][0];
        pixel.green = colorBand[colorbandIndex][1];
        pixel.blue = colorBand[colorbandIndex][2];
        pixel.alpha = colorBand[colorbandIndex][3];
    } else if (voronoiColorType != 0) {
        pixel.red = pixel.green = pixel.blue = 0.0f;
        pixel.alpha = 1.0f;
        for (int m = 0; m < 12; m += 3) {
            float weight = voronoiWeights[m / 3];
            NoiseMath.hash((int) pa[m], (int) pa[m + 1], (int) pa[m + 2], hashPoint);
            pixel.red += weight * hashPoint[0];
            pixel.green += weight * hashPoint[1];
            pixel.blue += weight * hashPoint[2];
        }
        if (voronoiColorType >= 2) {
            float t1 = (da[1] - da[0]) * 10.0f;
            if (t1 > 1.0f) {
                t1 = 1.0f;
            }
            if (voronoiColorType == 3) {
                t1 *= pixel.intensity;
            } else {
                t1 *= weightSum;
            }
            pixel.red *= t1;
            pixel.green *= t1;
            pixel.blue *= t1;
        } else {
            pixel.red *= weightSum;
            pixel.green *= weightSum;
            pixel.blue *= weightSum;
        }
    }

    if (voronoiColorType != 0 || colorBand != null) {
        this.applyBrightnessAndContrast(bacd, pixel);
    } else {
        this.applyBrightnessAndContrast(pixel, bacd.contrast, bacd.brightness);
    }
}