Example usage for com.badlogic.gdx.math Vector3 rot

List of usage examples for com.badlogic.gdx.math Vector3 rot

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector3 rot.

Prototype

public Vector3 rot(final Matrix4 matrix) 

Source Link

Document

Multiplies this vector by the first three columns of the matrix, essentially only applying rotation and scaling.

Usage

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 av a 2s. c  om
    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;
}