Merge pull request #6084 from pchote/renderpreview
Improve actor preview rendering
This commit is contained in:
@@ -8,56 +8,76 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class BodyOrientationInfo : ITraitInfo, IBodyOrientationInfo
|
||||
{
|
||||
[Desc("Number of facings for gameplay calculations. -1 indiciates auto-detection from sequence")]
|
||||
[Desc("Number of facings for gameplay calculations. -1 indicates auto-detection from another trait")]
|
||||
public readonly int QuantizedFacings = -1;
|
||||
|
||||
[Desc("Camera pitch for rotation calculations")]
|
||||
public readonly WAngle CameraPitch = WAngle.FromDegrees(40);
|
||||
|
||||
public WVec LocalToWorld(WVec vec)
|
||||
{
|
||||
// RA's 2d perspective doesn't correspond to an orthonormal 3D
|
||||
// coordinate system, so fudge the y axis to make things look good
|
||||
return new WVec(vec.Y, -CameraPitch.Sin() * vec.X / 1024, vec.Z);
|
||||
}
|
||||
|
||||
public WRot QuantizeOrientation(WRot orientation, int facings)
|
||||
{
|
||||
// Quantization disabled
|
||||
if (facings == 0)
|
||||
return orientation;
|
||||
|
||||
// Map yaw to the closest facing
|
||||
var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, facings) * (256 / facings);
|
||||
|
||||
// Roll and pitch are always zero if yaw is quantized
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new BodyOrientation(init.self, this); }
|
||||
}
|
||||
|
||||
public class BodyOrientation : IBodyOrientation
|
||||
{
|
||||
[Sync] public int QuantizedFacings { get; private set; }
|
||||
BodyOrientationInfo info;
|
||||
readonly BodyOrientationInfo info;
|
||||
readonly Lazy<int> quantizedFacings;
|
||||
|
||||
[Sync] public int QuantizedFacings { get { return quantizedFacings.Value; } }
|
||||
|
||||
public BodyOrientation(Actor self, BodyOrientationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
if (info.QuantizedFacings > 0)
|
||||
QuantizedFacings = info.QuantizedFacings;
|
||||
|
||||
quantizedFacings = Exts.Lazy(() =>
|
||||
{
|
||||
// Override value is set
|
||||
if (info.QuantizedFacings >= 0)
|
||||
return info.QuantizedFacings;
|
||||
|
||||
var qboi = self.Info.Traits.GetOrDefault<IQuantizeBodyOrientationInfo>();
|
||||
if (qboi == null)
|
||||
throw new InvalidOperationException("Actor type '" + self.Info.Name + "' does not define a quantized body orientation.");
|
||||
|
||||
return qboi.QuantizedBodyFacings(self.World.Map.SequenceProvider, self.Info);
|
||||
});
|
||||
}
|
||||
|
||||
public WAngle CameraPitch { get { return info.CameraPitch; } }
|
||||
|
||||
public WVec LocalToWorld(WVec vec)
|
||||
{
|
||||
// RA's 2d perspective doesn't correspond to an orthonormal 3D
|
||||
// coordinate system, so fudge the y axis to make things look good
|
||||
return new WVec(vec.Y, -info.CameraPitch.Sin()*vec.X/1024, vec.Z);
|
||||
return info.LocalToWorld(vec);
|
||||
}
|
||||
|
||||
public WRot QuantizeOrientation(Actor self, WRot orientation)
|
||||
{
|
||||
// Quantization disabled
|
||||
if (QuantizedFacings == 0)
|
||||
return orientation;
|
||||
|
||||
// Map yaw to the closest facing
|
||||
var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings);
|
||||
|
||||
// Roll and pitch are always zero if yaw is quantized
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
|
||||
public void SetAutodetectedFacings(int facings)
|
||||
{
|
||||
if (info.QuantizedFacings < 0)
|
||||
QuantizedFacings = facings;
|
||||
return info.QuantizeOrientation(orientation, quantizedFacings.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,15 +227,22 @@ namespace OpenRA.Traits
|
||||
public interface IRenderShroud { void RenderShroud(WorldRenderer wr, Shroud shroud); }
|
||||
|
||||
public interface IPostRenderSelection { IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr); }
|
||||
|
||||
public interface IBodyOrientation
|
||||
{
|
||||
WAngle CameraPitch { get; }
|
||||
int QuantizedFacings { get; }
|
||||
WVec LocalToWorld(WVec vec);
|
||||
WRot QuantizeOrientation(Actor self, WRot orientation);
|
||||
void SetAutodetectedFacings(int facings);
|
||||
}
|
||||
public interface IBodyOrientationInfo : ITraitInfo { }
|
||||
|
||||
public interface IBodyOrientationInfo : ITraitInfo
|
||||
{
|
||||
WVec LocalToWorld(WVec vec);
|
||||
WRot QuantizeOrientation(WRot orientation, int facings);
|
||||
}
|
||||
|
||||
public interface IQuantizeBodyOrientationInfo { int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai); }
|
||||
|
||||
public interface ITargetableInfo
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user