Example usage for com.badlogic.gdx.math Matrix4 M23

List of usage examples for com.badlogic.gdx.math Matrix4 M23

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Matrix4 M23.

Prototype

int M23

To view the source code for com.badlogic.gdx.math Matrix4 M23.

Click Source Link

Document

ZW: Typically the translation of the Z component.

Usage

From source file:com.lyeeedar.Graphics.ParticleEffects.ParticleEmitter.java

License:Open Source License

public void update(float delta, Camera cam) {
    if (light != null) {
        light.positionAbsolutely(x + lightx + (ex / 2f), y + lighty + ey, z + lightz + (ez / 2));
        if (lightFlicker)
            light.attenuation = (float) (lightAttenuation
                    * (1 - ((1 - ((float) inactive.size / (float) active.size))) / 2));
    }/*from ww  w  . j  ava  2s  .  co  m*/

    tmpRot.set(cam.view).inv();
    tmpRot.getValues()[Matrix4.M03] = 0;
    tmpRot.getValues()[Matrix4.M13] = 0;
    tmpRot.getValues()[Matrix4.M23] = 0;

    Iterator<Particle> pItr = active.iterator();

    i = 0;
    while (pItr.hasNext()) {
        Particle p = pItr.next();

        float[] velocity = getAttributeValue(p.lifetime, ParticleAttribute.VELOCITY);

        p.update(delta, velocity[0], velocity[1], velocity[2]);

        if (p.lifetime > particleLifetime) {
            pItr.remove();
            inactive.add(p);
            continue;
        }

        tmpMat.setToTranslation(p.x, p.y, p.z).mul(tmpRot);

        int sprite = (int) getAttributeValue(p.lifetime, ParticleAttribute.SPRITE)[0];
        float[] size = getAttributeValue(p.lifetime, ParticleAttribute.SIZE);
        float[] colour = getAttributeValue(p.lifetime, ParticleAttribute.COLOUR);

        quad.set(-size[0] / 2, size[1] / 2, 0).mul(tmpMat);

        v = 0;

        vertices[(i * VERTEX_SIZE * 4) + v + 0] = quad.x;
        vertices[(i * VERTEX_SIZE * 4) + v + 1] = quad.y;
        vertices[(i * VERTEX_SIZE * 4) + v + 2] = quad.z;

        vertices[(i * VERTEX_SIZE * 4) + v + 3] = colour[0];
        vertices[(i * VERTEX_SIZE * 4) + v + 4] = colour[1];
        vertices[(i * VERTEX_SIZE * 4) + v + 5] = colour[2];
        vertices[(i * VERTEX_SIZE * 4) + v + 6] = colour[3];

        vertices[(i * VERTEX_SIZE * 4) + v + 7] = topLeftTexCoords[sprite][0];
        vertices[(i * VERTEX_SIZE * 4) + v + 8] = topLeftTexCoords[sprite][1];

        quad.set(size[0] / 2, size[1] / 2, 0).mul(tmpMat);

        v += VERTEX_SIZE;

        vertices[(i * VERTEX_SIZE * 4) + v + 0] = quad.x;
        vertices[(i * VERTEX_SIZE * 4) + v + 1] = quad.y;
        vertices[(i * VERTEX_SIZE * 4) + v + 2] = quad.z;

        vertices[(i * VERTEX_SIZE * 4) + v + 3] = colour[0];
        vertices[(i * VERTEX_SIZE * 4) + v + 4] = colour[1];
        vertices[(i * VERTEX_SIZE * 4) + v + 5] = colour[2];
        vertices[(i * VERTEX_SIZE * 4) + v + 6] = colour[3];

        vertices[(i * VERTEX_SIZE * 4) + v + 7] = topRightTexCoords[sprite][0];
        vertices[(i * VERTEX_SIZE * 4) + v + 8] = topRightTexCoords[sprite][1];

        quad.set(-size[0] / 2, -size[1] / 2, 0).mul(tmpMat);

        v += VERTEX_SIZE;

        vertices[(i * VERTEX_SIZE * 4) + v + 0] = quad.x;
        vertices[(i * VERTEX_SIZE * 4) + v + 1] = quad.y;
        vertices[(i * VERTEX_SIZE * 4) + v + 2] = quad.z;

        vertices[(i * VERTEX_SIZE * 4) + v + 3] = colour[0];
        vertices[(i * VERTEX_SIZE * 4) + v + 4] = colour[1];
        vertices[(i * VERTEX_SIZE * 4) + v + 5] = colour[2];
        vertices[(i * VERTEX_SIZE * 4) + v + 6] = colour[3];

        vertices[(i * VERTEX_SIZE * 4) + v + 7] = botLeftTexCoords[sprite][0];
        vertices[(i * VERTEX_SIZE * 4) + v + 8] = botLeftTexCoords[sprite][1];

        quad.set(size[0] / 2, -size[1] / 2, 0).mul(tmpMat);

        v += VERTEX_SIZE;

        vertices[(i * VERTEX_SIZE * 4) + v + 0] = quad.x;
        vertices[(i * VERTEX_SIZE * 4) + v + 1] = quad.y;
        vertices[(i * VERTEX_SIZE * 4) + v + 2] = quad.z;

        vertices[(i * VERTEX_SIZE * 4) + v + 3] = colour[0];
        vertices[(i * VERTEX_SIZE * 4) + v + 4] = colour[1];
        vertices[(i * VERTEX_SIZE * 4) + v + 5] = colour[2];
        vertices[(i * VERTEX_SIZE * 4) + v + 6] = colour[3];

        vertices[(i * VERTEX_SIZE * 4) + v + 7] = botRightTexCoords[sprite][0];
        vertices[(i * VERTEX_SIZE * 4) + v + 8] = botRightTexCoords[sprite][1];

        i++;
    }
    mesh.setVertices(vertices);

    emissionCD -= delta;

    arrayLen = inactive.size;

    if (arrayLen == 0)
        return;

    while (emissionCD < 0 && arrayLen > 0) {
        Particle p = inactive.remove(0);

        if (emissionType == 0) {
            signx = (ran.nextInt(2) == 0) ? 1 : -1;
            signy = (ran.nextInt(2) == 0) ? 1 : -1;
            signz = (ran.nextInt(2) == 0) ? 1 : -1;
            p.set(particleLifetimeVar * ran.nextFloat(), x + (float) (ex * ran.nextGaussian() * signx),
                    y + (float) (ey * ran.nextGaussian() * signy),
                    z + (float) (ez * ran.nextGaussian() * signz));

        } else {
            System.err.println("Invalid emission type! " + emissionType);
        }
        active.add(p);

        emissionCD += emissionTime;
        arrayLen--;
    }
}

