vec4.getX(), vec4.getY(), vec4.getZ(),
/** * Transform vector by multiplying it by this transform and put result back * into vector. * * @param vector */ public final void transform(Vector4f vector) { if (vector.getW() != 1.0) { throw new RuntimeException("Final element of vector must be 1."); } double x = mat00 * vector.getX() + mat01 * vector.getY() + mat02 * vector.getZ() + mat03; double y = mat10 * vector.getX() + mat11 * vector.getY() + mat12 * vector.getZ() + mat13; double z = mat20 * vector.getX() + mat21 * vector.getY() + mat22 * vector.getZ() + mat23; vector.setX((float) x); vector.setY((float) y); vector.setZ((float) z); vector.setW(1.0f); }
/** * Transform vectorIn using this transform and store result in vectorOut. * * @param vectorIn * @param vectorOut */ public final void transform(Vector4f vectorIn, Vector4f vectorOut) { if (vectorIn != vectorOut) { vectorOut.setX((float) (mat00 * vectorIn.getX() + mat01 * vectorIn.getY() + mat02 * vectorIn.getZ() + mat03)); vectorOut.setY((float) (mat10 * vectorIn.getX() + mat11 * vectorIn.getY() + mat12 * vectorIn.getZ() + mat13)); vectorOut.setZ((float) (mat20 * vectorIn.getX() + mat21 * vectorIn.getY() + mat22 * vectorIn.getZ() + mat23)); vectorOut.setW(1.0f); } else { transform(vectorIn); } }
public static void assertVector4fEquals(String message, Vector4f expected, Vector4f actual, double delta) { assertEquals(message + " [X component]",expected.getX(), actual.getX(),delta); assertEquals(message + " [Y component]",expected.getY(), actual.getY(),delta); assertEquals(message + " [Z component]",expected.getZ(), actual.getZ(),delta); assertEquals(message + " [W component]", expected.getW(), actual.getW(), delta); }
/** * Multiply a 4x4 matrix by a 4x1 vector. Since result is stored in vector, the matrix must be 4x4. * @param matrix * @param vector */ public static void mult(DenseMatrix64F matrix, Vector4f vector) { if (matrix.numCols != 4 || matrix.numRows != 4) { throw new RuntimeException("Improperly sized matrices."); } float x = vector.getX(); float y = vector.getY(); float z = vector.getZ(); float w = vector.getW(); vector.setX((float) (matrix.get(0, 0) * x + matrix.get(0, 1) * y + matrix.get(0, 2) * z + matrix.get(0, 3) * w)); vector.setY((float) (matrix.get(1, 0) * x + matrix.get(1, 1) * y + matrix.get(1, 2) * z + matrix.get(1, 3) * w)); vector.setZ((float) (matrix.get(2, 0) * x + matrix.get(2, 1) * y + matrix.get(2, 2) * z + matrix.get(2, 3) * w)); vector.setW((float) (matrix.get(3, 0) * x + matrix.get(3, 1) * y + matrix.get(3, 2) * z + matrix.get(3, 3) * w)); }
private static int getIntersectSlot(Vec3d fromVec, Vec3d toVec, Matrix4f transform) { Matrix4f inv = new Matrix4f(); inv.invert(transform); // Convert the vectors into "minecart" space Vector4f to = new Vector4f((float) toVec.x, (float) toVec.y, (float) toVec.z, 1); inv.transform(to); Vector4f from = new Vector4f((float) fromVec.x, (float) fromVec.y, (float) fromVec.z, 1); inv.transform(from); Vector4f step = new Vector4f(); step.sub(to, from); step.scale(1 / 100.0f); // Now ray-trace to find where they intersect with the bounding box. for (int offset = 0; offset <= 100; offset++) { for (int i = 0; i < BOUNDS.length; i++) { AxisAlignedBB bb = BOUNDS[i]; if (bb.contains(new Vec3d(from.getX(), from.getY(), from.getZ()))) { // If we got the actual block itself then pretend nothing happened. return i - 1; } } from.add(step); } return -1; }