mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Made Quats proper value type
This commit is contained in:
1 file changed
+31
-43
@@ -10,42 +10,26 @@
|
||||
*/
|
||||
package vazkii.botania.common.core.helper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Formatter;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Quat {
|
||||
public final class Quat {
|
||||
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public double s;
|
||||
|
||||
public Quat() {
|
||||
s = 1.0D;
|
||||
x = 0.0D;
|
||||
y = 0.0D;
|
||||
z = 0.0D;
|
||||
}
|
||||
|
||||
public Quat(Quat quat) {
|
||||
x = quat.x;
|
||||
y = quat.y;
|
||||
z = quat.z;
|
||||
s = quat.s;
|
||||
}
|
||||
public static final Quat IDENTITY = new Quat(0, 0, 0, 1);
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
public final double s;
|
||||
private final int hashCode;
|
||||
|
||||
public Quat(double d, double d1, double d2, double d3) {
|
||||
x = d1;
|
||||
y = d2;
|
||||
z = d3;
|
||||
s = d;
|
||||
}
|
||||
|
||||
public void set(Quat quat) {
|
||||
x = quat.x;
|
||||
y = quat.y;
|
||||
z = quat.z;
|
||||
s = quat.s;
|
||||
this.hashCode = Arrays.hashCode(new double[] { d, d1, d2, d3 } );
|
||||
}
|
||||
|
||||
public static Quat aroundAxis(double ax, double ay, double az, double angle) {
|
||||
@@ -54,43 +38,33 @@ public class Quat {
|
||||
return new Quat(Math.cos(angle), ax * d4, ay * d4, az * d4);
|
||||
}
|
||||
|
||||
public void multiply(Quat quat) {
|
||||
public Quat multiply(Quat quat) {
|
||||
double d = s * quat.s - x * quat.x - y * quat.y - z * quat.z;
|
||||
double d1 = s * quat.x + x * quat.s - y * quat.z + z * quat.y;
|
||||
double d2 = s * quat.y + x * quat.z + y * quat.s - z * quat.x;
|
||||
double d3 = s * quat.z - x * quat.y + y * quat.x + z * quat.s;
|
||||
s = d;
|
||||
x = d1;
|
||||
y = d2;
|
||||
z = d3;
|
||||
return new Quat(d1, d2, d3, d);
|
||||
}
|
||||
|
||||
public void rightMultiply(Quat quat) {
|
||||
public Quat rightMultiply(Quat quat) {
|
||||
double d = s * quat.s - x * quat.x - y * quat.y - z * quat.z;
|
||||
double d1 = s * quat.x + x * quat.s + y * quat.z - z * quat.y;
|
||||
double d2 = s * quat.y - x * quat.z + y * quat.s + z * quat.x;
|
||||
double d3 = s * quat.z + x * quat.y - y * quat.x + z * quat.s;
|
||||
s = d;
|
||||
x = d1;
|
||||
y = d2;
|
||||
z = d3;
|
||||
return new Quat(d1, d2, d3, d);
|
||||
}
|
||||
|
||||
public double mag() {
|
||||
return Math.sqrt(x * x + y * y + z * z + s * s);
|
||||
}
|
||||
|
||||
public void normalize() {
|
||||
public Quat normalize() {
|
||||
double d = mag();
|
||||
if (d == 0.0D) {
|
||||
return;
|
||||
return this;
|
||||
} else {
|
||||
d = 1.0D / d;
|
||||
x *= d;
|
||||
y *= d;
|
||||
z *= d;
|
||||
s *= d;
|
||||
return;
|
||||
return new Quat(x * d, y * d, z * d, s * d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +78,20 @@ public class Quat {
|
||||
vec.z = d3 * s - d * z - d1 * y + d2 * x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Quat
|
||||
&& ((Quat) o).x == this.x
|
||||
&& ((Quat) o).y == this.y
|
||||
&& ((Quat) o).z == this.z
|
||||
&& ((Quat) o).s == this.s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
Reference in new issue
Block a user