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 ) ) ); }
@SideOnly( Side.CLIENT ) private static Pair<ItemStack, Matrix4f> getRenderedItem( TileCharger tile ) { Matrix4f transform = new Matrix4f(); transform.translate( new Vector3f( 0.5f, 0.4f, 0.5f ) ); return new ImmutablePair<>( tile.getInternalInventory().getStackInSlot( 0 ), transform ); }
public Trackball() { lastTransform = new Matrix4f(); }
/** * 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; }
/** * 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; }
/** * Scales the source matrix and put the result in the destination matrix * @param vec The vector to scale by * @param src The source matrix * @param dest The destination matrix, or null if a new matrix is to be created * @return The scaled matrix */ public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m00 = src.m00 * vec.x; dest.m01 = src.m01 * vec.x; dest.m02 = src.m02 * vec.x; dest.m03 = src.m03 * vec.x; dest.m10 = src.m10 * vec.y; dest.m11 = src.m11 * vec.y; dest.m12 = src.m12 * vec.y; dest.m13 = src.m13 * vec.y; dest.m20 = src.m20 * vec.z; dest.m21 = src.m21 * vec.z; dest.m22 = src.m22 * vec.z; dest.m23 = src.m23 * vec.z; return dest; }
/** * Add two matrices together and place the result in a third matrix. * @param left The left source matrix * @param right The right source matrix * @param dest The destination matrix, or null if a new one is to be created * @return the destination matrix */ public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m00 = left.m00 + right.m00; dest.m01 = left.m01 + right.m01; dest.m02 = left.m02 + right.m02; dest.m03 = left.m03 + right.m03; dest.m10 = left.m10 + right.m10; dest.m11 = left.m11 + right.m11; dest.m12 = left.m12 + right.m12; dest.m13 = left.m13 + right.m13; dest.m20 = left.m20 + right.m20; dest.m21 = left.m21 + right.m21; dest.m22 = left.m22 + right.m22; dest.m23 = left.m23 + right.m23; dest.m30 = left.m30 + right.m30; dest.m31 = left.m31 + right.m31; dest.m32 = left.m32 + right.m32; dest.m33 = left.m33 + right.m33; return dest; }
/** * Subtract the right matrix from the left and place the result in a third matrix. * @param left The left source matrix * @param right The right source matrix * @param dest The destination matrix, or null if a new one is to be created * @return the destination matrix */ public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m00 = left.m00 - right.m00; dest.m01 = left.m01 - right.m01; dest.m02 = left.m02 - right.m02; dest.m03 = left.m03 - right.m03; dest.m10 = left.m10 - right.m10; dest.m11 = left.m11 - right.m11; dest.m12 = left.m12 - right.m12; dest.m13 = left.m13 - right.m13; dest.m20 = left.m20 - right.m20; dest.m21 = left.m21 - right.m21; dest.m22 = left.m22 - right.m22; dest.m23 = left.m23 - right.m23; dest.m30 = left.m30 - right.m30; dest.m31 = left.m31 - right.m31; dest.m32 = left.m32 - right.m32; dest.m33 = left.m33 - right.m33; return dest; }
/** * Negate this matrix and place the result in a destination matrix. * @param src The source matrix * @param dest The destination matrix, or null if a new matrix is to be created * @return The negated matrix */ public static Matrix4f negate(Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m00 = -src.m00; dest.m01 = -src.m01; dest.m02 = -src.m02; dest.m03 = -src.m03; dest.m10 = -src.m10; dest.m11 = -src.m11; dest.m12 = -src.m12; dest.m13 = -src.m13; dest.m20 = -src.m20; dest.m21 = -src.m21; dest.m22 = -src.m22; dest.m23 = -src.m23; dest.m30 = -src.m30; dest.m31 = -src.m31; dest.m32 = -src.m32; dest.m33 = -src.m33; return dest; } }
/** * Copy the source matrix to the destination matrix * @param src The source matrix * @param dest The destination matrix, or null of a new one is to be created * @return The copied matrix */ public static Matrix4f load(Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); dest.m00 = src.m00; dest.m01 = src.m01; dest.m02 = src.m02; dest.m03 = src.m03; dest.m10 = src.m10; dest.m11 = src.m11; dest.m12 = src.m12; dest.m13 = src.m13; dest.m20 = src.m20; dest.m21 = src.m21; dest.m22 = src.m22; dest.m23 = src.m23; dest.m30 = src.m30; dest.m31 = src.m31; dest.m32 = src.m32; dest.m33 = src.m33; return dest; }
dest = new Matrix4f();
dest = new Matrix4f(); float m00 = src.m00; float m01 = src.m10;
public Matrix4f getMatrixForOrientation(Orientation orientation) { final Transformation transformation = getTransformation(orientation); return new Matrix4f(transformation.asMatrix); }
public Matrix4f getInverseMatrixForOrientation(Orientation orientation) { final Transformation transformation = getTransformation(orientation); return new Matrix4f(transformation.asInverseMatrix); }
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; }
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(); } }
@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(); }
@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();
Matrix4f rotationMat = new Matrix4f(); rotationMat.rotate(Minecraft.getMinecraft().getRenderViewEntity().rotationYaw * (float) (Math.PI / 180D), new Vector3f(0, -1, 0)); GlStateManager.enableBlend();