org.bukkit.util.Vector.dot()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.bukkit.util.Vector.dot()方法的一些代码示例,展示了Vector.dot()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.dot()方法的具体详情如下:
包路径:org.bukkit.util.Vector
类名称:Vector
方法名:dot

Vector.dot介绍

[英]Calculates the dot product of this vector with another. The dot product is defined as x1x2+y1y2+z1z2. The returned value is a scalar.
[中]计算这个向量与另一个向量的点积。点积定义为x1
x2+y1y2+z1z2。返回的值是标量。

代码示例

代码示例来源:origin: Bukkit/Bukkit

/**
 * Gets the angle between this vector and another in radians.
 *
 * @param other The other vector
 * @return angle in radians
 */
public float angle(Vector other) {
  double dot = dot(other) / (length() * other.length());
  return (float) Math.acos(dot);
}

代码示例来源:origin: SpigotMC/Spigot-API

/**
 * Gets the angle between this vector and another in radians.
 *
 * @param other The other vector
 * @return angle in radians
 */
public float angle(Vector other) {
  double dot = dot(other) / (length() * other.length());
  return (float) Math.acos(dot);
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      } else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      } else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      }
      else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

final double comp = velocity.dot(push.clone().normalize());
if (comp > factor) {
  velocity.multiply(.5);
  velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize())));
} else if (comp + factor * .5 > factor) {
  velocity.add(push.clone().multiply(factor - comp));

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      }
      else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      } else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      }
      else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      }
      else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      }
      else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

private void applyKnockBack(Vector starter, Vector n, org.bukkit.block.Block block, BlockFace blockFace) {
  if (block == null || block.getType() == org.bukkit.Material.AIR) {
    return;
  }
  if (this.knockBackBumper <= 0) {
    final Optional<BounceObject> optBounce = this.ball.getMeta().getBounceObjectController().getBounceObjectFromBlock(block);
    if (optBounce.isPresent() || this.ball.getMeta().isAlwaysBounceBack()) {
      Vector r = starter.clone().subtract(n.multiply(2 * starter.dot(n))).multiply(0.75);
      if (optBounce.isPresent()) {
        r = r.multiply(optBounce.get().getBounceModifier());
      }
      else {
        r = r.multiply(this.ball.getMeta().getModifiers().getBounceModifier());
      }
      final BallWallCollideEvent event = new BallWallCollideEvent(this.ball, block, blockFace, r.clone(), starter.clone());
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        this.setVelocity(r);
        ((CustomDesign) this.ball).revertAnimation = !((CustomDesign) this.ball).revertAnimation;
        this.knockBackBumper = 5;
      }
    }
  }
}

代码示例来源:origin: elBukkit/MagicPlugin

protected void reflect(Vector normal, double offset) {
  trackEntity = reflectTrackEntity;
  reorient = reflectReorient;
  if (reflectResetDistanceTraveled) distanceTravelled = 0;
  if (reflectTrackCursorRange >= 0) trackCursorRange = reflectTrackCursorRange;
  if (reflectTargetCaster) actionContext.setTargetsCaster(true);
  // Calculate angle of reflection
  if (normal != null) {
    velocity.multiply(-1);
    velocity = velocity.subtract(normal.multiply(2 * velocity.dot(normal))).normalize();
    velocity.multiply(-1);
    actionContext.getMage().sendDebugMessage(ChatColor.AQUA + "Projectile reflected: " + ChatColor.LIGHT_PURPLE
      + " with normal vector of " + TextUtils.printVector(normal), 4);
  } else {
    actionContext.getMage().sendDebugMessage(ChatColor.AQUA + "Projectile reflected");
  }
  // Offset position slightly to avoid hitting again
  actionContext.setTargetLocation(actionContext.getTargetLocation().add(velocity.clone().multiply(offset)));
  // actionContext.setTargetLocation(targetLocation.add(normal.normalize().multiply(2)));
  actionContext.playEffects("reflect");
  reflectCount++;
}

代码示例来源:origin: ProjectKorra/ProjectKorra

final double comp = velocity.dot(push.clone().normalize());
if (comp > factor) {
  velocity.multiply(.5);
  velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize())));
} else if (comp + factor * .5 > factor) {
  velocity.add(push.clone().multiply(factor - comp));

代码示例来源:origin: ProjectKorra/ProjectKorra

public static BlockFace getCardinalDirection(final Vector vector) {
  final BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
  Vector n, ne, e, se, s, sw, w, nw;
  w = new Vector(-1, 0, 0);
  n = new Vector(0, 0, -1);
  s = n.clone().multiply(-1);
  e = w.clone().multiply(-1);
  ne = n.clone().add(e.clone()).normalize();
  se = s.clone().add(e.clone()).normalize();
  nw = n.clone().add(w.clone()).normalize();
  sw = s.clone().add(w.clone()).normalize();
  final Vector[] vectors = { n, ne, e, se, s, sw, w, nw };
  double comp = 0;
  int besti = 0;
  for (int i = 0; i < vectors.length; i++) {
    final double dot = vector.dot(vectors[i]);
    if (dot > comp) {
      comp = dot;
      besti = i;
    }
  }
  return faces[besti];
}

代码示例来源:origin: ProjectKorra/ProjectKorra

boolean down = false;
final Vector norm = direction.clone().normalize();
if (norm.dot(new Vector(0, 1, 0)) == 1) {
  up = true;
} else if (norm.dot(new Vector(0, -1, 0)) == 1) {
  down = true;

相关文章