Java Code Examples for org.lwjgl.util.vector.Matrix4f#translate()

The following examples show how to use org.lwjgl.util.vector.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: CompositePrimitive.java    From ldparteditor with MIT License 6 votes vote down vote up
private void adjustTranslate(float old, float zoom2) {
    float dx = 0;
    float dy = 0;
    dx = 0f / viewport_pixel_per_ldu;
    dy = 0f / viewport_pixel_per_ldu;
    Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f);
    Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
    Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z);
    Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);

    Matrix4f.load(old_viewport_translation, viewport_translation);
    Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation);
    Matrix4f.translate(yAxis3, viewport_translation, viewport_translation);

    viewport_translation.m30 = 0f;
    if (viewport_translation.m13 > 0f) viewport_translation.m13 = 0f;
    if (-viewport_translation.m31 > maxY) viewport_translation.m31 = -maxY;
}
 
Example 2
Source File: CompositePrimitive.java    From ldparteditor with MIT License 6 votes vote down vote up
public void scroll(boolean down) {

        float dy = 0;

        Matrix4f.load(getTranslation(), old_viewport_translation);

        if (down) {
            dy = -37f /  viewport_pixel_per_ldu;
        } else {
            dy = 37f /  viewport_pixel_per_ldu;
        }

        Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
        Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);
        Matrix4f.load(old_viewport_translation, viewport_translation);
        Matrix4f.translate(yAxis3, old_viewport_translation, viewport_translation);

        if (viewport_translation.m31 > 0f) viewport_translation.m31 = 0f;
        if (-viewport_translation.m31 > maxY) viewport_translation.m31 = -maxY;

        openGL.drawScene(-1, -1);
    }
 
Example 3
Source File: GUIRoot.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
protected final void displayChangedNotify(int width, int height) {
	//Reset The Current Viewport And Perspective Transformation
	setDim(width, height);
	if (width != 0) {
		float scale = getUnitsPerPixel(Globals.GUI_Z);
		Matrix4f m1 = new Matrix4f();
		m1.setIdentity();
		Matrix4f m2 = new Matrix4f();
		m2.setIdentity();
		Matrix4f m3 = new Matrix4f();
		m1.scale(new Vector3f(scale, scale, scale));
		m2.translate(new Vector3f(0f, 0f, -Globals.GUI_Z));
		Matrix4f.mul(m2, m1, m3);
		m2.load(m3);
		m3.setIdentity();
		m3.translate(new Vector3f(-width/2f, -height/2f, 0f));
		Matrix4f.mul(m2, m3, m1);
		m1.store(matrix_buf);
		matrix_buf.rewind();
	}
	for (int i = 0; i < delegate_stack.size(); i++) {
		((CameraDelegate)delegate_stack.get(i)).displayChanged(width, height);
	}
}
 
Example 4
Source File: Maths.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public static void updateViewMatrix(Matrix4f viewMatrix, float x, float y, float z, float pitch, float yaw){
	viewMatrix.setIdentity();
	Matrix4f.rotate((float) Math.toRadians(pitch), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
	Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
	Vector3f negativeCameraPos = new Vector3f(-x, -y, -z);
	Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
 
Example 5
Source File: Camera.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
private void updateViewMatrix() {
	viewMatrix.setIdentity();
	Matrix4f.rotate((float) Math.toRadians(pitch.get()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
	Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
	Vector3f negativeCameraPos = new Vector3f(-position.x, -position.y, -position.z);
	Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
 
Example 6
Source File: MouseActions.java    From ldparteditor with MIT License 5 votes vote down vote up
public void translateViewport(float dx, float dy, Matrix4f viewport_translation, Matrix4f viewport_rotation,
        PerspectiveCalculator perspective) {
    Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f);
    Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
    Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null);
    Matrix4f.transform(ovr_inverse2, xAxis4f_translation, xAxis4f_translation);
    Matrix4f.transform(ovr_inverse2, yAxis4f_translation, yAxis4f_translation);
    Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z);
    Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);
    Matrix4f.load(old_viewport_translation, viewport_translation);
    Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation);
    Matrix4f.translate(yAxis3, viewport_translation, viewport_translation);
    perspective.calculateOriginData();
}
 
Example 7
Source File: KeyStateManager.java    From ldparteditor with MIT License 5 votes vote down vote up
private static void translateView(Composite3D c3d, float dx, float dy) {
    PerspectiveCalculator perspective = c3d.getPerspectiveCalculator();
    Matrix4f viewport_rotation = c3d.getRotation();
    Matrix4f viewport_translation = c3d.getTranslation();
    Matrix4f old_viewport_translation = new Matrix4f();
    Matrix4f.load(c3d.getTranslation(), old_viewport_translation);
    Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f);
    Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f);
    Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null);
    Matrix4f.transform(ovr_inverse2, xAxis4f_translation, xAxis4f_translation);
    Matrix4f.transform(ovr_inverse2, yAxis4f_translation, yAxis4f_translation);
    Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z);
    Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z);
    Matrix4f.load(old_viewport_translation, viewport_translation);
    Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation);
    Matrix4f.translate(yAxis3, viewport_translation, viewport_translation);
    perspective.calculateOriginData();
    c3d.getVertexManager().getResetTimer().set(true);
    if (c3d.isSyncTranslation()) {
        float tx = c3d.getTranslation().m30;
        float ty = c3d.getTranslation().m31;
        float tz = c3d.getTranslation().m32;
        for (OpenGLRenderer renderer : Editor3DWindow.getRenders()) {
            Composite3D c3d2 = renderer.getC3D();
            if (!c3d2.isDisposed() && c3d != c3d2 && c3d.getLockableDatFileReference().equals(c3d2.getLockableDatFileReference())) {
                c3d2.getTranslation().m30 = tx;
                c3d2.getTranslation().m31 = ty;
                c3d2.getTranslation().m32 = tz;
                ((ScalableComposite) c3d2.getParent()).redrawScales();
                c3d2.getPerspectiveCalculator().initializeViewportPerspective();
            }
        }
    }
}
 
