本文整理匯總了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);
}