Core/src/main/java/eu/univento/core/api/utils/Vectors.java

50 lines
1.5 KiB
Java

/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.core.api.utils;
import org.bukkit.util.Vector;
/**
* @author joethei
* @version 1.0
*/
final class Vectors {
private static Vector rotateAroundAxisX(Vector v, double angle) {
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double y = v.getY() * cos - v.getZ() * sin;
double z = v.getY() * sin + v.getZ() * cos;
return v.setY(y).setZ(z);
}
private static Vector rotateAroundAxisY(Vector v, double angle) {
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x = v.getX() * cos + v.getZ() * sin;
double z = v.getX() * -sin + v.getZ() * cos;
return v.setX(x).setZ(z);
}
private static Vector rotateAroundAxisZ(Vector v, double angle) {
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x = v.getX() * cos - v.getY() * sin;
double y = v.getX() * sin + v.getY() * cos;
return v.setX(x).setY(y);
}
public static Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) {
rotateAroundAxisX(v, angleX);
rotateAroundAxisY(v, angleY);
rotateAroundAxisZ(v, angleZ);
return v;
}
public static double angleToXAxis(Vector vector) {
return Math.atan2(vector.getX(), vector.getY());
}
}