From fe60f5a77f9b3359da2d18a45e8c78e4a3dfc682 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 14 Jan 2016 23:32:12 +0000 Subject: [PATCH] Introduce Turreted.WorldOrientation. --- OpenRA.Mods.Common/Traits/Armament.cs | 13 ++++++++----- .../Traits/Render/WithSpriteBarrel.cs | 6 +++--- .../Traits/Render/WithSpriteTurret.cs | 5 ++--- OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs | 10 +++++----- OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs | 2 +- OpenRA.Mods.Common/Traits/Turreted.cs | 10 +++++----- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index 5bf642ef11..6ff6f34fa1 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -253,7 +253,10 @@ namespace OpenRA.Mods.Common.Traits var localOffset = b.Offset + new WVec(-Recoil, WDist.Zero, WDist.Zero); if (turret != null) { - var turretOrientation = coords.QuantizeOrientation(self, turret.LocalOrientation(self)); + // WorldOrientation is quantized to satisfy the *Fudges. + // Need to then convert back to a pseudo-local coordinate space, apply offsets, + // then rotate back at the end + var turretOrientation = turret.WorldOrientation(self) - bodyOrientation; localOffset = localOffset.Rotate(turretOrientation); localOffset += turret.Offset; } @@ -263,10 +266,10 @@ namespace OpenRA.Mods.Common.Traits public WRot MuzzleOrientation(Actor self, Barrel b) { - var orientation = self.Orientation + WRot.FromYaw(b.Yaw); - if (turret != null) - orientation += turret.LocalOrientation(self); - return orientation; + var orientation = turret != null ? turret.WorldOrientation(self) : + coords.QuantizeOrientation(self, self.Orientation); + + return orientation + WRot.FromYaw(b.Yaw); } public Actor Actor { get { return self; } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs index ca507a8549..75f37f22be 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs @@ -90,9 +90,9 @@ namespace OpenRA.Mods.Common.Traits { var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero); var turretOffset = turreted != null ? turreted.Position(self) : WVec.Zero; - var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero; - var quantizedBody = body.QuantizeOrientation(self, self.Orientation); + var turretOrientation = turreted != null ? turreted.WorldOrientation(self) - quantizedBody : WRot.Zero; + var quantizedTurret = body.QuantizeOrientation(self, turretOrientation); return turretOffset + body.LocalToWorld(localOffset.Rotate(quantizedTurret).Rotate(quantizedBody)); } @@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits { var b = self.Orientation; var qb = body.QuantizeOrientation(self, b); - yield return turreted.LocalOrientation(self) + WRot.FromYaw(b.Yaw - qb.Yaw); + yield return turreted.WorldOrientation(self) - qb + WRot.FromYaw(b.Yaw - qb.Yaw); yield return qb; } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs index fe48517623..e65dd9d92f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs @@ -98,9 +98,8 @@ namespace OpenRA.Mods.Common.Traits var recoil = arms.Aggregate(WDist.Zero, (a, b) => a + b.Recoil); var localOffset = new WVec(-recoil, WDist.Zero, WDist.Zero); - var bodyOrientation = body.QuantizeOrientation(self, self.Orientation); - var turretOrientation = body.QuantizeOrientation(self, t.LocalOrientation(self)); - return t.Position(self) + body.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation)); + var quantizedWorldTurret = t.WorldOrientation(self); + return t.Position(self) + body.LocalToWorld(localOffset.Rotate(quantizedWorldTurret)); } public string NormalizeSequence(Actor self, string sequence) diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs index 5be2a84bed..958d795471 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs @@ -84,20 +84,20 @@ namespace OpenRA.Mods.Common.Traits WVec BarrelOffset() { + var b = self.Orientation; + var qb = body.QuantizeOrientation(self, b); var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero); var turretLocalOffset = turreted != null ? turreted.Offset : WVec.Zero; - var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero; + var turretOrientation = turreted != null ? turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw) : WRot.Zero; - var quantizedBody = body.QuantizeOrientation(self, self.Orientation); - var quantizedTurret = body.QuantizeOrientation(self, turretOrientation); - return body.LocalToWorld((turretLocalOffset + localOffset.Rotate(quantizedTurret)).Rotate(quantizedBody)); + return body.LocalToWorld((turretLocalOffset + localOffset.Rotate(turretOrientation)).Rotate(qb)); } IEnumerable BarrelRotation() { var b = self.Orientation; var qb = body.QuantizeOrientation(self, b); - yield return turreted.LocalOrientation(self) + WRot.FromYaw(b.Yaw - qb.Yaw); + yield return turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw); yield return qb; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs index e8ca5f1fd0..27d95225e8 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelTurret.cs @@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits { var b = self.Orientation; var qb = body.QuantizeOrientation(self, b); - yield return turreted.LocalOrientation(self) + WRot.FromYaw(b.Yaw - qb.Yaw); + yield return turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw); yield return qb; } diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index 246da505e2..60d1f698b7 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -122,18 +122,18 @@ namespace OpenRA.Mods.Common.Traits return body.LocalToWorld(Offset.Rotate(bodyOrientation)); } - // Orientation in unit-space - public WRot LocalOrientation(Actor self) + // Orientation in world-space + public WRot WorldOrientation(Actor self) { // Hack: turretFacing is relative to the world, so subtract the body yaw - var local = WRot.FromYaw(WAngle.FromFacing(TurretFacing) - self.Orientation.Yaw); + var world = WRot.FromYaw(WAngle.FromFacing(TurretFacing)); if (QuantizedFacings == 0) - return local; + return world; // Quantize orientation to match a rendered sprite // Implies no pitch or yaw - var facing = body.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings); + var facing = body.QuantizeFacing(world.Yaw.Angle / 4, QuantizedFacings); return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); }