Search in sources :

Example 11 with Matrix3f

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

the class ChildCollisionShape method write.

public void write(JmeExporter ex) throws IOException {
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.write(location, "location", new Vector3f());
    capsule.write(rotation, "rotation", new Matrix3f());
    capsule.write(shape, "shape", new BoxCollisionShape(new Vector3f(1, 1, 1)));
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Vector3f(com.jme3.math.Vector3f) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 12 with Matrix3f

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

the class ParticleEmitter method renderFromControl.

/**
     * Callback from Control.render(), do not use.
     *
     * @param rm
     * @param vp
     */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();
    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;
        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }
    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();
        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Camera(com.jme3.renderer.Camera) TempVars(com.jme3.util.TempVars)

Example 13 with Matrix3f

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

the class ParticlePointMesh method updateParticleData.

@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
    VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
    FloatBuffer positions = (FloatBuffer) pvb.getData();
    VertexBuffer cvb = getBuffer(VertexBuffer.Type.Color);
    ByteBuffer colors = (ByteBuffer) cvb.getData();
    VertexBuffer svb = getBuffer(VertexBuffer.Type.Size);
    FloatBuffer sizes = (FloatBuffer) svb.getData();
    VertexBuffer tvb = getBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer texcoords = (FloatBuffer) tvb.getData();
    float sizeScale = emitter.getWorldScale().x;
    // update data in vertex buffers
    positions.rewind();
    colors.rewind();
    sizes.rewind();
    texcoords.rewind();
    for (int i = 0; i < particles.length; i++) {
        Particle p = particles[i];
        positions.put(p.position.x).put(p.position.y).put(p.position.z);
        sizes.put(p.size * sizeScale);
        colors.putInt(p.color.asIntABGR());
        int imgX = p.imageIndex % imagesX;
        int imgY = (p.imageIndex - imgX) / imagesY;
        float startX = ((float) imgX) / imagesX;
        float startY = ((float) imgY) / imagesY;
        float endX = startX + (1f / imagesX);
        float endY = startY + (1f / imagesY);
        texcoords.put(startX).put(startY).put(endX).put(endY);
    }
    positions.flip();
    colors.flip();
    sizes.flip();
    texcoords.flip();
    // force renderer to re-send data to GPU
    pvb.updateData(positions);
    cvb.updateData(colors);
    svb.updateData(sizes);
    tvb.updateData(texcoords);
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 14 with Matrix3f

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

the class ParticleTriMesh method updateParticleData.

