Java Code Examples for com.jme3.math.Vector3f#minLocal()

The following examples show how to use com.jme3.math.Vector3f#minLocal() . 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: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){
    // applying gravity
    p.velocity.x -= gravity.x * tpf;
    p.velocity.y -= gravity.y * tpf;
    p.velocity.z -= gravity.z * tpf;
    temp.set(p.velocity).multLocal(tpf);
    p.position.addLocal(temp);

    // affecting color, size and angle
    float b = (p.startlife - p.life) / p.startlife;
    p.color.interpolateLocal(startColor, endColor, b);
    p.size = FastMath.interpolateLinear(b, startSize, endSize);
    p.angle += p.rotateSpeed * tpf;

    // Computing bounding volume
    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    if (!selectRandomImage) {
        p.imageIndex = (int) (b * imagesX * imagesY);
    }
}
 
Example 2
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Compute bounds from an array of points
 * @param pts
 * @param mat
 * @return a new BoundingBox
 */
public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) {
    Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
    Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
    TempVars vars = TempVars.get();
    Vector3f temp = vars.vect1;

    for (int i = 0; i < pts.length; i++) {
        float w = mat.multProj(pts[i], temp);

        temp.x /= w;
        temp.y /= w;
        // Why was this commented out?
        temp.z /= w;

        min.minLocal(temp);
        max.maxLocal(temp);
    }
    vars.release();
    Vector3f center = min.add(max).multLocal(0.5f);
    Vector3f extent = max.subtract(min).multLocal(0.5f);
    //Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned
    return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f);
}
 
Example 3
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 6 votes vote down vote up
protected void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){
    // applying gravity
    p.velocity.x -= gravity.x * tpf;
    p.velocity.y -= gravity.y * tpf;
    p.velocity.z -= gravity.z * tpf;
    temp.set(p.velocity).multLocal(tpf);
    p.position.addLocal(temp);

    // affecting color, size and angle
    float b = (p.startlife - p.life) / p.startlife;
    p.color.interpolateLocal(startColor, endColor, b);
    p.size = FastMath.interpolateLinear(b, startSize, endSize);
    p.angle += p.rotateSpeed * tpf;

    // Computing bounding volume
    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    if (!selectRandomImage) {
        p.imageIndex = (int) (b * imagesX * imagesY);
    }
}
 
Example 4
Source File: ShadowUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Compute bounds from an array of points
 * @param pts
 * @param mat
 * @return 
 */
public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) {
    Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
    Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
    Vector3f temp = new Vector3f();

    for (int i = 0; i < pts.length; i++) {
        float w = mat.multProj(pts[i], temp);

        temp.x /= w;
        temp.y /= w;
        // Why was this commented out?
        temp.z /= w;

        min.minLocal(temp);
        max.maxLocal(temp);
    }

    Vector3f center = min.add(max).multLocal(0.5f);
    Vector3f extent = max.subtract(min).multLocal(0.5f);
    //Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned
    return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f);
}
 
Example 5
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){
    // applying gravity
    p.velocity.x -= gravity.x * tpf;
    p.velocity.y -= gravity.y * tpf;
    p.velocity.z -= gravity.z * tpf;
    temp.set(p.velocity).multLocal(tpf);
    p.position.addLocal(temp);

    // affecting color, size and angle
    float b = (p.startlife - p.life) / p.startlife;
    p.color.interpolate(startColor, endColor, b);
    p.size = FastMath.interpolateLinear(b, startSize, endSize);
    p.angle += p.rotateSpeed * tpf;

    // Computing bounding volume
    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    if (!selectRandomImage) {
        p.imageIndex = (int) (b * imagesX * imagesY);
    }
}
 
Example 6
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Particle emitParticle(Vector3f min, Vector3f max) {
    int idx = lastUsed + 1;
    if (idx >= particles.length) {
        return null;
    }

    Particle p = particles[idx];
    if (selectRandomImage) {
        p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1);
    }

    p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife);
    p.life = p.startlife;
    p.color.set(startColor);
    p.size = startSize;
    //shape.getRandomPoint(p.position);
    particleInfluencer.influenceParticle(p, shape);
    if (worldSpace) {
        worldTransform.transformVector(p.position, p.position);
        worldTransform.getRotation().mult(p.velocity, p.velocity);
        // TODO: Make scale relevant somehow??
    }
    if (randomAngle) {
        p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI;
    }
    if (rotateSpeed != 0) {
        p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f);
    }

    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    ++lastUsed;
    firstUnUsed = idx + 1;
    return p;
}
 
Example 7
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compute bounds from an array of points
 *
 * @param pts
 * @param transform
 * @return a new instance
 */
public static BoundingBox computeBoundForPoints(Vector3f[] pts, Transform transform) {
    Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
    Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
    Vector3f temp = new Vector3f();
    for (int i = 0; i < pts.length; i++) {
        transform.transformVector(pts[i], temp);

        min.minLocal(temp);
        max.maxLocal(temp);
    }
    Vector3f center = min.add(max).multLocal(0.5f);
    Vector3f extent = max.subtract(min).multLocal(0.5f);
    return new BoundingBox(center, extent.x, extent.y, extent.z);
}
 
Example 8
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 5 votes vote down vote up
private Particle emitParticle(Vector3f min, Vector3f max) {
    int idx = lastUsed + 1;
    if (idx >= particles.length) {
        return null;
    }

    Particle p = particles[idx];
    if (selectRandomImage) {
        p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1);
    }

    p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife);
    p.life = p.startlife;
    p.color.set(startColor);
    p.size = startSize;
    //shape.getRandomPoint(p.position);
    particleInfluencer.influenceParticle(p, shape);
    if (worldSpace) {
        worldTransform.transformVector(p.position, p.position);
        worldTransform.getRotation().mult(p.velocity, p.velocity);
        // TODO: Make scale relevant somehow??
    }
    if (randomAngle) {
        p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI;
    }
    if (rotateSpeed != 0) {
        p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f);
    }

    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    ++lastUsed;
    firstUnUsed = idx + 1;
    return p;
}
 
Example 9
Source File: ShadowUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Compute bounds from an array of points
 * @param pts
 * @param transform
 * @return 
 */
public static BoundingBox computeBoundForPoints(Vector3f[] pts, Transform transform) {
    Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY);
    Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY);
    Vector3f temp = new Vector3f();
    for (int i = 0; i < pts.length; i++) {
        transform.transformVector(pts[i], temp);

        min.minLocal(temp);
        max.maxLocal(temp);
    }
    Vector3f center = min.add(max).multLocal(0.5f);
    Vector3f extent = max.subtract(min).multLocal(0.5f);
    return new BoundingBox(center, extent.x, extent.y, extent.z);
}
 
Example 10
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Particle emitParticle(Vector3f min, Vector3f max) {
    int idx = lastUsed + 1;
    if (idx >= particles.length) {
        return null;
    }

    Particle p = particles[idx];
    if (selectRandomImage) {
        p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1);
    }

    p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife);
    p.life = p.startlife;
    p.color.set(startColor);
    p.size = startSize;
    //shape.getRandomPoint(p.position);
    particleInfluencer.influenceParticle(p, shape);
    if (worldSpace) {
        worldTransform.transformVector(p.position, p.position);
        worldTransform.getRotation().mult(p.velocity, p.velocity);
        // TODO: Make scale relevant somehow??
    }
    if (randomAngle) {
        p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI;
    }
    if (rotateSpeed != 0) {
        p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f);
    }

    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    ++lastUsed;
    firstUnUsed = idx + 1;
    return p;
}