Add ContrailEndWidth
This commit is contained in:
committed by
Matthias Mailänder
parent
ff488b77b5
commit
7ef1dccdcf
@@ -27,19 +27,21 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
// Store trail positions in a circular buffer
|
||||
readonly WPos[] trail;
|
||||
readonly WDist width;
|
||||
readonly WDist startWidth;
|
||||
readonly WDist endWidth;
|
||||
int next;
|
||||
int length;
|
||||
readonly int skip;
|
||||
|
||||
public ContrailRenderable(World world, Color startcolor, Color endcolor, WDist width, int length, int skip, int zOffset)
|
||||
: this(world, new WPos[length], width, 0, 0, skip, startcolor, endcolor, zOffset) { }
|
||||
public ContrailRenderable(World world, Color startcolor, Color endcolor, WDist startWidth, WDist endWidth, int length, int skip, int zOffset)
|
||||
: this(world, new WPos[length], startWidth, endWidth, 0, 0, skip, startcolor, endcolor, zOffset) { }
|
||||
|
||||
ContrailRenderable(World world, WPos[] trail, WDist width, int next, int length, int skip, Color startcolor, Color endcolor, int zOffset)
|
||||
ContrailRenderable(World world, WPos[] trail, WDist startWidth, WDist endWidth, int next, int length, int skip, Color startcolor, Color endcolor, int zOffset)
|
||||
{
|
||||
this.world = world;
|
||||
this.trail = trail;
|
||||
this.width = width;
|
||||
this.startWidth = startWidth;
|
||||
this.endWidth = endWidth;
|
||||
this.next = next;
|
||||
this.length = length;
|
||||
this.skip = skip;
|
||||
@@ -52,12 +54,12 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public int ZOffset { get; }
|
||||
public bool IsDecoration => true;
|
||||
|
||||
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, startcolor, endcolor, newOffset); }
|
||||
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), startWidth, endWidth, next, length, skip, startcolor, endcolor, newOffset); }
|
||||
public IRenderable OffsetBy(in WVec vec)
|
||||
{
|
||||
// Lambdas can't use 'in' variables, so capture a copy for later
|
||||
var offset = vec;
|
||||
return new ContrailRenderable(world, trail.Select(pos => pos + offset).ToArray(), width, next, length, skip, startcolor, endcolor, ZOffset);
|
||||
return new ContrailRenderable(world, trail.Select(pos => pos + offset).ToArray(), startWidth, endWidth, next, length, skip, startcolor, endcolor, ZOffset);
|
||||
}
|
||||
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
@@ -71,7 +73,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
if (renderLength <= 1)
|
||||
return;
|
||||
|
||||
var screenWidth = wr.ScreenVector(new WVec(width, WDist.Zero, WDist.Zero))[0];
|
||||
var screenWidth = wr.ScreenVector(new WVec(1, 0, 0))[0];
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
|
||||
// Start of the first line segment is the tail of the list - don't smooth it.
|
||||
@@ -97,8 +99,20 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
var nextPos = new WPos((int)(nextX / k), (int)(nextY / k), (int)(nextZ / k));
|
||||
|
||||
if (!world.FogObscures(curPos) && !world.FogObscures(nextPos))
|
||||
wcr.DrawLine(wr.Screen3DPosition(curPos), wr.Screen3DPosition(nextPos), screenWidth, curColor, nextColor);
|
||||
// When renderLength = 2 we are rendering only one segment, so it needs to be handled differently to avoid
|
||||
// division by 0. For width we choose startWidth instead of the average as this makes the transition between
|
||||
// rendering 1 and multiple segments smoother. Above checks make sure that renderLength can never be lower than 2.
|
||||
float width;
|
||||
if (renderLength == 2)
|
||||
width = startWidth.Length;
|
||||
else
|
||||
{
|
||||
var lerp = (i - 1f) / (renderLength - 2);
|
||||
width = startWidth.Length * (1 - lerp) + endWidth.Length * lerp;
|
||||
}
|
||||
|
||||
if (width > 0 && !world.FogObscures(curPos) && !world.FogObscures(nextPos))
|
||||
wcr.DrawLine(wr.Screen3DPosition(curPos), wr.Screen3DPosition(nextPos), screenWidth * width, curColor, nextColor);
|
||||
|
||||
curPos = nextPos;
|
||||
curColor = nextColor;
|
||||
|
||||
Reference in New Issue
Block a user