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

The following examples show how to use com.jme3.math.Vector3f#maxLocal() . 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: BoxLayout.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void calculatePreferredSize( Vector3f size ) {
    // Calculate the size we'd like to be to let
    // all of the children have space
    Vector3f pref = new Vector3f();
    preferredSizes.clear();
    for( Node n : children ) {
        Vector3f v = n.getControl(GuiControl.class).getPreferredSize();

        preferredSizes.add(v.clone());

        // We do a little trickery here by adding the
        // axis direction to the returned preferred size.
        // That way we can just "max" the whole thing.
        switch( axis ) {
            case X:
                v.x += pref.x;
                break;
            case Y:
                v.y += pref.y;
                break;
            case Z:
                v.z += pref.z;
                break;
        }

        pref.maxLocal(v);
    }
    lastPreferredSize = pref.clone();

    // The preferred size is the size... because layouts will always
    // be the decider in a component stack.  They are always first
    // in the component chain for preferred size and last for reshaping.
    size.set(pref);
}
 
Example 7
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 8
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 9
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 10
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 11
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;
}