private Vector3f[] positionFromFloat16ArrayData(float[] inverseBindMatrixArray) { Vector3f[] translationVectorArray = new Vector3f[inverseBindMatrixArray.length / 16]; for (int i = 0; i < inverseBindMatrixArray.length / 16; ++i) { int offset = i * 16; Matrix4f matrix4f = new Matrix4f(Arrays.copyOfRange(inverseBindMatrixArray, offset, offset + 16)); Vector3f translationVector = matrix4f.getTranslation(); translationVectorArray[i] = translationVector; } return translationVectorArray; }
public static Matrix4f calcViewProjectionMatrix(Matrix4f vm, Matrix4f p) { Matrix4f result = new Matrix4f(); result.mul(p, vm); return result; }
public static Matrix4f calcModelViewMatrix(Matrix4f m, Matrix4f vm) { Matrix4f result = new Matrix4f(); result.mul(m, vm); return result; }
public static Matrix4f createPerspectiveProjectionMatrix(float fovY, float aspectRatio, float zNear, float zFar) { Matrix4f m = new Matrix4f(); float f = 1.0f / (float) Math.tan((double) fovY * 0.5f); m.m00 = f / aspectRatio; m.m10 = 0; m.m20 = 0; m.m30 = 0; m.m01 = 0; m.m11 = f; m.m21 = 0; m.m31 = 0; m.m02 = 0; m.m12 = 0; m.m22 = (zFar + zNear) / (zNear - zFar); m.m32 = (2 * zFar * zNear) / (zNear - zFar); m.m03 = 0; m.m13 = 0; m.m23 = -1; m.m33 = 0; m.transpose(); return m; }
private Quat4f[] quad4fArrayFromFloat16ArrayData(float[] inverseBindMatrixArray) { Quat4f[] rotationArray = new Quat4f[inverseBindMatrixArray.length / 16]; for (int i = 0; i < inverseBindMatrixArray.length / 16; ++i) { int offset = i * 16; Matrix4f matrix4f = new Matrix4f(Arrays.copyOfRange(inverseBindMatrixArray, offset, offset + 16)); Quat4f rotation = new Quat4f(); rotation.set(matrix4f); rotationArray[i] = rotation; } return rotationArray; }
public static Matrix4f createOrthogonalProjectionMatrix(float left, float right, float top, float bottom, float near, float far) { Matrix4f m = new Matrix4f(); float lateral = right - left; float vertical = top - bottom; float forward = far - near; float tx = -(right + left) / (right - left); float ty = -(top + bottom) / (top - bottom); float tz = -(far + near) / (far - near); m.m00 = 2.0f / lateral; m.m10 = 0.0f; m.m20 = 0.0f; m.m30 = tx; m.m01 = 0.0f; m.m11 = 2.0f / vertical; m.m21 = 0.0f; m.m31 = ty; m.m02 = 0.0f; m.m12 = 0.0f; m.m22 = -2.0f / forward; m.m32 = tz; m.m03 = 0.0f; m.m13 = 0.0f; m.m23 = 0.0f; m.m33 = 1.0f; m.transpose(); return m; }
@Override public void generate(BlockManager blockManager, CoreChunk view, Random rand, int posX, int posY, int posZ) { Vector3f position = new Vector3f(0f, 0f, 0f); Matrix4f rotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, 1f), (float) Math.PI / 2f), Vector3f.ZERO, 1.0f); float angleOffset = rand.nextFloat(-MAX_ANGLE_OFFSET, MAX_ANGLE_OFFSET); Block bark = blockManager.getBlock(barkType); Block leaf = blockManager.getBlock(leafType); recursiveGenerator.recurse(view, rand, posX, posY, posZ, angleOffset, new CharSequenceIterator(initialAxiom), position, rotation, bark, leaf, 0, this); }
viewProjectionMatrixRightEye = MatrixUtils.calcViewProjectionMatrix(viewMatrixRightEye, projectionMatrixRightEye); inverseViewProjectionMatrixLeftEye = new Matrix4f(viewProjectionMatrixLeftEye); inverseViewProjectionMatrixRightEye = new Matrix4f(viewProjectionMatrixRightEye); inverseViewProjectionMatrixLeftEye.invert(viewProjectionMatrixLeftEye); inverseViewProjectionMatrixRightEye.invert(viewProjectionMatrixRightEye); inverseProjectionMatrixLeftEye = new Matrix4f(projectionMatrixLeftEye); inverseProjectionMatrixRightEye = new Matrix4f(projectionMatrixRightEye); inverseProjectionMatrixLeftEye.invert(projectionMatrixLeftEye); inverseProjectionMatrixRightEye.invert(projectionMatrixRightEye);
public void recurse(CoreChunk view, Random rand, int posX, int posY, int posZ, float angleOffset, CharSequenceIterator axiomIterator, Vector3f position, Matrix4f rotation, Block bark, Block leaf, int depth, AbstractTreeGenerator treeGenerator) { Matrix4f tempRotation = new Matrix4f(); while (axiomIterator.hasNext()) { char c = axiomIterator.nextChar(); break; case '[': recurse(view, rand, posX, posY, posZ, angleOffset, axiomIterator, new Vector3f(position), new Matrix4f(rotation), bark, leaf, depth, treeGenerator); break; case ']': return; case '+': tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, 1f), angle + angleOffset), Vector3f.ZERO, 1.0f); rotation.mul(tempRotation); break; case '-': tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, -1f), angle + angleOffset), Vector3f.ZERO, 1.0f); rotation.mul(tempRotation); break; case '&': tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, 1f, 0f), angle + angleOffset), Vector3f.ZERO, 1.0f); rotation.mul(tempRotation); break; case '^': tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, -1f, 0f), angle + angleOffset), Vector3f.ZERO, 1.0f); rotation.mul(tempRotation); break; case '*':
centerOffset.scale(-1.0f); Matrix4f centerTransform = new Matrix4f(BaseQuat4f.IDENTITY, centerOffset, 1.0f); Matrix4f userTransform = new Matrix4f(rotation, offset, -fitScale * scale); Matrix4f translateTransform = new Matrix4f(BaseQuat4f.IDENTITY, new Vector3f((drawRegion.minX() + drawRegion.width() / 2) * uiScale, (drawRegion.minY() + drawRegion.height() / 2) * uiScale, 0), 1); translateTransform.mul(userTransform); Matrix4f finalMat = new Matrix4f(modelView); finalMat.mul(translateTransform); MatrixUtils.matrixToFloatBuffer(finalMat, matrixBuffer);
public static Matrix4f createViewMatrix(Vector3f eye, Vector3f center, Vector3f up) { Matrix4f m = new Matrix4f();
@Override public void renderOverlay() { if (entityToRegionOutlineMap.isEmpty()) { return; // skip everything if there is nothing to do to avoid possibly costly draw mode changes } glDisable(GL_DEPTH_TEST); glLineWidth(2); Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition(); FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16); FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12); material.setFloat("sunlight", 1.0f, true); material.setFloat("blockLight", 1.0f, true); material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix()); Vector3f worldPos = new Vector3f(); Vector3f worldPositionCameraSpace = new Vector3f(); worldPositionCameraSpace.sub(worldPos, cameraPosition); Matrix4f matrixCameraSpace = new Matrix4f(new Quat4f(0, 0, 0, 1), worldPositionCameraSpace, 1.0f); Matrix4f modelViewMatrix = MatrixUtils.calcModelViewMatrix(worldRenderer.getActiveCamera().getViewMatrix(), matrixCameraSpace); MatrixUtils.matrixToFloatBuffer(modelViewMatrix, tempMatrixBuffer44); material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true); MatrixUtils.matrixToFloatBuffer(MatrixUtils.calcNormalMatrix(modelViewMatrix), tempMatrixBuffer33); material.setMatrix3("normalMatrix", tempMatrixBuffer33, true); for (RegionOutlineComponent regionOutline: entityToRegionOutlineMap.values()) { material.setFloat3("colorOffset", regionOutline.color.rf(), regionOutline.color.gf(), regionOutline.color.bf(), true); drawRegionOutline(regionOutline); } glEnable(GL_DEPTH_TEST); }
Matrix4f matrixCameraSpace = new Matrix4f(worldRot, worldPositionCameraSpace, worldScale);
@Override public void preRender() { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 0, 2048f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); modelView = new Matrix4f(); modelView.setIdentity(); modelView.setTranslation(new Vector3f(0, 0, -1024f)); MatrixUtils.matrixToFloatBuffer(modelView, matrixBuffer); glLoadMatrix(matrixBuffer); matrixBuffer.rewind(); glScalef(uiScale, uiScale, uiScale); requestedCropRegion = Rect2i.createFromMinAndSize(0, 0, Display.getWidth(), Display.getHeight()); currentTextureCropRegion = requestedCropRegion; textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY()); }
Matrix4f matrixCameraSpace = new Matrix4f(worldRot, offsetFromCamera, worldScale);
Matrix4f matrixCameraSpace = new Matrix4f(new Quat4f(0, 0, 0, 1), worldPositionCameraSpace, worldScale);
Matrix4f modelMatrix = new Matrix4f();