@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
    //        System.arraycopy(particles, 0, particlesCopy, 0, particlesCopy.length);
    //        comparator.setCamera(cam);
    //        Arrays.sort(particlesCopy, comparator);
    //        SortUtil.qsort(particlesCopy, comparator);
    //        SortUtil.msort(particles, particlesCopy, comparator);
    //        particles = particlesCopy;
    VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
    FloatBuffer positions = (FloatBuffer) pvb.getData();
    VertexBuffer cvb = getBuffer(VertexBuffer.Type.Color);
    ByteBuffer colors = (ByteBuffer) cvb.getData();
    VertexBuffer tvb = getBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer texcoords = (FloatBuffer) tvb.getData();
    Vector3f camUp = cam.getUp();
    Vector3f camLeft = cam.getLeft();
    Vector3f camDir = cam.getDirection();
    inverseRotation.multLocal(camUp);
    inverseRotation.multLocal(camLeft);
    inverseRotation.multLocal(camDir);
    boolean facingVelocity = emitter.isFacingVelocity();
    Vector3f up = new Vector3f(), left = new Vector3f();
    if (!facingVelocity) {
        up.set(camUp);
        left.set(camLeft);
    }
    // update data in vertex buffers
    positions.clear();
    colors.clear();
    texcoords.clear();
    Vector3f faceNormal = emitter.getFaceNormal();
    for (int i = 0; i < particles.length; i++) {
        Particle p = particles[i];
        boolean dead = p.life == 0;
        if (dead) {
            positions.put(0).put(0).put(0);
            positions.put(0).put(0).put(0);
            positions.put(0).put(0).put(0);
            positions.put(0).put(0).put(0);
            continue;
        }
        if (facingVelocity) {
            left.set(p.velocity).normalizeLocal();
            camDir.cross(left, up);
            up.multLocal(p.size);
            left.multLocal(p.size);
        } else if (faceNormal != null) {
            up.set(faceNormal).crossLocal(Vector3f.UNIT_X);
            faceNormal.cross(up, left);
            up.multLocal(p.size);
            left.multLocal(p.size);
            if (p.angle != 0) {
                TempVars vars = TempVars.get();
                vars.vect1.set(faceNormal).normalizeLocal();
                vars.quat1.fromAngleNormalAxis(p.angle, vars.vect1);
                vars.quat1.multLocal(left);
                vars.quat1.multLocal(up);
                vars.release();
            }
        } else if (p.angle != 0) {
            float cos = FastMath.cos(p.angle) * p.size;
            float sin = FastMath.sin(p.angle) * p.size;
            left.x = camLeft.x * cos + camUp.x * sin;
            left.y = camLeft.y * cos + camUp.y * sin;
            left.z = camLeft.z * cos + camUp.z * sin;
            up.x = camLeft.x * -sin + camUp.x * cos;
            up.y = camLeft.y * -sin + camUp.y * cos;
            up.z = camLeft.z * -sin + camUp.z * cos;
        } else {
            up.set(camUp);
            left.set(camLeft);
            up.multLocal(p.size);
            left.multLocal(p.size);
        }
        positions.put(p.position.x + left.x + up.x).put(p.position.y + left.y + up.y).put(p.position.z + left.z + up.z);
        positions.put(p.position.x - left.x + up.x).put(p.position.y - left.y + up.y).put(p.position.z - left.z + up.z);
        positions.put(p.position.x + left.x - up.x).put(p.position.y + left.y - up.y).put(p.position.z + left.z - up.z);
        positions.put(p.position.x - left.x - up.x).put(p.position.y - left.y - up.y).put(p.position.z - left.z - up.z);
        if (uniqueTexCoords) {
            int imgX = p.imageIndex % imagesX;
            int imgY = (p.imageIndex - imgX) / imagesY;
            float startX = ((float) imgX) / imagesX;
            float startY = ((float) imgY) / imagesY;
            float endX = startX + (1f / imagesX);
            float endY = startY + (1f / imagesY);
            texcoords.put(startX).put(endY);
            texcoords.put(endX).put(endY);
            texcoords.put(startX).put(startY);
            texcoords.put(endX).put(startY);
        }
        int abgr = p.color.asIntABGR();
        colors.putInt(abgr);
        colors.putInt(abgr);
        colors.putInt(abgr);
        colors.putInt(abgr);
    }
    positions.clear();
    colors.clear();
    if (!uniqueTexCoords)
        texcoords.clear();
    else {
        texcoords.clear();
        tvb.updateData(texcoords);
    }
    // force renderer to re-send data to GPU
    pvb.updateData(positions);
    cvb.updateData(colors);
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer) TempVars(com.jme3.util.TempVars) ByteBuffer(java.nio.ByteBuffer)

Example 15 with Matrix3f

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

the class BillboardControl method read.

@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule capsule = e.getCapsule(this);
    orient = (Matrix3f) capsule.readSavable("orient", null);
    look = (Vector3f) capsule.readSavable("look", null);
    left = (Vector3f) capsule.readSavable("left", null);
    alignment = capsule.readEnum("alignment", Alignment.class, Alignment.Screen);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Aggregations

Matrix3f (com.jme3.math.Matrix3f)21 Vector3f (com.jme3.math.Vector3f)10 TempVars (com.jme3.util.TempVars)8 ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)5 InputCapsule (com.jme3.export.InputCapsule)5 Transform (com.bulletphysics.linearmath.Transform)3 OutputCapsule (com.jme3.export.OutputCapsule)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)2 CollisionShape (com.jme3.bullet.collision.shapes.CollisionShape)2 CompoundCollisionShape (com.jme3.bullet.collision.shapes.CompoundCollisionShape)2 Geometry (com.jme3.scene.Geometry)2 Node (com.jme3.scene.Node)2 Spatial (com.jme3.scene.Spatial)2 VertexBuffer (com.jme3.scene.VertexBuffer)2 ByteBuffer (java.nio.ByteBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 Generic6DofConstraint (com.bulletphysics.dynamics.constraintsolver.Generic6DofConstraint)1 RotationalLimitMotor (com.jme3.bullet.joints.motors.RotationalLimitMotor)1 BitmapFont (com.jme3.font.BitmapFont)1