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 ) ) ); }
/** * 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); }
/** * 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); }
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); } } }
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); }
@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(); }
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);
GlStateManager.pushMatrix(); Matrix4f rotationMat = new Matrix4f(); rotationMat.rotate(Minecraft.getMinecraft().getRenderViewEntity().rotationYaw * (float) (Math.PI / 180D), new Vector3f(0, -1, 0)); GlStateManager.enableBlend(); GlStateManager.pushMatrix();