@Override public Vector3f mul(float a) { return mul(a, a, a); }
@Override public Vector3f mul(float a) { return mul(a, a, a); }
public Vector3f mul(double a) { return mul((float) a); }
public Vector3f mul(Vector3f v) { return mul(v.x, v.y, v.z); }
public Vector3f mul(double a) { return mul((float) a); }
public Vector3f mul(double x, double y, double z) { return mul((float) x, (float) y, (float) z); }
public Vector3f mul(Vector3f v) { return mul(v.x, v.y, v.z); }
public Vector3f mul(double x, double y, double z) { return mul((float) x, (float) y, (float) z); }
/** * Calculates the linear interpolation between a and b with the given percent * * @param a The first know value * @param b The second know value * @param percent The percent * @return the interpolated vector */ public static Vector3f lerp(Vector3f a, Vector3f b, float percent) { return a.mul(1 - percent).add(b.mul(percent)); }
/** * Calculates the linear interpolation between a and b with the given percent * * @param a The first know value * @param b The second know value * @param percent The percent * @return the interpolated vector */ public static Vector3f lerp(Vector3f a, Vector3f b, float percent) { return a.mul(1 - percent).add(b.mul(percent)); }
/** * Returns the angles in degrees around the x, y and z axes that correspond to the rotation represented by this quaternion. * * @return The angle in degrees for each axis, stored in a vector, in the corresponding component */ public Vector3f getAxesAnglesDeg() { return getAxesAnglesRad().mul(TrigMath.RAD_TO_DEG); }
/** * Returns the angles in degrees around the x, y and z axes that correspond to the rotation represented by this quaternion. * * @return The angle in degrees for each axis, stored in a vector, in the corresponding component */ public Vector3f getAxesAnglesDeg() { return getAxesAnglesRad().mul(TrigMath.RAD_TO_DEG); }
@Override public void handle(McpeDropItem packet) { Health health = ensureAndGet(Health.class); if (!spawned || health.isDead()) { return; } if (packet.getItem().getItemType() == BlockTypes.AIR) { return; } // TODO: Events Optional<ItemStack> stackOptional = playerInventory.getStackInHand(); if (!stackOptional.isPresent()) { sendPlayerInventory(); return; } DroppedItem item = new VoxelwindDroppedItem(getLevel(), getPosition().add(0, 1.3, 0), getServer(), stackOptional.get()); item.setMotion(getDirectionVector().mul(0.4)); playerInventory.clearItem(playerInventory.getHeldInventorySlot()); }
/** * Creates a "look at" matrix for the given eye point. * * @param size The size of the matrix, minimum of 4 * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static MatrixNf createLookAt(int size, Vector3f eye, Vector3f at, Vector3f up) { if (size < 4) { throw new IllegalArgumentException("Minimum matrix size is 4"); } final Vector3f f = at.sub(eye).normalize(); up = up.normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f).normalize(); final MatrixNf mat = new MatrixNf(size); mat.set(0, 0, s.getX()); mat.set(0, 1, s.getY()); mat.set(0, 2, s.getZ()); mat.set(1, 0, u.getX()); mat.set(1, 1, u.getY()); mat.set(1, 2, u.getZ()); mat.set(2, 0, -f.getX()); mat.set(2, 1, -f.getY()); mat.set(2, 2, -f.getZ()); return mat.translate(eye.mul(-1).toVectorN()); }
/** * Creates a "look at" matrix for the given eye point. * * @param size The size of the matrix, minimum of 4 * @param eye The position of the camera * @param at The point that the camera is looking at * @param up The "up" vector * @return A rotational transform that corresponds to a camera looking at the given point */ public static MatrixNf createLookAt(int size, Vector3f eye, Vector3f at, Vector3f up) { if (size < 4) { throw new IllegalArgumentException("Minimum matrix size is 4"); } final Vector3f f = at.sub(eye).normalize(); up = up.normalize(); final Vector3f s = f.cross(up).normalize(); final Vector3f u = s.cross(f).normalize(); final MatrixNf mat = new MatrixNf(size); mat.set(0, 0, s.getX()); mat.set(0, 1, s.getY()); mat.set(0, 2, s.getZ()); mat.set(1, 0, u.getX()); mat.set(1, 1, u.getY()); mat.set(1, 2, u.getZ()); mat.set(2, 0, -f.getX()); mat.set(2, 1, -f.getY()); mat.set(2, 2, -f.getZ()); return mat.translate(eye.mul(-1).toVectorN()); }
@Override public void run(Entity entity) { Physics physics = entity.ensureAndGet(Physics.class); if (entity.getMotion().lengthSquared() > 0) { boolean onGroundPreviously = entity.isOnGround(); entity.setPositionFromSystem(entity.getPosition().add(entity.getMotion())); boolean onGroundNow = entity.isOnGround(); if (!onGroundPreviously && onGroundNow) { entity.setPositionFromSystem(new Vector3f(entity.getPosition().getX(), entity.getPosition().getFloorY(), entity.getPosition().getZ())); entity.setMotion(Vector3f.ZERO); } else { entity.setMotion(entity.getMotion().mul(1f - physics.getDrag())); if (!onGroundNow) { entity.setMotion(entity.getMotion().sub(0, physics.getGravity(), 0)); } } } } }