From 70a86bed7a17c836be6bf50bcf2c96ece9adc1e0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 18 Jul 2020 14:32:17 +0100 Subject: [PATCH] Optimize WRot negation. The conjugate of a quaternion just negates the x/y/z components, so there is no need to recalculate from scratch and throw away precision by forcing a quat->euler->quat round trip. --- OpenRA.Game/WRot.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/WRot.cs b/OpenRA.Game/WRot.cs index 0611b0ea18..fa7300d59a 100644 --- a/OpenRA.Game/WRot.cs +++ b/OpenRA.Game/WRot.cs @@ -69,13 +69,24 @@ namespace OpenRA Yaw = -WAngle.ArcTan(sycp, cycp); } + WRot(int x, int y, int z, int w, WAngle roll, WAngle pitch, WAngle yaw) + { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + Roll = roll; + Pitch = pitch; + Yaw = yaw; + } + public static readonly WRot None = new WRot(WAngle.Zero, WAngle.Zero, WAngle.Zero); public static WRot FromFacing(int facing) { return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); } public static WRot FromYaw(WAngle yaw) { return new WRot(WAngle.Zero, WAngle.Zero, yaw); } public static WRot operator +(WRot a, WRot b) { return new WRot(a.Roll + b.Roll, a.Pitch + b.Pitch, a.Yaw + b.Yaw); } public static WRot operator -(WRot a, WRot b) { return new WRot(a.Roll - b.Roll, a.Pitch - b.Pitch, a.Yaw - b.Yaw); } - public static WRot operator -(WRot a) { return new WRot(-a.Roll, -a.Pitch, -a.Yaw); } + public static WRot operator -(WRot a) { return new WRot(-a.x, -a.y, -a.z, a.w, -a.Roll, -a.Pitch, -a.Yaw); } public WRot Rotate(WRot rot) {