本文整理汇总了Java中org.bukkit.util.Vector.angle方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.angle方法的具体用法?Java Vector.angle怎么用?Java Vector.angle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.util.Vector
的用法示例。
在下文中一共展示了Vector.angle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTick
import org.bukkit.util.Vector; //导入方法依赖的package包/类
@Override
public void onTick() {
if (target.isDead()) {
return;
}
double speed = this.entity.getVelocity().length() * 0.9D + 0.14D;
Vector velocity = null;
Vector direction = this.entity.getVelocity().clone().normalize();
Vector targetDirection = this.target.getLocation().clone().add(new Vector(0, 0.5D, 0))
.subtract(this.entity.getLocation()).toVector();
Vector targetDirectionNorm = targetDirection.clone().normalize();
double angle = direction.angle(targetDirectionNorm);
if (angle < 0.12D) {
velocity = direction.clone().multiply(speed);
} else {
velocity = direction.clone().multiply((angle - 0.12D) / angle)
.add(targetDirectionNorm.clone().multiply(0.12D / angle)).normalize().multiply(speed);
}
this.entity.setVelocity(velocity.add(new Vector(0.0D, 0.03D, 0.0D)));
}
示例2: rotate
import org.bukkit.util.Vector; //导入方法依赖的package包/类
public static Vector rotate(Vector toRotate, double yawAngle, double pitchAngle) {
/*
x = mx + r * cos b * cos a
y = my + r * cos b * sin a
z = mz + r * sin b
*/
Vector zeroDegreeYaw = new Vector(1, 0, 0);
Vector zeroDegreePitch = new Vector(0, 1, 0);
double oldYaw = toRotate.angle(zeroDegreeYaw);
double oldPitch = toRotate.angle(zeroDegreePitch);
double yaw = oldYaw + yawAngle;
double pitch = oldPitch + pitchAngle;
double x = Math.cos(yaw) * Math.cos(pitch);
double z = Math.cos(yaw) * Math.sin(pitch);
double y = Math.sin(yaw);
System.out.println(x + " " + y + " " + z);
return new Vector(x, y, z);
}