Introduce world offsets for turrets & armaments.

This commit is contained in:
Paul Chote
2013-03-25 20:33:32 +13:00
parent 27d852a425
commit bb6a1ed6e0
4 changed files with 163 additions and 38 deletions

View File

@@ -37,19 +37,32 @@ namespace OpenRA.Mods.RA.Render
anim.Play("turret");
anims.Add("turret_{0}".F(i++), new AnimationWithOffset(anim,
() => turret.PxPosition(self, facing).ToFloat2() + RecoilOffset(self, turret), null));
() => TurretPosition(self, turret, facing), null));
}
}
float2 RecoilOffset(Actor self, Turreted t)
float2 TurretPosition(Actor self, Turreted t, IFacing facing)
{
var a = self.TraitsImplementing<Armament>()
.OrderByDescending(w => w.Recoil)
.FirstOrDefault(w => w.Info.Turret == t.info.Turret);
if (a == null)
return float2.Zero;
if (t.CoordinateModel == CoordinateModel.Legacy)
{
var recoil = self.TraitsImplementing<Armament>()
.Where(w => w.Info.Turret == t.Name)
.Sum(w => w.LegacyRecoil);
return t.PxPosition(self, facing).ToFloat2() + Traits.Util.RotateVectorByFacing(new float2(0, recoil), t.turretFacing, .7f);
}
else
{
var recoil = self.TraitsImplementing<Armament>()
.Where(w => w.Info.Turret == t.Name)
.Aggregate(WRange.Zero, (a,b) => a + b.Recoil);
return a.RecoilPxOffset(self, t.turretFacing).ToFloat2();
var localOffset = new WVec(-recoil, WRange.Zero, WRange.Zero);
var bodyOrientation = QuantizeOrientation(self, self.Orientation);
var turretOrientation = QuantizeOrientation(self, t.LocalOrientation(self));
var worldPos = WPos.Zero + t.Position(self) + LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
return PPos.FromWPosHackZ(worldPos).ToFloat2();
}
}
}
}