Java Code Examples for org.joml.Matrix4f#get()

The following examples show how to use org.joml.Matrix4f#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstancedMesh.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private void renderChunkInstanced(List<GameItem> gameItems, boolean depthMap, Transformation transformation, Matrix4f viewMatrix, Matrix4f lightViewMatrix) {
    this.modelViewBuffer.clear();
    this.modelLightViewBuffer.clear();

    int i = 0;

    for (GameItem gameItem : gameItems) {
        Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
        if (!depthMap) {
            Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix);
            modelViewMatrix.get(InstancedMesh.MATRIX_SIZE_FLOATS * i, modelViewBuffer);
        }
        Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix);
        modelLightViewMatrix.get(InstancedMesh.MATRIX_SIZE_FLOATS * i, this.modelLightViewBuffer);
        i++;
    }

    glBindBuffer(GL_ARRAY_BUFFER, modelViewVBO);
    glBufferData(GL_ARRAY_BUFFER, modelViewBuffer, GL_DYNAMIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, modelLightViewVBO);
    glBufferData(GL_ARRAY_BUFFER, modelLightViewBuffer, GL_DYNAMIC_DRAW);

    glDrawElementsInstanced(
            GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0, gameItems.size());

    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
Example 2
Source File: GenericShader.java    From LWJGUI with MIT License 4 votes vote down vote up
public void setProjectionMatrix(Matrix4f mat) {
	mat.get(matrix44Buffer);
	glUniformMatrix4fv(projMatLoc, false, matrix44Buffer);
}
 
Example 3
Source File: GenericShader.java    From LWJGUI with MIT License 4 votes vote down vote up
public void setViewMatrix(Matrix4f mat) {
	mat.get(matrix44Buffer);
	glUniformMatrix4fv(viewMatLoc, false, matrix44Buffer);
}
 
Example 4
Source File: GenericShader.java    From LWJGUI with MIT License 4 votes vote down vote up
public void setWorldMatrix(Matrix4f mat) {
	mat.get(matrix44Buffer);
	glUniformMatrix4fv(worldMatLoc, false, matrix44Buffer);
}
 
Example 5
Source File: Shader.java    From LWJGL-3-Tutorial with MIT License 4 votes vote down vote up
public void setUniform(String uniformName, Matrix4f value) {
	int location = glGetUniformLocation(programObject, uniformName);
	FloatBuffer matrixData = BufferUtils.createFloatBuffer(16);
	value.get(matrixData);
	if (location != -1) glUniformMatrix4fv(location, false, matrixData);
}
 
Example 6
Source File: InstancedMesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
private void renderChunkInstanced(List<GameItem> gameItems, boolean billBoard, Transformation transformation, Matrix4f viewMatrix, Matrix4f lightViewMatrix) {
    this.instanceDataBuffer.clear();

    int i = 0;

    Texture text = getMaterial().getTexture();
    for (GameItem gameItem : gameItems) {
        Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
        if (viewMatrix != null) {
            if (billBoard) {
                viewMatrix.transpose3x3(modelMatrix);
            }
            Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix);
            if (billBoard) {
                modelViewMatrix.scale(gameItem.getScale());
            }
            modelViewMatrix.get(InstancedMesh.INSTANCE_SIZE_FLOATS * i, instanceDataBuffer);
        }
        if (lightViewMatrix != null) {
            Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix);
            modelLightViewMatrix.get(InstancedMesh.INSTANCE_SIZE_FLOATS * i + InstancedMesh.MATRIX_SIZE_FLOATS, this.instanceDataBuffer);
        }
        if (text != null) {
            int col = gameItem.getTextPos() % text.getNumCols();
            int row = gameItem.getTextPos() / text.getNumCols();
            float textXOffset = (float) col / text.getNumCols();
            float textYOffset = (float) row / text.getNumRows();
            int buffPos = InstancedMesh.INSTANCE_SIZE_FLOATS * i + InstancedMesh.MATRIX_SIZE_FLOATS * 2;
            this.instanceDataBuffer.put(buffPos, textXOffset);
            this.instanceDataBuffer.put(buffPos + 1, textYOffset);
        }

        i++;
    }

    glBindBuffer(GL_ARRAY_BUFFER, instanceDataVBO);
    glBufferData(GL_ARRAY_BUFFER, instanceDataBuffer, GL_DYNAMIC_DRAW);

    glDrawElementsInstanced(
            GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0, gameItems.size());

    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
