Fix Vector rotation

The Vector class' rotateAround methods were modifying the used variables during the rotation, which should not be the case. Bukkit's similar Vector class manages to do this correctly.
This commit is contained in:
MrGazdag 2021-07-04 17:18:17 +02:00 committed by GitHub
parent fe1bfaee93
commit 6cba2cb7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -327,8 +327,11 @@ public class Vector implements PublicCloneable<Vector> {
double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle);
this.y = angleCos * getY() - angleSin * getZ();
this.z = angleSin * getY() + angleCos * getZ();
double oldY = getY();
double oldZ = getZ();
this.y = angleCos * oldY - angleSin * oldZ;
this.z = angleSin * oldY + angleCos * oldZ;
return this;
}
@ -349,8 +352,11 @@ public class Vector implements PublicCloneable<Vector> {
double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle);
this.x = angleCos * getX() + angleSin * getZ();
this.z = -angleSin * getX() + angleCos * getZ();
double oldX = getX();
double oldZ = getZ();
this.x = angleCos * oldX + angleSin * oldZ;
this.z = -angleSin * oldX + angleCos * oldZ;
return this;
}
@ -371,8 +377,11 @@ public class Vector implements PublicCloneable<Vector> {
double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle);
this.x = angleCos * getX() - angleSin * getY();
this.y = angleSin * getX() + angleCos * getY();
double oldX = getX();
double oldY = getY();
this.x = angleCos * oldX - angleSin * oldY;
this.y = angleSin * oldX + angleCos * oldY;
return this;
}