public Matrix4f getTransformation() { Matrix4f translationMatrix = new Matrix4f().translation(translation); Matrix4f scaleMatrix = new Matrix4f().scale(scale); Matrix4f rotationMatrix = new Matrix4f().rotate(rotation); return translationMatrix.mul(rotationMatrix.mul(scaleMatrix)); }
public Matrix4f getViewProjection() { Matrix4f cameraRotation = new Matrix4f().initRotation(forward, up); Matrix4f cameraTranslation = new Matrix4f().initTranslation(-pos.getX(), -pos.getY(), -pos.getZ()); return projection.mul(cameraRotation.mul(cameraTranslation)); }
public Matrix4f getTransformation() { Matrix4f translationMatrix = new Matrix4f().initTranslation(translation.getX(), translation.getY(), translation.getZ()); Matrix4f rotationMatrix = new Matrix4f().initRotation(rotation.getX(), rotation.getY(), rotation.getZ()); Matrix4f scaleMatrix = new Matrix4f().initScale(scale.getX(), scale.getY(), scale.getZ()); return translationMatrix.mul(rotationMatrix.mul(scaleMatrix)); }
public Matrix4f getProjectedTransformation() { Matrix4f transformationMatrix = getTransformation(); Matrix4f projectionMatrix = new Matrix4f().initProjection(fov, width, height, zNear, zFar); Matrix4f cameraRotation = new Matrix4f().initCamera(camera.getForward(), camera.getUp()); Matrix4f cameraTranslation = new Matrix4f() .initTranslation( -camera.getPos().getX(), -camera.getPos().getY(), -camera.getPos().getZ()); return projectionMatrix.mul(cameraRotation.mul(cameraTranslation.mul(transformationMatrix))); }
public void run() { adjustToScreenSize = (float) Math.min( jframe.getWidth(), jframe.getHeight()); // used here, since you can change the screen-Size Matrix4f newTranslation = new Matrix4f(); newTranslation.setIdentity(); Matrix4f oldcTranslation = new Matrix4f(); oldcTranslation = camera.getCameraMatrix(); // world z-Axis-turn if (mouseWorldTurn != null) { newTranslation.mul(mouseWorldTurn); mouseWorldTurn.setIdentity(); } // camera x-Axis-turn if (mouseTurn != null) { newTranslation.mul(mouseTurn); mouseTurn.setIdentity(); } // camera movement if (keyMove != null) { newTranslation.mul(keyMove); keyMove.setIdentity(); } newTranslation.mul(oldcTranslation); camera.setCameraMatrix(newTranslation); // something still appears to be wrong while turning // Trigger redrawing of the render window renderPanel.getCanvas().repaint(); }
private void setTransformation(Matrix4f transformation) { // Compute the modelview matrix by multiplying the camera matrix and // the transformation matrix of the object Matrix4f modelview = new Matrix4f(sceneManager.getCamera().getCameraMatrix()); modelview.mul(transformation); // Set modelview and projection matrices in shader gl.glUniformMatrix4fv( gl.glGetUniformLocation(activeShaderID, "modelview"), 1, false, transformationToFloat16(modelview), 0); gl.glUniformMatrix4fv( gl.glGetUniformLocation(activeShaderID, "projection"), 1, false, transformationToFloat16(sceneManager.getFrustum().getProjectionMatrix()), 0); }
public Matrix4f initRotation(float x, float y, float z) { Matrix4f rx = new Matrix4f(); Matrix4f ry = new Matrix4f(); Matrix4f rz = new Matrix4f(); x = (float) Math.toRadians(x); y = (float) Math.toRadians(y); z = (float) Math.toRadians(z); rz.m[0][0] = (float) Math.cos(z); rz.m[0][1] = -(float) Math.sin(z); rz.m[0][2] = 0; rz.m[0][3] = 0; rz.m[1][0] = (float) Math.sin(z); rz.m[1][1] = (float) Math.cos(z); rz.m[1][2] = 0; rz.m[1][3] = 0; rz.m[2][0] = 0; rz.m[2][1] = 0; rz.m[2][2] = 1; rz.m[2][3] = 0; rz.m[3][0] = 0; rz.m[3][1] = 0; rz.m[3][2] = 0; rz.m[3][3] = 1; rx.m[0][0] = 1; rx.m[0][1] = 0; rx.m[0][2] = 0; rx.m[0][3] = 0; rx.m[1][0] = 0; rx.m[1][1] = (float) Math.cos(x); rx.m[1][2] = -(float) Math.sin(x); rx.m[1][3] = 0; rx.m[2][0] = 0; rx.m[2][1] = (float) Math.sin(x); rx.m[2][2] = (float) Math.cos(x); rx.m[2][3] = 0; rx.m[3][0] = 0; rx.m[3][1] = 0; rx.m[3][2] = 0; rx.m[3][3] = 1; ry.m[0][0] = (float) Math.cos(y); ry.m[0][1] = 0; ry.m[0][2] = -(float) Math.sin(y); ry.m[0][3] = 0; ry.m[1][0] = 0; ry.m[1][1] = 1; ry.m[1][2] = 0; ry.m[1][3] = 0; ry.m[2][0] = (float) Math.sin(y); ry.m[2][1] = 0; ry.m[2][2] = (float) Math.cos(y); ry.m[2][3] = 0; ry.m[3][0] = 0; ry.m[3][1] = 0; ry.m[3][2] = 0; ry.m[3][3] = 1; m = rz.mul(ry.mul(rx)).getM(); return this; }