/** * Gets the Vector3d with the given {@link AxisDirection}. * * @param axisDirection The direction along the axis. * @return the Vector3d */ public Vector3d toVector3dWithDirection(final AxisDirection axisDirection) { return this.direction.mul(axisDirection.getSignum()); }
/** * "Adds" a scale to this transform. Scales are multiplicative, so this * actually multiplies the current scale. * * <p>Returns the results as a new copy.</p> * * @param scale The scale to add * @return A new transform */ public Transform<E> addScale(Vector3d scale) { checkNotNull(scale, "scale"); return new Transform<>(getExtent(), getPosition(), getRotation(), getScale().mul(scale)); }
/** * "Adds" another transform to this one. This is equivalent to adding the * translation, rotation and scale individually. * * <p>Returns the results as a new copy.</p> * * @param other The transform to add * @return A new transform */ public Transform<E> add(Transform<E> other) { checkNotNull(other, "other"); return new Transform<>( getExtent(), getPosition().add(other.getPosition()), toAxesAngles(other.getRotationAsQuaternion().mul(getRotationAsQuaternion())), getScale().mul(other.getScale()) ); }
@Test public void testScale() { final Vector3d scale1 = new Vector3d(1, 2, 3); final Vector3d scale2 = new Vector3d(4, 5, 6); Transform<Extent> transform = new Transform<>(this.mockExtent1, Vector3d.ZERO, Vector3d.ZERO, scale1); assertEquals(scale1, transform.getScale()); transform = transform.addScale(scale2); assertEquals(scale2.mul(scale1), transform.getScale()); }
public Vector3d mul(float x, float y, float z) { return mul((double) x, (double) y, (double) z); }
@Override public Vector3d mul(double a) { return mul(a, a, a); }
@Override public Vector3d mul(double a) { return mul(a, a, a); }
public Vector3d mul(float a) { return mul((double) a); }
public Vector3d mul(Vector3d v) { return mul(v.x, v.y, v.z); }
public Vector3d mul(Vector3d v) { return mul(v.x, v.y, v.z); }
public Vector3d mul(float a) { return mul((double) a); }
public Vector3d mul(float x, float y, float z) { return mul((double) x, (double) y, (double) 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 Vector3d lerp(Vector3d a, Vector3d b, double 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 Vector3d lerp(Vector3d a, Vector3d b, double 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 Vector3d getAxesAnglesDeg() { return getAxesAnglesRad().mul(TrigMath.RAD_TO_DEG); }
/** * Gets the Vector3d with the given {@link AxisDirection}. * * @param axisDirection The direction along the axis. * @return the Vector3d */ public Vector3d toVector3dWithDirection(final AxisDirection axisDirection) { return this.direction.mul(axisDirection.getSignum()); }
/** * 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 Vector3d getAxesAnglesDeg() { return getAxesAnglesRad().mul(TrigMath.RAD_TO_DEG); }
/** * "Adds" a scale to this transform. * Scales are multiplicative, so * this actually multiplies the * current scale. * Returns the results as a new copy. * * @param scale The scale to add * @return A new transform */ public Transform<E> addScale(Vector3d scale) { checkNotNull(scale, "scale"); return new Transform<>(getExtent(), getPosition(), getRotation(), getScale().mul(scale)); } /**
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5); TippedArrow arrow = (TippedArrow) dispenser.getWorld().createEntityNaturally(EntityTypes.TIPPED_ARROW, location.getPosition()); arrow.offer(Keys.FIRE_TICKS, 5000); Vector3d arrowVelocity = face.asOffset().add(0, 0.1f, 0).normalize().mul(1.5f); arrow.setVelocity(arrowVelocity); try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM); dispenser.getWorld().spawnEntity(arrow); } return true; } return false; } }
@Listener public void onEntityMove(MoveEntityEvent event) { if(event.getTargetEntity().isOnGround()) { if(BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), event.getTargetEntity().getLocation().getRelative(Direction.DOWN).getBlock())) { FootprintData data = getFootprintData(event.getTargetEntity().getUniqueId()); if (data.canPlaceFootprint(event.getToTransform().getPosition())) { Vector3d footprintLocation = event.getToTransform().getPosition().add(0, 0.19, 0); //Flip these, it should 'roughly' rotate 90 or -90 degrees. Vector3d footOffset = new Vector3d(footprintLocation.getZ(), 0, footprintLocation.getX()).normalize().div(2); event.getTargetEntity().getWorld().spawnParticles(footprintParticle, footprintLocation.add(footOffset.mul(data.side ? -1 : 1))); data.position = event.getToTransform().getPosition(); data.side = !data.side; } } } }