Introduce Turreted.WorldOrientation.
This commit is contained in:
@@ -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; } }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<WRot> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user