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

The following examples show how to use org.joml.Matrix4f#translate() . 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: Transform3DTest.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
@Test
public void getLocalMatrix()
{
    Transform3D t = new Transform3D();

    t.setPosition(10f, 30f, 50f);
    t.getRotation()
     .rotateLocalX((float) Math.toRadians(90f));
    t.setSize(4f);

    Matrix4f mat = new Matrix4f();
    t.getLocalMatrix(mat);

    Matrix4f mat2 = new Matrix4f();
    mat2.translate(10f, 30f, 50f);
    mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(90f)));
    mat2.scale(4f);

    Assert.assertEquals(mat2, mat);
}
 
Example 2
Source File: Transform3DTest.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
@Test
public void getFullMatrix_NullParent()
{
    Transform3D t = new Transform3D();
    t.setPosition(10f, 30f, 50f);
    t.getRotation()
     .rotateLocalX((float) Math.toRadians(90f));
    t.setSize(4f);

    Matrix4f mat = new Matrix4f();
    t.getFullMatrix(mat);

    Matrix4f mat2 = new Matrix4f();
    mat2.translate(10f, 30f, 50f);
    mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(90f)));
    mat2.scale(4f);

    Assert.assertEquals(mat2, mat);
}
 
Example 3
Source File: Transform3DTest.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
@Test
public void getLocalMatrix()
{
    Transform3D t = new Transform3D();

    t.setPosition(10f, 30f, 50f);
    t.getRotation()
     .rotateLocalX((float) Math.toRadians(90f));
    t.setSize(4f);

    Matrix4f mat = new Matrix4f();
    t.getLocalMatrix(mat);

    Matrix4f mat2 = new Matrix4f();
    mat2.translate(10f, 30f, 50f);
    mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(90f)));
    mat2.scale(4f);

    Assert.assertEquals(mat2, mat);
}
 
Example 4
Source File: Transform3DTest.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
@Test
public void getFullMatrix_NullParent()
{
    Transform3D t = new Transform3D();
    t.setPosition(10f, 30f, 50f);
    t.getRotation()
     .rotateLocalX((float) Math.toRadians(90f));
    t.setSize(4f);

    Matrix4f mat = new Matrix4f();
    t.getFullMatrix(mat);

    Matrix4f mat2 = new Matrix4f();
    mat2.translate(10f, 30f, 50f);
    mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(90f)));
    mat2.scale(4f);

    Assert.assertEquals(mat2, mat);
}
 
Example 5
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), new Vector3f(1, 0, 0))
            .rotate((float)Math.toRadians(rotation.y), new Vector3f(0, 1, 0));
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 6
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), new Vector3f(1, 0, 0))
            .rotate((float)Math.toRadians(rotation.y), new Vector3f(0, 1, 0));
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 7
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), new Vector3f(1, 0, 0))
            .rotate((float)Math.toRadians(rotation.y), new Vector3f(0, 1, 0));
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 8
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), X_AXIS)
            .rotate((float)Math.toRadians(rotation.y), Y_AXIS);
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 9
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), X_AXIS)
            .rotate((float)Math.toRadians(rotation.y), Y_AXIS);
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 10
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), X_AXIS)
            .rotate((float)Math.toRadians(rotation.y), Y_AXIS);
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 11
Source File: Transformation.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
private Matrix4f updateGenericViewMatrix(Vector3f position, Vector3f rotation, Matrix4f matrix) {
    matrix.identity();
    // First do the rotation so camera rotates over its position
    matrix.rotate((float)Math.toRadians(rotation.x), X_AXIS)
            .rotate((float)Math.toRadians(rotation.y), Y_AXIS);
    // Then do the translation
    matrix.translate(-position.x, -position.y, -position.z);
    return matrix;
}
 
Example 12
Source File: Transform3D.java    From WraithEngine with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the local matrix for this transform, and stores it in the output
 * matrix parameter.
 *
 * @param out
 *     - The matrix to store the output into.
 */
public void getLocalMatrix(Matrix4f out)
{
    out.identity();
    out.translate(position);
    out.rotate(rotation);
    out.scale(size);
}
 
Example 13
Source File: Transform3DTest.java    From WraithEngine with Apache License 2.0 5 votes vote down vote up
@Test
public void getFullMatrix()
{
    Transform3D parent = new Transform3D();
    parent.setPosition(10f, 30f, 50f);
    parent.setRotation(new Quaternionf().rotateLocalX((float) Math.toRadians(90f)));
    parent.setSize(4f);

    Transform3D t = new Transform3D();

    t.setParent(parent);
    t.setPosition(-5f, -17f, -5f);
    t.getRotation()
     .rotateLocalX((float) Math.toRadians(45f));
    t.setSize(0.5f);

    Matrix4f mat = new Matrix4f();
    t.getFullMatrix(mat);

    Matrix4f mat2 = new Matrix4f();
    mat2.translate(-5f, -17f, -5f);
    mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(45f)));
    mat2.scale(0.5f);

    Matrix4f tempMat2 = new Matrix4f();
    parent.getLocalMatrix(tempMat2);
    mat2 = tempMat2.mul(mat2);

    Assert.assertEquals(mat2, mat);
}
 
Example 14
Source File: Transform3D.java    From WraithEngine with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the local matrix for this transform, and stores it in the output
 * matrix parameter.
 *
 * @param out
 *     - The matrix to store the output into.
 */
public void getLocalMatrix(Matrix4f out)
{
    out.identity();
    out.translate(position);
    out.rotate(rotation);
    out.scale(size);
}
 
Example 15
Source File: Transform3DTest.java    From WraithEngine with Apache License 2.0 5 votes vote down vote up
@Test
public void getFullMatrix()
{
    Transform3D parent = new Transform3D();
    parent.setPosition(10f, 30f, 50f);
    parent.setRotation(new Quaternionf().rotateLocalX((float) Math.toRadians(90f)));
    parent.setSize(4f);

    Transform3D t = new Transform3D();

    t.setParent(parent);
    t.setPosition(-5f, -17f, -5f);
    t.getRotation()
     .rotateLocalX((float) Math.toRadians(45f));
    t.setSize(0.5f);

    Matrix4f mat = new Matrix4f();
    t.getFullMatrix(mat);

    Matrix4f mat2 = new Matrix4f();
    mat2.translate(-5f, -17f, -5f);
    mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(45f)));
    mat2.scale(0.5f);

    Matrix4f tempMat2 = new Matrix4f();
    parent.getLocalMatrix(tempMat2);
    mat2 = tempMat2.mul(mat2);

    Assert.assertEquals(mat2, mat);
}
 
Example 16
Source File: Transform.java    From LWJGL-3-Tutorial with MIT License 4 votes vote down vote up
public Matrix4f getProjection(Matrix4f target) {
	target.translate(pos);
	target.scale(scale);
	return target;
}