Search in sources :

Example 66 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class TriangleAxisComparator method compare.

public int compare(BIHTriangle o1, BIHTriangle o2) {
    float v1, v2;
    Vector3f c1 = o1.getCenter();
    Vector3f c2 = o2.getCenter();
    switch(axis) {
        case 0:
            v1 = c1.x;
            v2 = c2.x;
            break;
        case 1:
            v1 = c1.y;
            v2 = c2.y;
            break;
        case 2:
            v1 = c1.z;
            v2 = c2.z;
            break;
        default:
            assert false;
            return 0;
    }
    if (v1 > v2)
        return 1;
    else if (v1 < v2)
        return -1;
    else
        return 0;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 67 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method updateParticleState.

private void updateParticleState(float tpf) {
    // Force world transform to update
    this.getWorldTransform();
    TempVars vars = TempVars.get();
    Vector3f min = vars.vect1.set(Vector3f.POSITIVE_INFINITY);
    Vector3f max = vars.vect2.set(Vector3f.NEGATIVE_INFINITY);
    for (int i = 0; i < particles.length; ++i) {
        Particle p = particles[i];
        if (p.life == 0) {
            //                assert i <= firstUnUsed;
            continue;
        }
        p.life -= tpf;
        if (p.life <= 0) {
            this.freeParticle(i);
            continue;
        }
        updateParticle(p, tpf, min, max);
        if (firstUnUsed < i) {
            this.swap(firstUnUsed, i);
            if (i == lastUsed) {
                lastUsed = firstUnUsed;
            }
            firstUnUsed++;
        }
    }
    // Spawns particles within the tpf timeslot with proper age
    float interval = 1f / particlesPerSec;
    float originalTpf = tpf;
    tpf += timeDifference;
    while (tpf > interval) {
        tpf -= interval;
        Particle p = emitParticle(min, max);
        if (p != null) {
            p.life -= tpf;
            if (lastPos != null && isInWorldSpace()) {
                p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf);
            }
            if (p.life <= 0) {
                freeParticle(lastUsed);
            } else {
                updateParticle(p, tpf, min, max);
            }
        }
    }
    timeDifference = tpf;
    if (lastPos == null) {
        lastPos = new Vector3f();
    }
    lastPos.set(getWorldTranslation());
    //This check avoids a NaN bounds when all the particles are dead during the first update.
    if (!min.equals(Vector3f.POSITIVE_INFINITY) && !max.equals(Vector3f.NEGATIVE_INFINITY)) {
        BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
        bbox.setMinMax(min, max);
        this.setBoundRefresh();
    }
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) TempVars(com.jme3.util.TempVars)

