private FacingToRotation( Vector3f rot ) { this.rot = rot; this.mat = TRSRTransformation .toVecmath( new org.lwjgl.util.vector.Matrix4f().rotate( (float) Math.toRadians( rot.x ), new org.lwjgl.util.vector.Vector3f( 1, 0, 0 ) ) .rotate( (float) Math.toRadians( rot.y ), new org.lwjgl.util.vector.Vector3f( 0, 1, 0 ) ) .rotate( (float) Math.toRadians( rot.z ), new org.lwjgl.util.vector.Vector3f( 0, 0, 1 ) ) ); }
/** * Invert this matrix * @return this if successful, null otherwise */ public Matrix invert() { return invert(this, this); }
@Override public void renderTileEntityAt( T te, double x, double y, double z, float partialTicks, int destroyStage ) { Pair<ItemStack, Matrix4f> pair = this.f.apply( te ); if( pair != null && pair.getLeft() != null ) { GlStateManager.pushMatrix(); if( pair.getRight() != null ) { FloatBuffer matrix = BufferUtils.createFloatBuffer( 16 ); pair.getRight().store( matrix ); matrix.flip(); GlStateManager.multMatrix( matrix ); } Minecraft.getMinecraft().getRenderItem().renderItem( pair.getLeft(), TransformType.GROUND ); GlStateManager.popMatrix(); } }
@SideOnly(Side.CLIENT) public static Vec3d mouseToWorldRay(int mouseX, int mouseY, int width, int height) { double aspectRatio = ((double) width / (double) height); double fov = ((Minecraft.getMinecraft().gameSettings.fovSetting / 2d) + 11) * (Math.PI / 180); Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity(); double a = -((double) mouseX / (double) width - 0.5) * 2; double b = -((double) mouseY / (double) height - 0.5) * 2; double tanf = Math.tan(fov); float yawn = renderViewEntity.rotationYaw; float pitch = renderViewEntity.rotationPitch; Matrix4f rot = new Matrix4f(); rot.rotate(yawn * (float) (Math.PI / 180), new Vector3f(0, -1, 0)); rot.rotate(pitch * (float) (Math.PI / 180), new Vector3f(1, 0, 0)); Vector4f foward = new Vector4f(0, 0, 1, 0); Vector4f up = new Vector4f(0, 1, 0, 0); Vector4f left = new Vector4f(1, 0, 0, 0); Matrix4f.transform(rot, foward, foward); Matrix4f.transform(rot, up, up); Matrix4f.transform(rot, left, left); return new Vec3d(foward.x, foward.y, foward.z) .addVector(left.x * tanf * aspectRatio * a, left.y * tanf * aspectRatio * a, left.z * tanf * aspectRatio * a) .addVector(up.x * tanf * b, up.y * tanf * b, up.z * tanf * b) .normalize(); }
public Trackball() { lastTransform = new Matrix4f(); }
private Matrix4f getTransform(float mouseX, float mouseY) { Preconditions.checkNotNull(dragStart, "Draging not started"); Vector3f current = calculateSpherePoint(mouseX, mouseY); float dot = Vector3f.dot(dragStart, current); if (Math.abs(dot - 1) < 0.0001) return lastTransform; Vector3f axis = Vector3f.cross(dragStart, current, null); try { axis.normalise(); } catch (IllegalStateException e) { // Zero length vector return lastTransform; } float angle = 2 * (float)(Math.acos(dot)); Matrix4f rotation = new Matrix4f(); rotation.rotate(angle, axis); return Matrix4f.mul(rotation, lastTransform, null); }
public Transformation(Orientation orientation) { final javax.vecmath.Matrix4f originalMatrix = new javax.vecmath.Matrix4f(); originalMatrix.set(orientation.getLocalToWorldMatrix()); asMatrix = TRSRTransformation.toLwjgl(originalMatrix); asBuffer = BufferUtils.createFloatBuffer(16); asMatrix.store(asBuffer); asBuffer.rewind(); asInverseMatrix = new Matrix4f(); Matrix4f.invert(asMatrix, asInverseMatrix); asInverseBuffer = BufferUtils.createFloatBuffer(16); asInverseMatrix.store(asInverseBuffer); asInverseBuffer.rewind(); } }
/** * Rotates the matrix around the given axis the specified angle * @param angle the angle, in radians. * @param axis The vector representing the rotation axis. Must be normalized. * @param dest The matrix to put the result, or null if a new matrix is to be created * @return The rotated matrix */ public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) { return rotate(angle, axis, this, dest); }
float determinant = src.determinant(); dest = new Matrix4f(); float determinant_inv = 1f/determinant; float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); float t02 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); float t03 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); float t10 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); float t11 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); float t12 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); float t13 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); float t20 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33); float t21 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, src.m33); float t22 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33); float t23 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, src.m32); float t30 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, src.m23); float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23); float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23); float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22);
/** * Translate this matrix and stash the result in another matrix * @param vec The vector to translate by * @param dest The destination matrix or null if a new matrix is to be created * @return the translated matrix */ public Matrix4f translate(Vector2f vec, Matrix4f dest) { return translate(vec, this, dest); }
@SideOnly(Side.CLIENT) public void SpawnVentParticles(float speed, EnumFacing side, int count) { for (int i = 0; i < count; i++) { Matrix4f rotation = new Matrix4f(); Vector3f offset = new Vector3f(); rotation.rotate((float) Math.PI / 2f, new Vector3f(0, 0, 1)); offset = new Vector3f(0.5f, 0.7f, 0.5f); } else if (side == EnumFacing.WEST) { rotation.rotate((float) Math.PI / 2f, new Vector3f(0, 0, 1)); offset = new Vector3f(-0.2f, 0.5f, 0.5f); } else if (side == EnumFacing.EAST) { rotation.rotate((float) Math.PI / 2f, new Vector3f(0, 0, -1)); offset = new Vector3f(1.2f, 0.5f, 0.5f); } else if (side == EnumFacing.SOUTH) { rotation.rotate((float) Math.PI / 2f, new Vector3f(1, 0, 0)); offset = new Vector3f(0.5f, 0.5f, 1.2f); } else if (side == EnumFacing.NORTH) { rotation.rotate((float) Math.PI / 2f, new Vector3f(-1, 0, 0)); offset = new Vector3f(0.5f, 0.5f, -0.2f); circle.scale(0.4f); Vector4f circleTransformed = new Vector4f(circle.x, circle.y, circle.z, 1); Matrix4f.transform(rotation, circleTransformed, circleTransformed);
/** * Translate the source matrix and stash the result in the destination matrix * @param vec The vector to translate by * @param src The source matrix * @param dest The destination matrix or null if a new matrix is to be created * @return The translated matrix */ public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z; dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z; dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z; dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z; return dest; }
/** * Rotates the matrix around the given axis the specified angle * @param angle the angle, in radians. * @param axis The vector representing the rotation axis. Must be normalized. * @return this */ public Matrix4f rotate(float angle, Vector3f axis) { return rotate(angle, axis, this); }
/** * Translate this matrix * @param vec The vector to translate by * @return this */ public Matrix4f translate(Vector3f vec) { return translate(vec, this); }
Matrix4f rotationMat = new Matrix4f(); rotationMat.rotate(Minecraft.getMinecraft().getRenderViewEntity().rotationYaw * (float) (Math.PI / 180D), new Vector3f(0, -1, 0)); GlStateManager.enableBlend(); GlStateManager.pushMatrix(); Vector4f pos = new Vector4f((float) (getClampedSize(from) + 0.25), 0, 0, 1); Matrix4f.transform(rotationMat, pos, pos); GlStateManager.translate(pos.x, pos.y, pos.z); renderPlanet(from, viewerDistance); GlStateManager.pushMatrix(); pos = new Vector4f((float) -(getClampedSize(to) + 0.25), 0, 0, 1); Matrix4f.transform(rotationMat, pos, pos); GlStateManager.translate(pos.x, pos.y, pos.z); renderPlanet(to, viewerDistance);
/** * Translate the source matrix and stash the result in the destination matrix * @param vec The vector to translate by * @param src The source matrix * @param dest The destination matrix or null if a new matrix is to be created * @return The translated matrix */ public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m30 += src.m00 * vec.x + src.m10 * vec.y; dest.m31 += src.m01 * vec.x + src.m11 * vec.y; dest.m32 += src.m02 * vec.x + src.m12 * vec.y; dest.m33 += src.m03 * vec.x + src.m13 * vec.y; return dest; }
public static Matrix4f createEntityRotateMatrix(Entity entity) { double yaw = Math.toRadians(entity.rotationYaw - 180); double pitch = Math.toRadians(entity.rotationPitch); Matrix4f initial = new Matrix4f(); initial.rotate((float)pitch, new Vector3f(1, 0, 0)); initial.rotate((float)yaw, new Vector3f(0, 1, 0)); return initial; }
public static void rotateFromBlock(Matrix4f mat, IBlockAccess world, BlockPos pos) { if (world != null) { IBlockState blockState = world.getBlockState(pos); EnumFacing rotation = blockState.getValue(MOBlock.PROPERTY_DIRECTION); Vector3f axis = new Vector3f(0, 1, 0); if (rotation == EnumFacing.WEST) { mat.rotate(-(float) (Math.PI / 2), axis); } else if (rotation == EnumFacing.EAST) { mat.rotate((float) (Math.PI / 2), axis); } else if (rotation == EnumFacing.NORTH) { mat.rotate(-(float) (Math.PI), axis); } } }
/** * Translate this matrix and stash the result in another matrix * @param vec The vector to translate by * @param dest The destination matrix or null if a new matrix is to be created * @return the translated matrix */ public Matrix4f translate(Vector3f vec, Matrix4f dest) { return translate(vec, this, dest); }