private static Quaterniond fromAxesAngles(Vector3d angles) { return Quaterniond.fromAxesAnglesDeg(angles.getX(), -angles.getY(), angles.getZ()); }
/** * Gets all the entities that are in the line of sight of the given entity, * up to a given distance. This ignores occluders like blocks or other * entities. That is to say, the returned entities might not actually be * visible. Only the entities that pass the filter test are added. * * @param looker The looking entity * @param distance The distance of the ray (from the start) * @param filter The filter test * @return The intersecting entities in no particular order, with the * associated intersection point and normal */ default Set<EntityHit> getIntersectingEntities(Entity looker, double distance, Predicate<EntityHit> filter) { checkNotNull(looker, "looker"); final Vector3d rotation = looker.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Optional<EyeLocationProperty> data = looker.getProperty(EyeLocationProperty.class); final Vector3d start = data.map(EyeLocationProperty::getValue).orElse(looker.getLocation().getPosition()); return getIntersectingEntities(start, direction, distance, filter); }
/** * Initializes a block ray builder for the entity's eye. * If the eye location isn't defined for the entity, the * regular location is used. This sets both the starting * point and direction. * * @param entity The entity * @return A new block ray builder */ public static BlockRayBuilder<World> from(Entity entity) { checkNotNull(entity, "entity"); final Vector3d rotation = entity.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Location<World> location = entity.getLocation(); final Optional<EyeLocationProperty> data = entity.getProperty(EyeLocationProperty.class); final Vector3d position = data.map(EyeLocationProperty::getValue).orElse(location.getPosition()); return from(location.getExtent(), position).direction(direction); }
@Test public void testRotation() { final Vector3d rotation1 = new Vector3d(20, 40, 60); final Quaterniond rotationQuat1 = Quaterniond.fromAxesAnglesDeg(rotation1.getX(), -rotation1.getY(), rotation1.getZ()); final Vector3d rotation2 = new Vector3d(45, 135, 225); final Quaterniond rotationQuat2 = Quaterniond.fromAxesAnglesDeg(rotation2.getX(), -rotation2.getY(), rotation2.getZ()); final Quaterniond rotationQuat1Plus2 = rotationQuat2.mul(rotationQuat1); final Vector3d axesAnglesDeg = rotationQuat1Plus2.getAxesAnglesDeg(); final Vector3d rotation1Plus2 = new Vector3d(axesAnglesDeg.getX(), -axesAnglesDeg.getY(), axesAnglesDeg.getZ()); Transform<Extent> transform = new Transform<>(this.mockExtent1, Vector3d.ZERO, rotation1); assertEquals(rotation1, transform.getRotation()); assertEquals(rotationQuat1, transform.getRotationAsQuaternion()); Assert.assertEquals(rotation1.getX(), transform.getPitch(), EPSILON); Assert.assertEquals(rotation1.getY(), transform.getYaw(), EPSILON); Assert.assertEquals(rotation1.getZ(), transform.getRoll(), EPSILON); transform = transform.addRotation(rotation2); assertEquals(rotationQuat1Plus2, transform.getRotationAsQuaternion()); assertEquals(rotation1Plus2, transform.getRotation()); }
/** * Creates a new quaternion from the float angles in degrees around the x, y and z axes. * * @param pitch The rotation around x * @param yaw The rotation around y * @param roll The rotation around z * @return The quaternion defined by the rotations around the axes */ public static Quaterniond fromAxesAnglesDeg(float pitch, float yaw, float roll) { return fromAxesAnglesDeg((double) pitch, (double) yaw, (double) roll); }
/** * Creates a new quaternion from the float angles in degrees around the x, y and z axes. * * @param pitch The rotation around x * @param yaw The rotation around y * @param roll The rotation around z * @return The quaternion defined by the rotations around the axes */ public static Quaterniond fromAxesAnglesDeg(float pitch, float yaw, float roll) { return fromAxesAnglesDeg((double) pitch, (double) yaw, (double) roll); }
private static Quaterniond fromAxesAngles(Vector3d angles) { return Quaterniond.fromAxesAnglesDeg(angles.getX(), -angles.getY(), angles.getZ()); } }
/** * Gets all the entities that are in the line of sight of the given entity, * up to a given distance. This ignores occluders like blocks or other * entities. That is to say, the returned entities might not actually be * visible. Only the entities that pass the filter test are added. * * @param looker The looking entity * @param distance The distance of the ray (from the start) * @param filter The filter test * @return The intersecting entities in no particular order, with the * associated intersection point and normal */ default Set<EntityHit> getIntersectingEntities(Entity looker, double distance, Predicate<EntityHit> filter) { checkNotNull(looker, "looker"); final Vector3d rotation = looker.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Optional<EyeLocationProperty> data = looker.getProperty(EyeLocationProperty.class); final Vector3d start = data.map(EyeLocationProperty::getValue).orElse(looker.getLocation().getPosition()); return getIntersectingEntities(start, direction, distance, filter); }
/** * Initializes a block ray builder for the entity's eye. * If the eye location isn't defined for the entity, the * regular location is used. This sets both the starting * point and direction. * * @param entity The entity * @return A new block ray builder */ public static BlockRayBuilder<World> from(Entity entity) { checkNotNull(entity, "entity"); final Vector3d rotation = entity.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Location<World> location = entity.getLocation(); final Optional<EyeLocationProperty> data = entity.getProperty(EyeLocationProperty.class); final Vector3d position = data.map(EyeLocationProperty::getValue).orElse(location.getPosition()); return from(location.getExtent(), position).direction(direction); }