private Vector3d getXzNormal() { if (this.xzNormal == null) { this.xzNormal = this.xNormal.add(this.zNormal).normalize(); } return this.xzNormal; }
private Vector3d getXyNormal() { if (this.xyNormal == null) { this.xyNormal = this.xNormal.add(this.yNormal).normalize(); } return this.xyNormal; }
private Vector3d getYzNormal() { if (this.yzNormal == null) { this.yzNormal = this.yNormal.add(this.zNormal).normalize(); } return this.yzNormal; }
/** * Sets the direction. This or setting the ending location is required * and can only be done once. * * @param direction The direction * @return This for chained calls */ public BlockRayBuilder<E> direction(Vector3d direction) { checkState(this.direction == null, "Direction has already been set"); checkNotNull(direction, "direction"); checkArgument(direction.lengthSquared() != 0, "Direction must be a non-zero vector"); this.direction = direction.normalize(); return this; }
private Vector3d getXyzNormal() { if (this.xyzNormal == null) { this.xyzNormal = this.xNormal.add(this.yNormal).add(this.zNormal).normalize(); } return this.xyzNormal; }
/** * Sets the direction and ending location. This or setting the direction * is required and can only be done once. * * @param end The ending location * @return This for chained calls */ public BlockRayBuilder<E> to(Vector3d end) { checkState(this.direction == null, "Direction has already been set"); checkNotNull(end, "end"); checkArgument(!this.position.equals(end), "Start and end cannot be equal"); this.direction = end.sub(this.position).normalize(); return stopFilter(new TargetBlockFilter<>(end)); }
/** * Returns whether the given vector is along this axis. * * @param vector The vector to test * @return True if it is along this axis */ public boolean isVectorAlongAxis(final Vector3d vector) { return vector.abs().normalize().sub(this.direction).lengthSquared() == 0; }
Direction(Vector3d direction, Division division) { if (direction.lengthSquared() == 0) { // Prevent normalization of the zero direction this.offset = direction; } else { this.offset = direction.normalize(); } this.blockOffset = direction.round().toInt(); this.division = division; }
vector = vector.normalize();
@Test public void testIntersectsRay() { final AABB aabb = new AABB(new Vector3d(0, 0, 0), new Vector3d(2, 2, 2)); Assert.assertEquals(new Tuple<>(new Vector3d(2, 1, 1), new Vector3d(1, 0, 0)), aabb.intersects(new Vector3d(1, 1, 1), new Vector3d(1, 0, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 2, 1), new Vector3d(0, 1, 0)), aabb.intersects(new Vector3d(1, 1, 1), new Vector3d(0, 1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 1, 2), new Vector3d(0, 0, 1)), aabb.intersects(new Vector3d(1, 1, 1), new Vector3d(0, 0, 1)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(0, 0, 0), new Vector3d(-1, -1, -1).normalize()), aabb.intersects(new Vector3d(-1, -1, -1), new Vector3d(1, 1, 1)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(0, 0, 1), new Vector3d(-1, -1, -0.0).normalize()), aabb.intersects(new Vector3d(-1, -1, 1), new Vector3d(1, 1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(0, 1, 1), new Vector3d(-1, -0.0, -0.0)), aabb.intersects(new Vector3d(-1, 1, 1), new Vector3d(1, 0, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(2, 1, 1), new Vector3d(1, 0, 0)), aabb.intersects(new Vector3d(3, 1, 1), new Vector3d(-1, 0, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 0, 1), new Vector3d(-0.0, -1, -0.0)), aabb.intersects(new Vector3d(1, -1, 1), new Vector3d(0, 1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 2, 1), new Vector3d(0, 1, 0)), aabb.intersects(new Vector3d(1, 3, 1), new Vector3d(0, -1, 0)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 1, 0), new Vector3d(-0.0, -0.0, -1)), aabb.intersects(new Vector3d(1, 1, -1), new Vector3d(0, 0, 1)).get()); Assert.assertEquals(new Tuple<>(new Vector3d(1, 1, 2), new Vector3d(0, 0, 1)), aabb.intersects(new Vector3d(1, 1, 3), new Vector3d(0, 0, -1)).get()); Assert.assertFalse(aabb.intersects(new Vector3d(-1, -1, -1), new Vector3d(0, 1, 0)).isPresent()); }
normal = normalMin; normal = normal.normalize();
private Vector3d getXyNormal() { if (this.xyNormal == null) { this.xyNormal = this.xNormal.add(this.yNormal).normalize(); } return this.xyNormal; }
private Vector3d getXzNormal() { if (this.xzNormal == null) { this.xzNormal = this.xNormal.add(this.zNormal).normalize(); } return this.xzNormal; }
private Vector3d getYzNormal() { if (this.yzNormal == null) { this.yzNormal = this.yNormal.add(this.zNormal).normalize(); } return this.yzNormal; }
/** * Sets the direction. This or setting the ending location is required and can only be done once. * * @param direction The direction * @return This for chained calls */ public BlockRayBuilder<E> direction(Vector3d direction) { checkState(this.direction == null, "Direction has already been set"); checkNotNull(direction, "direction"); checkArgument(direction.lengthSquared() != 0, "Direction must be a non-zero vector"); this.direction = direction.normalize(); return this; }
private Vector3d getXyzNormal() { if (this.xyzNormal == null) { this.xyzNormal = this.xNormal.add(this.yNormal).add(this.zNormal).normalize(); } return this.xyzNormal; }
/** * Returns whether the given vector is along this axis. * * @param vector The vector to test * @return True if it is along this axis */ public boolean isVectorAlongAxis(final Vector3d vector) { return vector.abs().normalize().sub(this.direction).lengthSquared() == 0; }
Direction(Vector3d direction, Division division) { if (direction.lengthSquared() == 0) { // Prevent normalization of the zero direction this.offset = direction; } else { this.offset = direction.normalize(); } this.blockOffset = direction.round().toInt(); this.division = division; }
private void doFireball(final SnipeData v) { Player pl = v.owner().getPlayer(); Vector3d target = this.targetBlock.getPosition().sub(pl.getLocation().getPosition().add(0, 1.72, 0)); pl.launchProjectile(SmallFireball.class, target.normalize()); }
private void doLargeFireball(final SnipeData v) { Player pl = v.owner().getPlayer(); Vector3d target = this.targetBlock.getPosition().sub(pl.getLocation().getPosition().add(0, 1.72, 0)); pl.launchProjectile(LargeFireball.class, target.normalize()); }