Removes some unnecessary calculation when converting relative vectors to real vectors

This commit is contained in:
Kristian Knarvik 2021-12-03 23:23:19 +01:00
parent a7dc02eef0
commit 5d1d6ffaf0

View File

@ -113,16 +113,21 @@ public final class DirectionHelper {
* @return <p>A normal vector</p> * @return <p>A normal vector</p>
*/ */
public static Vector getCoordinateVectorFromRelativeVector(double right, double down, double out, double yaw) { public static Vector getCoordinateVectorFromRelativeVector(double right, double down, double out, double yaw) {
Vector distanceVector = DirectionHelper.getDirectionVectorFromYaw(yaw); if (yaw == 0) {
distanceVector.multiply(out); //South
return new Vector(right, -down, out);
Vector rightVector = DirectionHelper.getDirectionVectorFromYaw(yaw - 90); } else if (yaw == 90) {
rightVector.multiply(right); //West
return new Vector(-out, -down, right);
Vector depthVector = new Vector(0, -1, 0); } else if (yaw == 180) {
depthVector.multiply(down); //North
return new Vector(-right, -down, -out);
return distanceVector.add(rightVector).add(depthVector); } else if (yaw == 270) {
//East
return new Vector(out, -down, -right);
} else {
throw new IllegalArgumentException(String.format("Invalid yaw %f given", yaw));
}
} }
/** /**