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

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

Introduction

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

Prototype

public Matrix4 set(Affine2 affine) 

Source Link

Document

Sets this matrix to the given affine matrix.

Usage

From source file:br.com.abby.util.BufferTools.java

License:LGPL

public static FloatBuffer asFloatBuffer(Matrix4 matrix4f) {
    FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
    matrix4f.set(buffer.array());
    return buffer;
}

From source file:br.com.abby.util.BufferTools.java

License:LGPL

public static FloatBuffer asFlippedFloatBuffer(Matrix4 matrix4f) {
    FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
    matrix4f.set(buffer.array());
    buffer.flip();/*w w  w . j a  v  a  2s  .  co m*/
    return buffer;
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.Shapes.java

License:Open Source License

public static Mesh insertLight(Mesh mesh, LightManager lights, boolean bakeStatics, Matrix4 model_matrix) {
    VertexAttributes attributes = mesh.getVertexAttributes();
    final int vertCount = mesh.getNumVertices();
    final int vertexSize = attributes.vertexSize / 4;

    VertexAttribute[] newAttributes = new VertexAttribute[attributes.size() + 1];
    for (int i = 0; i < attributes.size(); i++) {
        newAttributes[i] = attributes.get(i);
    }/*from w w w  .j a  v  a  2s  . c  o m*/
    newAttributes[attributes.size()] = new VertexAttribute(Usage.Generic, 3, "a_baked_light");

    final int newVertexSize = vertexSize + 3;

    float[] verts = new float[vertexSize * vertCount];
    mesh.getVertices(verts);
    short[] indices = new short[mesh.getNumIndices()];
    mesh.getIndices(indices);
    float[] newVerts = new float[newVertexSize * vertCount];

    int positionOffset = attributes.getOffset(Usage.Position);
    int normalOffset = attributes.getOffset(Usage.Normal);

    Matrix4 normal_matrix = new Matrix4();
    normal_matrix.set(model_matrix);

    Vector3 position = new Vector3();

    for (int i = 0; i < vertCount; i++) {
        int j = 0;
        for (; j < vertexSize; j++) {
            newVerts[(i * newVertexSize) + j] = verts[(i * vertexSize) + j];
        }

        position.set(verts[(i * vertexSize) + positionOffset], verts[(i * vertexSize) + positionOffset + 1],
                verts[(i * vertexSize) + positionOffset + 2]).mul(model_matrix);

        Vector3 normal = new Vector3(verts[(i * vertexSize) + normalOffset],
                verts[(i * vertexSize) + normalOffset + 1], verts[(i * vertexSize) + normalOffset + 2]);
        normal.rot(normal_matrix).nor();

        Color light_colour = lights.calculateLightAtPoint(position, normal, bakeStatics);

        newVerts[(i * newVertexSize) + j + 0] = light_colour.r;
        newVerts[(i * newVertexSize) + j + 1] = light_colour.g;
        newVerts[(i * newVertexSize) + j + 2] = light_colour.b;
    }

    Mesh newMesh = new Mesh(true, mesh.getNumVertices(), mesh.getNumIndices(), newAttributes);
    newMesh.setVertices(newVerts);
    newMesh.setIndices(indices);

    return newMesh;
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.VisibleObject.java

License:Open Source License

public void bakeLights(LightManager lights, boolean bakeStatics) {
    int primitive_type = model.subMeshes[0].primitiveType;

    Mesh oldMesh = model.subMeshes[0].mesh;

    Matrix4 mat = new Matrix4();
    mat.set(attributes.getTransform()).scale(attributes.scale, attributes.scale, attributes.scale)
            .mul(attributes.getRotation());
    Mesh newMesh = Shapes.insertLight(oldMesh, lights, bakeStatics, mat);

    model.subMeshes[0] = new StillSubMesh("SubMesh1", newMesh, primitive_type);
}

From source file:com.mygdx.game.scene.GameScene.java

License:Apache License

/**
 * Creates and adds the navmesh to this scene.
 *//*w  ww .  ja  v a 2 s . co  m*/
private void setNavmesh(GameObjectBlueprint bp) {
    // We need to set the node transforms before calculating the navmesh shape
    GameModel gameModel = new GameModel(bp.model, bp.name, bp.position, bp.rotation, bp.scale);

    Array<NodePart> nodes = gameModel.modelInstance.model.getNode("navmesh").parts;
    // Sort the model meshParts array according to material name
    nodes.sort(new NavMeshNodeSorter());

    // The model transform must be applied to the meshparts for shape generation to work correctly.
    gameModel.modelInstance.calculateTransforms();
    Matrix4 transform = new Matrix4();
    for (Node node : gameModel.modelInstance.nodes) {
        transform.set(node.globalTransform).inv();
        for (NodePart nodePart : node.parts) {
            nodePart.meshPart.mesh.transform(transform);
        }
    }
    navMesh = new NavMesh(gameModel.modelInstance.model);
    btCollisionShape shape = navMesh.getShape();

    navmeshBody = new InvisibleBody("navmesh", shape, 0, gameModel.modelInstance.transform,
            GameEngine.NAVMESH_FLAG, GameEngine.NAVMESH_FLAG, false, false);
    worldBounds.set(gameModel.boundingBox);
    gameModel.dispose();
}

From source file:com.trgk.touchwave.tgengine.ui.TGText.java

License:Open Source License

@Override
public void draw(Batch batch, float parentAlpha) {
    Matrix4 oldTransform = new Matrix4(batch.getTransformMatrix());
    Affine2 localTransform = new Affine2();
    localTransform.setToTrnScl(getX() + getOriginX(), getY() + getOriginY(), getScaleX(), getScaleY());
    localTransform.translate(-getOriginX(), -getOriginY());
    localTransform.scale(1f / TGResources.baseFontSize, 1f / TGResources.baseFontSize);

    Matrix4 localTransformMatrix = new Matrix4();
    localTransformMatrix.set(localTransform);

    Matrix4 newTransform = new Matrix4(oldTransform);
    newTransform.mul(localTransformMatrix);
    batch.setTransformMatrix(newTransform);

    Color alphaMultipliedColor = new Color(getColor());
    alphaMultipliedColor.a *= parentAlpha;
    drawCache.tint(alphaMultipliedColor);
    drawCache.draw(batch);//from  w ww  .  ja  va2s .  c  om

    batch.setTransformMatrix(oldTransform);
}

From source file:gaia.cu9.ari.gaiaorbit.util.g3d.MeshBuilder2.java

License:Apache License

@Override
public void arrow(float x1, float y1, float z1, float x2, float y2, float z2, float capLength,
        float stemThickness, int divisions) {
    Vector3 begin = tmp(x1, y1, z1), end = tmp(x2, y2, z2);
    float length = begin.dst(end);
    float coneHeight = length * capLength;
    float coneDiameter = 2 * (float) (coneHeight * Math.sqrt(1f / 3));
    float stemLength = length - coneHeight;
    float stemDiameter = coneDiameter * stemThickness;

    Vector3 up = tmp(end).sub(begin).nor();
    Vector3 forward = tmp(up).crs(Vector3.Z);
    if (forward.isZero())
        forward.set(Vector3.X);/*from  www .  j a  va 2 s. co m*/
    forward.crs(up).nor();
    Vector3 left = tmp(up).crs(forward).nor();
    Vector3 direction = tmp(end).sub(begin).nor();

    // Matrices
    Matrix4 userTransform = getVertexTransform(tmp());
    Matrix4 transform = tmp();
    float[] val = transform.val;
    val[Matrix4.M00] = left.x;
    val[Matrix4.M01] = up.x;
    val[Matrix4.M02] = forward.x;
    val[Matrix4.M10] = left.y;
    val[Matrix4.M11] = up.y;
    val[Matrix4.M12] = forward.y;
    val[Matrix4.M20] = left.z;
    val[Matrix4.M21] = up.z;
    val[Matrix4.M22] = forward.z;
    Matrix4 temp = tmp();

    // Stem
    transform.setTranslation(tmp(direction).scl(stemLength / 2).add(x1, y1, z1));
    setVertexTransform(temp.set(transform).mul(userTransform));
    cylinder(stemDiameter, stemLength, stemDiameter, divisions);

    // Cap
    transform.setTranslation(tmp(direction).scl(stemLength).add(x1, y1, z1));
    setVertexTransform(temp.set(transform).mul(userTransform));
    cone(coneDiameter, coneHeight, coneDiameter, divisions);

    setVertexTransform(userTransform);
    cleanup();
}

From source file:gaia.cu9.ari.gaiaorbit.util.g3d.MeshBuilder2.java

License:Apache License

@Override
public Matrix4 getVertexTransform(Matrix4 out) {
    return out.set(positionTransform);
}

From source file:MeshBoneUtil.Utils.java

License:Open Source License

public static Matrix4 mulMat(Matrix4 mat_in, float factor) {
    Matrix4 ret_mat = mat_in.cpy();
    float val[] = ret_mat.getValues();

    for (int i = 0; i < 16; i++) {
        val[i] *= factor;
    }/*from  w  ww .ja  v a  2s. c  o m*/

    ret_mat.set(val);

    return ret_mat;
}