Convert turret facings to WAngle relative to the body.
This commit is contained in:
@@ -52,10 +52,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var turreted = self.TraitsImplementing<Turreted>()
|
||||
.FirstOrDefault(t => t.Name == arm.Info.Turret);
|
||||
|
||||
// Workaround for broken ternary operators in certain versions of mono (3.10 and
|
||||
// certain versions of the 3.8 series): https://bugzilla.xamarin.com/show_bug.cgi?id=23319
|
||||
if (turreted != null)
|
||||
getFacing = () => WAngle.FromFacing(turreted.TurretFacing);
|
||||
getFacing = () => turreted.WorldOrientation.Yaw;
|
||||
else if (facing != null)
|
||||
getFacing = () => facing.Facing;
|
||||
else
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == armament.Turret);
|
||||
|
||||
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||
var turretFacing = t.WorldFacingFromInit(init);
|
||||
var anim = new Animation(init.World, image, turretFacing);
|
||||
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
.First(tt => tt.Name == armament.Info.Turret);
|
||||
|
||||
rs = self.Trait<RenderSprites>();
|
||||
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => WAngle.FromFacing(turreted.TurretFacing));
|
||||
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => turreted.WorldOrientation.Yaw);
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
|
||||
rs.Add(new AnimationWithOffset(
|
||||
DefaultAnimation, () => BarrelOffset(), () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 0)));
|
||||
@@ -98,21 +98,10 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
WVec BarrelOffset()
|
||||
{
|
||||
var orientation = turreted != null ? turreted.WorldOrientation : self.Orientation;
|
||||
var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero);
|
||||
var turretOffset = turreted != null ? turreted.Position(self) : WVec.Zero;
|
||||
var quantizedBody = body.QuantizeOrientation(self, self.Orientation);
|
||||
var turretOrientation = turreted != null ? turreted.WorldOrientation(self) - quantizedBody : WRot.None;
|
||||
|
||||
var quantizedTurret = body.QuantizeOrientation(self, turretOrientation);
|
||||
return turretOffset + body.LocalToWorld(localOffset.Rotate(quantizedTurret).Rotate(quantizedBody));
|
||||
}
|
||||
|
||||
IEnumerable<WRot> BarrelRotation()
|
||||
{
|
||||
var b = self.Orientation;
|
||||
var qb = body.QuantizeOrientation(self, b);
|
||||
yield return turreted.WorldOrientation(self) - qb + WRot.FromYaw(b.Yaw - qb.Yaw);
|
||||
yield return qb;
|
||||
var turretLocalOffset = turreted != null ? turreted.Offset : WVec.Zero;
|
||||
return body.LocalToWorld(turretLocalOffset + localOffset.Rotate(orientation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||
var turretFacing = t.WorldFacingFromInit(init);
|
||||
var anim = new Animation(init.World, image, turretFacing);
|
||||
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
arms = self.TraitsImplementing<Armament>()
|
||||
.Where(w => w.Info.Turret == info.Turret).ToArray();
|
||||
|
||||
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => WAngle.FromFacing(t.TurretFacing));
|
||||
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => t.WorldOrientation.Yaw);
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
|
||||
rs.Add(new AnimationWithOffset(DefaultAnimation,
|
||||
() => TurretOffset(self),
|
||||
@@ -106,10 +106,9 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
if (!Info.Recoils)
|
||||
return t.Position(self);
|
||||
|
||||
var recoil = arms.Aggregate(WDist.Zero, (a, b) => a + b.Recoil);
|
||||
var localOffset = new WVec(-recoil, WDist.Zero, WDist.Zero);
|
||||
var quantizedWorldTurret = t.WorldOrientation(self);
|
||||
return t.Position(self) + body.LocalToWorld(localOffset.Rotate(quantizedWorldTurret));
|
||||
var recoilDist = arms.Aggregate(WDist.Zero, (a, b) => a + b.Recoil);
|
||||
var recoil = new WVec(-recoilDist, WDist.Zero, WDist.Zero);
|
||||
return t.Position(self) + body.LocalToWorld(recoil.Rotate(t.WorldOrientation));
|
||||
}
|
||||
|
||||
public string NormalizeSequence(Actor self, string sequence)
|
||||
|
||||
@@ -51,13 +51,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||
|
||||
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||
Func<WRot> turretOrientation = () => body.QuantizeOrientation(WRot.FromYaw(turretFacing() - orientation().Yaw), facings);
|
||||
|
||||
Func<WRot> quantizedTurret = () => body.QuantizeOrientation(turretOrientation(), facings);
|
||||
var turretOrientation = t.PreviewOrientation(init, orientation, facings);
|
||||
Func<WRot> quantizedBody = () => body.QuantizeOrientation(orientation(), facings);
|
||||
Func<WVec> barrelOffset = () => body.LocalToWorld((t.Offset + LocalOffset.Rotate(quantizedTurret())).Rotate(quantizedBody()));
|
||||
Func<WRot> barrelOrientation = () => turretOrientation().Rotate(orientation());
|
||||
Func<WVec> barrelOffset = () => body.LocalToWorld((t.Offset + LocalOffset.Rotate(turretOrientation())).Rotate(quantizedBody()));
|
||||
Func<WRot> barrelOrientation = () => LocalOrientation.Rotate(turretOrientation()).Rotate(quantizedBody());
|
||||
|
||||
yield return new ModelAnimation(model, barrelOffset, barrelOrientation, () => false, () => 0, ShowShadow);
|
||||
}
|
||||
}
|
||||
@@ -87,21 +85,15 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
WVec BarrelOffset()
|
||||
{
|
||||
var b = self.Orientation;
|
||||
var qb = body.QuantizeOrientation(self, b);
|
||||
var orientation = turreted != null ? turreted.WorldOrientation : self.Orientation;
|
||||
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.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw) : WRot.None;
|
||||
|
||||
return body.LocalToWorld((turretLocalOffset + localOffset.Rotate(turretOrientation)).Rotate(qb));
|
||||
return body.LocalToWorld(turretLocalOffset + localOffset.Rotate(orientation));
|
||||
}
|
||||
|
||||
WRot BarrelRotation()
|
||||
{
|
||||
var b = self.Orientation;
|
||||
var qb = body.QuantizeOrientation(self, b);
|
||||
var t = turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw);
|
||||
return Info.LocalOrientation.Rotate(t).Rotate(qb);
|
||||
return Info.LocalOrientation.Rotate(turreted != null ? turreted.WorldOrientation : self.Orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,17 +37,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
if (!EnabledByDefault)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||
Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
|
||||
|
||||
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||
Func<WRot> turretOrientation = () => WRot.FromYaw(turretFacing() - orientation().Yaw)
|
||||
.Rotate(body.QuantizeOrientation(orientation(), facings));
|
||||
|
||||
var turretOffset = t.PreviewPosition(init, orientation);
|
||||
var turretOrientation = t.PreviewOrientation(init, orientation, facings);
|
||||
yield return new ModelAnimation(model, turretOffset, turretOrientation, () => false, () => 0, ShowShadow);
|
||||
}
|
||||
}
|
||||
@@ -68,15 +63,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
var rv = self.Trait<RenderVoxels>();
|
||||
rv.Add(new ModelAnimation(self.World.ModelCache.GetModelSequence(rv.Image, Info.Sequence),
|
||||
() => turreted.Position(self), TurretRotation,
|
||||
() => turreted.Position(self), () => turreted.WorldOrientation,
|
||||
() => IsTraitDisabled, () => 0, info.ShowShadow));
|
||||
}
|
||||
|
||||
WRot TurretRotation()
|
||||
{
|
||||
var b = self.Orientation;
|
||||
var qb = body.QuantizeOrientation(self, b);
|
||||
return (turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw)).Rotate(qb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user