Example 7
Source File: InstancedMesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
private void renderChunkInstanced(List<GameItem> gameItems, boolean billBoard, Transformation transformation, Matrix4f viewMatrix, Matrix4f lightViewMatrix) {
    this.instanceDataBuffer.clear();

    int i = 0;

    Texture text = getMaterial().getTexture();
    for (GameItem gameItem : gameItems) {
        Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
        if (viewMatrix != null) {
            if (billBoard) {
                viewMatrix.transpose3x3(modelMatrix);
            }
            Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix);
            if (billBoard) {
                modelViewMatrix.scale(gameItem.getScale());
            }
            modelViewMatrix.get(InstancedMesh.INSTANCE_SIZE_FLOATS * i, instanceDataBuffer);
        }
        if (lightViewMatrix != null) {
            Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix);
            modelLightViewMatrix.get(InstancedMesh.INSTANCE_SIZE_FLOATS * i + InstancedMesh.MATRIX_SIZE_FLOATS, this.instanceDataBuffer);
        }
        if (text != null) {
            int col = gameItem.getTextPos() % text.getNumCols();
            int row = gameItem.getTextPos() / text.getNumCols();
            float textXOffset = (float) col / text.getNumCols();
            float textYOffset = (float) row / text.getNumRows();
            int buffPos = InstancedMesh.INSTANCE_SIZE_FLOATS * i + InstancedMesh.MATRIX_SIZE_FLOATS * 2;
            this.instanceDataBuffer.put(buffPos, textXOffset);
            this.instanceDataBuffer.put(buffPos + 1, textYOffset);
        }

        i++;
    }

    glBindBuffer(GL_ARRAY_BUFFER, instanceDataVBO);
    glBufferData(GL_ARRAY_BUFFER, instanceDataBuffer, GL_DYNAMIC_DRAW);

    glDrawElementsInstanced(
            GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0, gameItems.size());

    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
Example 8
Source File: InstancedMesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
private void renderChunkInstanced(List<GameItem> gameItems, boolean billBoard, Transformation transformation, Matrix4f viewMatrix, Matrix4f lightViewMatrix) {
    this.instanceDataBuffer.clear();

    int i = 0;

    Texture text = getMaterial().getTexture();
    for (GameItem gameItem : gameItems) {
        Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
        if (viewMatrix != null) {
            if (billBoard) {
                viewMatrix.transpose3x3(modelMatrix);
            }
            Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix);
            if (billBoard) {
                modelViewMatrix.scale(gameItem.getScale());
            }
            modelViewMatrix.get(InstancedMesh.INSTANCE_SIZE_FLOATS * i, instanceDataBuffer);
        }
        if (lightViewMatrix != null) {
            Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix);
            modelLightViewMatrix.get(InstancedMesh.INSTANCE_SIZE_FLOATS * i + InstancedMesh.MATRIX_SIZE_FLOATS, this.instanceDataBuffer);
        }
        if (text != null) {
            int col = gameItem.getTextPos() % text.getNumCols();
            int row = gameItem.getTextPos() / text.getNumCols();
            float textXOffset = (float) col / text.getNumCols();
            float textYOffset = (float) row / text.getNumRows();
            int buffPos = InstancedMesh.INSTANCE_SIZE_FLOATS * i + InstancedMesh.MATRIX_SIZE_FLOATS * 2;
            this.instanceDataBuffer.put(buffPos, textXOffset);
            this.instanceDataBuffer.put(buffPos + 1, textYOffset);
        }

        i++;
    }

    glBindBuffer(GL_ARRAY_BUFFER, instanceDataVBO);
    glBufferData(GL_ARRAY_BUFFER, instanceDataBuffer, GL_DYNAMIC_DRAW);

    glDrawElementsInstanced(
            GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0, gameItems.size());

    glBindBuffer(GL_ARRAY_BUFFER, 0);
}