Example 68 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(shape, "shape", DEFAULT_SHAPE);
    oc.write(meshType, "meshType", ParticleMesh.Type.Triangle);
    oc.write(enabled, "enabled", true);
    oc.write(particles.length, "numParticles", 0);
    oc.write(particlesPerSec, "particlesPerSec", 0);
    oc.write(lowLife, "lowLife", 0);
    oc.write(highLife, "highLife", 0);
    oc.write(gravity, "gravity", null);
    oc.write(imagesX, "imagesX", 1);
    oc.write(imagesY, "imagesY", 1);
    oc.write(startColor, "startColor", null);
    oc.write(endColor, "endColor", null);
    oc.write(startSize, "startSize", 0);
    oc.write(endSize, "endSize", 0);
    oc.write(worldSpace, "worldSpace", false);
    oc.write(facingVelocity, "facingVelocity", false);
    oc.write(faceNormal, "faceNormal", new Vector3f(Vector3f.NAN));
    oc.write(selectRandomImage, "selectRandomImage", false);
    oc.write(randomAngle, "randomAngle", false);
    oc.write(rotateSpeed, "rotateSpeed", 0);
    oc.write(particleInfluencer, "influencer", DEFAULT_INFLUENCER);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 69 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    shape = (EmitterShape) ic.readSavable("shape", DEFAULT_SHAPE);
    if (shape == DEFAULT_SHAPE) {
        // Prevent reference to static
        shape = shape.deepClone();
    }
    meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle);
    int numParticles = ic.readInt("numParticles", 0);
    enabled = ic.readBoolean("enabled", true);
    particlesPerSec = ic.readFloat("particlesPerSec", 0);
    lowLife = ic.readFloat("lowLife", 0);
    highLife = ic.readFloat("highLife", 0);
    gravity = (Vector3f) ic.readSavable("gravity", null);
    imagesX = ic.readInt("imagesX", 1);
    imagesY = ic.readInt("imagesY", 1);
    startColor = (ColorRGBA) ic.readSavable("startColor", null);
    endColor = (ColorRGBA) ic.readSavable("endColor", null);
    startSize = ic.readFloat("startSize", 0);
    endSize = ic.readFloat("endSize", 0);
    worldSpace = ic.readBoolean("worldSpace", false);
    this.setIgnoreTransform(worldSpace);
    facingVelocity = ic.readBoolean("facingVelocity", false);
    faceNormal = (Vector3f) ic.readSavable("faceNormal", new Vector3f(Vector3f.NAN));
    selectRandomImage = ic.readBoolean("selectRandomImage", false);
    randomAngle = ic.readBoolean("randomAngle", false);
    rotateSpeed = ic.readFloat("rotateSpeed", 0);
    switch(meshType) {
        case Point:
            particleMesh = new ParticlePointMesh();
            this.setMesh(particleMesh);
            break;
        case Triangle:
            particleMesh = new ParticleTriMesh();
            this.setMesh(particleMesh);
            break;
        default:
            throw new IllegalStateException("Unrecognized particle type: " + meshType);
    }
    this.setNumParticles(numParticles);
    //        particleMesh.initParticleData(this, particles.length);
    //        particleMesh.setImagesXY(imagesX, imagesY);
    particleInfluencer = (ParticleInfluencer) ic.readSavable("influencer", DEFAULT_INFLUENCER);
    if (particleInfluencer == DEFAULT_INFLUENCER) {
        particleInfluencer = particleInfluencer.clone();
    }
    if (im.getFormatVersion() == 0) {
        // find it in the controls and take it out, then add the proper one in
        for (int i = 0; i < controls.size(); i++) {
            Object obj = controls.get(i);
            if (obj instanceof ParticleEmitter) {
                controls.remove(i);
                // now add the proper one in
                controls.add(new ParticleEmitterControl(this));
                break;
            }
        }
        // compatability before gravity was not a vector but a float
        if (gravity == null) {
            gravity = new Vector3f();
            gravity.y = ic.readFloat("gravity", 0);
        }
    } else {
        // since the parentEmitter is not loaded, it must be
        // loaded separately
        control = getControl(ParticleEmitterControl.class);
        control.parentEmitter = this;
    }
}
Also used : Type(com.jme3.effect.ParticleMesh.Type) InputCapsule(com.jme3.export.InputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 70 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class ChaseCamera method setSpatial.

/**
     * Sets the spacial for the camera control, should only be used internally
     * @param spatial
     */
public void setSpatial(Spatial spatial) {
    target = spatial;
    if (spatial == null) {
        return;
    }
    computePosition();
    prevPos = new Vector3f(target.getWorldTranslation());
    cam.setLocation(pos);
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)536 Material (com.jme3.material.Material)126 Geometry (com.jme3.scene.Geometry)118 DirectionalLight (com.jme3.light.DirectionalLight)95 Quaternion (com.jme3.math.Quaternion)94 TempVars (com.jme3.util.TempVars)67 ColorRGBA (com.jme3.math.ColorRGBA)64 Node (com.jme3.scene.Node)63 Spatial (com.jme3.scene.Spatial)57 Box (com.jme3.scene.shape.Box)57 Sphere (com.jme3.scene.shape.Sphere)51 Texture (com.jme3.texture.Texture)41 KeyTrigger (com.jme3.input.controls.KeyTrigger)36 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)35 Vector2f (com.jme3.math.Vector2f)35 FilterPostProcessor (com.jme3.post.FilterPostProcessor)34 FloatBuffer (java.nio.FloatBuffer)34 InputCapsule (com.jme3.export.InputCapsule)33 BoundingBox (com.jme3.bounding.BoundingBox)30 AmbientLight (com.jme3.light.AmbientLight)30