Example 8
Source File: GLMatrixStack.java    From ldparteditor with MIT License 5 votes vote down vote up
public void glTranslatef(float x, float y, float z) {

        Matrix4f.translate(new Vector3f(x, y, z), currentMatrix, currentMatrix);

        final FloatBuffer buf = BufferUtils.createFloatBuffer(16);
        currentMatrix.store(buf);
        buf.position(0);

        int model = shader.getUniformLocation("model" ); //$NON-NLS-1$
        GL20.glUniformMatrix4fv(model, false, buf);
    }
 
Example 9
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Matrix4f createLookAt(Vector3f eye, Vector3f lookAt, Vector3f up)
{
	Matrix4f matrix = new Matrix4f();
	matrix.setIdentity();
	
	// Create the basis vectors
	Vector3f forwards = Vector3f.sub(eye, lookAt, null);
	forwards.normalise();
	
	Vector3f right = Vector3f.cross(up, forwards, null);
	right.normalise();
	
	Vector3f actualUp = Vector3f.cross(forwards, right, null);
	actualUp.normalise();
	
	// Right vector across the top
	matrix.m00 = right.x;
	matrix.m10 = right.y;
	matrix.m20 = right.z;
	
	// Up vector across the middle row
	matrix.m01 = actualUp.x;
	matrix.m11 = actualUp.y;
	matrix.m21 = actualUp.z;
	
	// Forwards vector across the bottom row
	matrix.m02 = forwards.x;
	matrix.m12 = forwards.y;
	matrix.m22 = forwards.z;
	
	// Negative translation in the last column
	Matrix4f translation = new Matrix4f();
	translation.setIdentity();
	translation.translate(new Vector3f(-eye.x, -eye.y, -eye.z));
	
	return Matrix4f.mul(matrix, translation, null);
}
 
Example 10
Source File: SubMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static Matrix4f createTransform(Rotation horizontalRotation, final float horizontalAngleDeg,
										Rotation verticalRotation, final float verticalAngleDeg)
{
	if (horizontalRotation == Rotation.None && verticalRotation == Rotation.None)
		return null;
	
	float horizontalAngleInRads = horizontalAngleDeg / 360.0f * 2.0f * (float)Math.PI;
	if (horizontalRotation == Rotation.AntiClockwise)
		horizontalAngleInRads *= -1.0f;
	
	float verticalAngleInRads = verticalAngleDeg / 360.0f * 2.0f * (float)Math.PI;
	if (verticalRotation == Rotation.AntiClockwise)
		verticalAngleInRads *= -1.0f;
	
	Matrix4f trans0 = new Matrix4f();
	trans0.translate(new Vector3f(+0.5f, +0.5f, +0.5f));
	
	Matrix4f horizontalRotate = new Matrix4f();
	horizontalRotate.rotate(horizontalAngleInRads, new Vector3f(0, 1, 0));
	
	Matrix4f verticalRotate = new Matrix4f();
	verticalRotate.rotate(verticalAngleInRads, new Vector3f(0, 0, 1));
	
	Matrix4f trans1 = new Matrix4f();
	trans1.translate(new Vector3f(-0.5f, -0.5f, -0.5f));
	
	Matrix4f combinedRotate = new Matrix4f();
	Matrix4f.mul(horizontalRotate, verticalRotate, combinedRotate);
	
	Matrix4f working = new Matrix4f();
	Matrix4f.mul(trans0, combinedRotate, working);
	
	Matrix4f actual = new Matrix4f();
	Matrix4f.mul(working, trans1, actual);
	
	
	
/*	Matrix4f working = new Matrix4f();
	Matrix4f.mul(trans0, rotate, working);
	
	Matrix4f actual = new Matrix4f();
	Matrix4f.mul(working, trans1, actual);
*/
	
	return actual;
}
 
Example 11
Source File: JointTransform.java    From OpenGL-Animation with The Unlicense 3 votes vote down vote up
/**
 * In this method the bone-space transform matrix is constructed by
 * translating an identity matrix using the position variable and then
 * applying the rotation. The rotation is applied by first converting the
 * quaternion into a rotation matrix, which is then multiplied with the
 * transform matrix.
 * 
 * @return This bone-space joint transform as a matrix. The exact same
 *         transform as represented by the position and rotation in this
 *         instance, just in matrix form.
 */
protected Matrix4f getLocalTransform() {
	Matrix4f matrix = new Matrix4f();
	matrix.translate(position);
	Matrix4f.mul(matrix, rotation.toRotationMatrix(), matrix);
	return matrix;
}