Pass pre-combined rotations into the rendering code.
This commit is contained in:
@@ -19,12 +19,12 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
public readonly IModel Model;
|
||||
public readonly Func<WVec> OffsetFunc;
|
||||
public readonly Func<IEnumerable<WRot>> RotationFunc;
|
||||
public readonly Func<WRot> RotationFunc;
|
||||
public readonly Func<bool> DisableFunc;
|
||||
public readonly Func<uint> FrameFunc;
|
||||
public readonly bool ShowShadow;
|
||||
|
||||
public ModelAnimation(IModel model, Func<WVec> offset, Func<IEnumerable<WRot>> rotation, Func<bool> disable, Func<uint> frame, bool showshadow)
|
||||
public ModelAnimation(IModel model, Func<WVec> offset, Func<WRot> rotation, Func<bool> disable, Func<uint> frame, bool showshadow)
|
||||
{
|
||||
Model = model;
|
||||
OffsetFunc = offset;
|
||||
|
||||
@@ -114,8 +114,7 @@ namespace OpenRA.Graphics
|
||||
var offsetVec = Util.MatrixVectorMultiply(invCameraTransform, wr.ScreenVector(m.OffsetFunc()));
|
||||
var offsetTransform = Util.TranslationMatrix(offsetVec[0], offsetVec[1], offsetVec[2]);
|
||||
|
||||
var worldTransform = m.RotationFunc().Aggregate(Util.IdentityMatrix(),
|
||||
(x, y) => Util.MatrixMultiply(Util.MakeFloatMatrix(y.AsMatrix()), x));
|
||||
var worldTransform = Util.MakeFloatMatrix(m.RotationFunc().AsMatrix());
|
||||
worldTransform = Util.MatrixMultiply(scaleTransform, worldTransform);
|
||||
worldTransform = Util.MatrixMultiply(offsetTransform, worldTransform);
|
||||
|
||||
@@ -189,8 +188,7 @@ namespace OpenRA.Graphics
|
||||
var offsetVec = Util.MatrixVectorMultiply(invCameraTransform, wr.ScreenVector(m.OffsetFunc()));
|
||||
var offsetTransform = Util.TranslationMatrix(offsetVec[0], offsetVec[1], offsetVec[2]);
|
||||
|
||||
var rotations = m.RotationFunc().Aggregate(Util.IdentityMatrix(),
|
||||
(x, y) => Util.MatrixMultiply(Util.MakeFloatMatrix(y.AsMatrix()), x));
|
||||
var rotations = Util.MakeFloatMatrix(m.RotationFunc().AsMatrix());
|
||||
var worldTransform = Util.MatrixMultiply(scaleTransform, rotations);
|
||||
worldTransform = Util.MatrixMultiply(offsetTransform, worldTransform);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var model = init.World.ModelCache.GetModelSequence(image, IdleSequence);
|
||||
yield return new ModelAnimation(model, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(orientation(), facings) },
|
||||
() => body.QuantizeOrientation(orientation(), facings),
|
||||
() => false, () => 0, ShowShadow);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
|
||||
var idleModel = self.World.ModelCache.GetModelSequence(rv.Image, info.IdleSequence);
|
||||
modelAnimation = new ModelAnimation(idleModel, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
|
||||
() => body.QuantizeOrientation(self, self.Orientation),
|
||||
() => Docked,
|
||||
() => 0, info.ShowShadow);
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
|
||||
var unloadModel = self.World.ModelCache.GetModelSequence(rv.Image, info.UnloadSequence);
|
||||
rv.Add(new ModelAnimation(unloadModel, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
|
||||
() => body.QuantizeOrientation(self, self.Orientation),
|
||||
() => !Docked,
|
||||
() => 0, info.ShowShadow));
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
var frame = init.GetValue<BodyAnimationFrameInit, uint>(this, 0);
|
||||
|
||||
yield return new ModelAnimation(model, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(orientation(), facings) },
|
||||
() => body.QuantizeOrientation(orientation(), facings),
|
||||
() => false, () => frame, ShowShadow);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
var model = self.World.ModelCache.GetModelSequence(rv.Image, info.Sequence);
|
||||
frames = model.Frames;
|
||||
modelAnimation = new ModelAnimation(model, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
|
||||
() => body.QuantizeOrientation(self, self.Orientation),
|
||||
() => false, () => frame, info.ShowShadow);
|
||||
|
||||
rv.Add(modelAnimation);
|
||||
|
||||
@@ -183,8 +183,8 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
foreach (var v in draw)
|
||||
{
|
||||
var bounds = v.Model.Bounds(v.FrameFunc());
|
||||
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
|
||||
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
|
||||
var rotation = OpenRA.Graphics.Util.MakeFloatMatrix(v.RotationFunc().AsMatrix());
|
||||
var worldTransform = OpenRA.Graphics.Util.MatrixMultiply(scaleTransform, rotation);
|
||||
|
||||
var pxPos = pxOrigin + wr.ScreenVectorComponents(v.OffsetFunc());
|
||||
var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
|
||||
@@ -241,8 +241,8 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
foreach (var v in draw)
|
||||
{
|
||||
var bounds = v.Model.Bounds(v.FrameFunc());
|
||||
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
|
||||
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
|
||||
var rotation = OpenRA.Graphics.Util.MakeFloatMatrix(v.RotationFunc().AsMatrix());
|
||||
var worldTransform = OpenRA.Graphics.Util.MatrixMultiply(scaleTransform, rotation);
|
||||
|
||||
var pxPos = pxOrigin + wr.ScreenVectorComponents(v.OffsetFunc());
|
||||
var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
|
||||
|
||||
@@ -129,8 +129,8 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
foreach (var v in draw)
|
||||
{
|
||||
var bounds = v.Model.Bounds(v.FrameFunc());
|
||||
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
|
||||
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
|
||||
var rotation = OpenRA.Graphics.Util.MakeFloatMatrix(v.RotationFunc().AsMatrix());
|
||||
var worldTransform = OpenRA.Graphics.Util.MatrixMultiply(scaleTransform, rotation);
|
||||
|
||||
var pxPos = pxOrigin + wr.ScreenVectorComponents(v.OffsetFunc());
|
||||
var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
|
||||
|
||||
@@ -57,9 +57,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
Func<WRot> quantizedTurret = () => body.QuantizeOrientation(turretOrientation(), facings);
|
||||
Func<WRot> quantizedBody = () => body.QuantizeOrientation(orientation(), facings);
|
||||
Func<WVec> barrelOffset = () => body.LocalToWorld((t.Offset + LocalOffset.Rotate(quantizedTurret())).Rotate(quantizedBody()));
|
||||
|
||||
yield return new ModelAnimation(model, barrelOffset, () => new[] { turretOrientation(), orientation() },
|
||||
() => false, () => 0, ShowShadow);
|
||||
Func<WRot> barrelOrientation = () => turretOrientation().Rotate(orientation());
|
||||
yield return new ModelAnimation(model, barrelOffset, barrelOrientation, () => false, () => 0, ShowShadow);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,13 +96,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
return body.LocalToWorld((turretLocalOffset + localOffset.Rotate(turretOrientation)).Rotate(qb));
|
||||
}
|
||||
|
||||
IEnumerable<WRot> BarrelRotation()
|
||||
WRot BarrelRotation()
|
||||
{
|
||||
var b = self.Orientation;
|
||||
var qb = body.QuantizeOrientation(self, b);
|
||||
yield return Info.LocalOrientation;
|
||||
yield return turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw);
|
||||
yield return qb;
|
||||
var t = turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw);
|
||||
return Info.LocalOrientation.Rotate(t).Rotate(qb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||
yield return new ModelAnimation(model, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(orientation(), facings) },
|
||||
() => body.QuantizeOrientation(orientation(), facings),
|
||||
() => false, () => 0, ShowShadow);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
var model = self.World.ModelCache.GetModelSequence(rv.Image, info.Sequence);
|
||||
modelAnimation = new ModelAnimation(model, () => WVec.Zero,
|
||||
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
|
||||
() => body.QuantizeOrientation(self, self.Orientation),
|
||||
() => IsTraitDisabled, () => 0, info.ShowShadow);
|
||||
|
||||
rv.Add(modelAnimation);
|
||||
|
||||
@@ -45,9 +45,10 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
|
||||
|
||||
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||
Func<WRot> turretBodyOrientation = () => WRot.FromYaw(turretFacing() - orientation().Yaw);
|
||||
yield return new ModelAnimation(model, turretOffset,
|
||||
() => new[] { turretBodyOrientation(), body.QuantizeOrientation(orientation(), facings) }, () => false, () => 0, ShowShadow);
|
||||
Func<WRot> turretOrientation = () => WRot.FromYaw(turretFacing() - orientation().Yaw)
|
||||
.Rotate(body.QuantizeOrientation(orientation(), facings));
|
||||
|
||||
yield return new ModelAnimation(model, turretOffset, turretOrientation, () => false, () => 0, ShowShadow);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +72,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
() => IsTraitDisabled, () => 0, info.ShowShadow));
|
||||
}
|
||||
|
||||
IEnumerable<WRot> TurretRotation()
|
||||
WRot TurretRotation()
|
||||
{
|
||||
var b = self.Orientation;
|
||||
var qb = body.QuantizeOrientation(self, b);
|
||||
yield return turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw);
|
||||
yield return qb;
|
||||
return (turreted.WorldOrientation(self) - b + WRot.FromYaw(b.Yaw - qb.Yaw)).Rotate(qb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user