Add Transform and client yaw helpers to Quaternion
Transform holds location, rotation and scale as the client's ArcObjectInfo does, with parent x local composition (sb.exe 0x6516C0). Quaternion.fromYaw matches the client's MakeRotateY and getYaw returns the angle it would need. Nothing uses them yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
74b2eaaaf2
commit
2078a5c344
2 files changed
+56
No files matched your search
@@ -1142,6 +1142,17 @@ public class Quaternion {
|
||||
return opposite(this);
|
||||
}
|
||||
|
||||
// Client MakeRotateY (Math.dll 0x10002960): w = cos θ/2, y = sin θ/2, radians.
|
||||
// Math rather than FastMath: FastMath.reduceSinAngle mis-reduces angles below -π.
|
||||
public static Quaternion fromYaw(float yaw) {
|
||||
return new Quaternion(0f, (float) Math.sin(yaw * 0.5), 0f, (float) Math.cos(yaw * 0.5));
|
||||
}
|
||||
|
||||
// The angle MakeRotateY would need to produce this rotation; characters send it as one float.
|
||||
public float getYaw() {
|
||||
return 2 * FastMath.atan2(y, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Quaternion clone() {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2026
|
||||
// https://www.magicbane.com
|
||||
|
||||
package engine.math;
|
||||
|
||||
// The client's placement (ArcObjectInfo +0x28/+0x34/+0x44, math::Transformation); see MBDATA/specs/WorldPlacement.md §7.
|
||||
|
||||
public class Transform {
|
||||
|
||||
public final Vector3fImmutable location;
|
||||
public final Quaternion rotation;
|
||||
public final Vector3f scale;
|
||||
|
||||
public Transform(Vector3fImmutable location, Quaternion rotation, Vector3f scale) {
|
||||
this.location = location;
|
||||
this.rotation = rotation;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public static Transform fromYaw(Vector3fImmutable location, float yaw) {
|
||||
return new Transform(location, Quaternion.fromYaw(yaw), new Vector3f(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
// world = parent × local, as the client composes zone and object transforms (sb.exe 0x6516C0).
|
||||
public static Transform mult(Transform parent, Transform local) {
|
||||
|
||||
Vector3f scaledLocation;
|
||||
Vector3f rotatedLocation;
|
||||
Quaternion rotation;
|
||||
Vector3f scale;
|
||||
|
||||
scaledLocation = new Vector3f(local.location).mult(parent.scale);
|
||||
rotatedLocation = parent.rotation.mult(scaledLocation);
|
||||
rotation = parent.rotation.mult(local.rotation);
|
||||
scale = parent.scale.mult(local.scale);
|
||||
|
||||
return new Transform(parent.location.add(rotatedLocation), rotation, scale);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user