From source file:com.perfectplay.org.SkyBox.java

License:Open Source License

public void render(PerspectiveCamera camera) {
    invView.set(camera.view);//from  www  .  j  a  v  a 2 s  .c o  m

    // Remove translation
    invView.val[Matrix4.M03] = 0;
    invView.val[Matrix4.M13] = 0;
    invView.val[Matrix4.M23] = 0;

    invView.inv().tra();

    mvp.set(camera.projection);
    mvp.mul(invView);

    Gdx.gl.glEnable(GL20.GL_CULL_FACE);
    Gdx.gl.glCullFace(GL20.GL_FRONT);
    Gdx.gl.glFrontFace(GL20.GL_CCW);

    Gdx.gl20.glDisable(GL20.GL_BLEND);
    Gdx.gl20.glDisable(GL20.GL_DEPTH_TEST);
    Gdx.gl20.glDepthMask(false);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, g_cubeTexture);

    program.begin();

    program.setUniformMatrix("u_mvpMatrix", mvp);
    program.setUniformi("s_cubemap", 0);

    cube.render(program, GL20.GL_TRIANGLE_STRIP);

    program.end();

    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(true);
}

From source file:MeshBoneUtil.dualQuat.java

License:Open Source License

public void convertToMat(Matrix4 m) {
    float cur_length = (float) real.dot(real);
    float w = (float) real.w, x = (float) real.x, y = (float) real.y, z = (float) real.z;
    float t0 = (float) imaginary.w, t1 = (float) imaginary.x, t2 = (float) imaginary.y,
            t3 = (float) imaginary.z;

    m.val[Matrix4.M01] = w * w + x * x - y * y - z * z;
    m.val[Matrix4.M02] = 2 * x * y - 2 * w * z;
    m.val[Matrix4.M03] = 2 * x * z + 2 * w * y;

    m.val[Matrix4.M11] = 2 * x * y + 2 * w * z;
    m.val[Matrix4.M12] = w * w + y * y - x * x - z * z;
    m.val[Matrix4.M13] = 2 * y * z - 2 * w * x;

    m.val[Matrix4.M21] = 2 * x * z - 2 * w * y;
    m.val[Matrix4.M22] = 2 * y * z + 2 * w * x;
    m.val[Matrix4.M23] = w * w + z * z - x * x - y * y;

    m.val[Matrix4.M31] = -2 * t0 * x + 2 * w * t1 - 2 * t2 * z + 2 * y * t3;
    m.val[Matrix4.M32] = -2 * t0 * y + 2 * t1 * z - 2 * x * t3 + 2 * w * t2;
    m.val[Matrix4.M33] = -2 * t0 * z + 2 * x * t2 + 2 * w * t3 - 2 * t1 * y;

    // ??//from  w  w w  .  ja  v a  2s.  com
    m.val[Matrix4.M03] = 0;
    m.val[Matrix4.M13] = 0;
    m.val[Matrix4.M23] = 0;
    m.val[Matrix4.M33] = cur_length;

    for (int i = 0; i < 16; i++) {
        m.val[i] /= cur_length;
    }
    //m /= cur_length;
}

