/** * Returns the position of the intersection. * * @return The intersection coordinates */ public Vector3d getPosition() { if (this.position == null) { this.position = new Vector3d(this.x, this.y, this.z); } return this.position; }
/** * Create a new instance. * * @param extent The extent * @param x The X-axis position * @param y The Y-axis position * @param z The Z-axis position */ public Location(E extent, double x, double y, double z) { this(extent, new Vector3d(x, y, z)); }
@Override default Location<World> getLocation(double x, double y, double z) { return getLocation(new Vector3d(x, y, z)); }
/** * Create a Sponge rotation from a WorldEdit location. * * @param location the WorldEdit location * @return a Sponge rotation */ public static Vector3d adaptRotation(Location location) { checkNotNull(location); return new Vector3d(location.getPitch(), location.getYaw(), 0); }
@Test public void testContainsVector3d() { final AABB aabb = new AABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13)); Assert.assertTrue(aabb.contains(new Vector3d(5, 3, 11))); Assert.assertFalse(aabb.contains(new Vector3d(-1, 3, 11))); Assert.assertFalse(aabb.contains(new Vector3d(5, 11, 11))); Assert.assertFalse(aabb.contains(new Vector3d(5, 3, 14))); }
private static AABB newAABB() { final Vector3d min = new Vector3d(RANDOM.nextDouble() * 20 - 10, RANDOM.nextDouble() * 20 - 10, RANDOM.nextDouble() * 20 - 10); return new AABB(min, min.add(RANDOM.nextDouble() * 4 + 4, RANDOM.nextDouble() * 4 + 4, RANDOM.nextDouble() * 4 + 4)); }
private static Vector3d toAxesAngles(Quaterniond quaternion) { final Vector3d axesAngles = quaternion.getAxesAnglesDeg(); return new Vector3d(axesAngles.getX(), -axesAngles.getY(), axesAngles.getZ()); }
@Override public void setPosition(Vector3 pos, float pitch, float yaw) { org.spongepowered.api.world.Location<World> loc = new org.spongepowered.api.world.Location<>( this.player.getWorld(), pos.getX(), pos.getY(), pos.getZ() ); this.player.setLocationAndRotation(loc, new Vector3d(pitch, yaw, 0)); }
@Test public void testContainsVector3i() { final AABB aabb = new AABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13)); Assert.assertTrue(aabb.contains(new Vector3i(5, 3, 11))); Assert.assertFalse(aabb.contains(new Vector3i(-1, 3, 11))); Assert.assertFalse(aabb.contains(new Vector3i(5, 11, 11))); Assert.assertFalse(aabb.contains(new Vector3i(5, 3, 14))); }
@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()); }
@Test public void testContainsCoordinates() { final AABB aabb = new AABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13)); Assert.assertTrue(aabb.contains(5, 3, 11)); Assert.assertTrue(aabb.contains(7, 3, 11)); Assert.assertTrue(aabb.contains(5, 4, 11)); Assert.assertTrue(aabb.contains(5, 3, 13)); Assert.assertFalse(aabb.contains(-1, 3, 11)); Assert.assertFalse(aabb.contains(5, 11, 11)); Assert.assertFalse(aabb.contains(5, 3, 14)); }
@Test public void testOfVector3d() { final Vector3d vecGray = new Vector3d(128.0, 128.459, 127.5); final Color colorGray = Color.of(vecGray); assertTrue(Color.GRAY.equals(colorGray)); }