From source file:ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera.java

License:Apache License

public void setCustomARProjectionMatrix(final float focalPointX, final float focalPointY,
        final float cameraCenterX, final float cameraCenterY, final float near, final float far, final float w,
        final float h) {
    final float FAR_PLUS_NEAR = far + near;
    final float FAR_LESS_NEAR = far - near;

    projection.val[Matrix4.M00] = -2.0f * focalPointX / w;
    projection.val[Matrix4.M10] = 0.0f;
    projection.val[Matrix4.M20] = 0.0f;
    projection.val[Matrix4.M30] = 0.0f;

    projection.val[Matrix4.M01] = 0.0f;
    projection.val[Matrix4.M11] = 2.0f * focalPointY / h;
    projection.val[Matrix4.M21] = 0.0f;
    projection.val[Matrix4.M31] = 0.0f;

    projection.val[Matrix4.M02] = 2.0f * cameraCenterX / w - 1.0f;
    projection.val[Matrix4.M12] = 2.0f * cameraCenterY / h - 1.0f;
    projection.val[Matrix4.M22] = -FAR_PLUS_NEAR / FAR_LESS_NEAR;
    projection.val[Matrix4.M32] = -1.0f;

    projection.val[Matrix4.M03] = 0.0f;
    projection.val[Matrix4.M13] = 0.0f;
    projection.val[Matrix4.M23] = -2.0f * far * near / FAR_LESS_NEAR;
    projection.val[Matrix4.M33] = 0.0f;
}

From source file:ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem.java

License:Apache License

private void applyWorldTransform(ModelInstance model, GeometryComponent geometry) {
    translationMatrix.setToTranslation(geometry.position);

    rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
    rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
    rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
    rotationMatrix.val[Matrix4.M30] = 0;

    rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
    rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
    rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
    rotationMatrix.val[Matrix4.M31] = 0;

    rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
    rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
    rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
    rotationMatrix.val[Matrix4.M32] = 0;

    rotationMatrix.val[Matrix4.M03] = 0;
    rotationMatrix.val[Matrix4.M13] = 0;
    rotationMatrix.val[Matrix4.M23] = 0;
    rotationMatrix.val[Matrix4.M33] = 1;

    scalingMatrix.setToScaling(geometry.scaling);

    model.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
    model.calculateTransforms();/* w  w  w . j a va2  s  . c  o m*/
}