Skip to content

Commit

Permalink
Fix vehicle turret rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Nov 23, 2024
1 parent 771b21b commit 0cc2e76
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/TSMapEditor/Rendering/ObjectRenderers/UnitRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ protected override CommonDrawParams GetDrawParams(Unit gameObject)
};
}

protected override float GetDepthFromPosition(Unit gameObject, int bottomDrawPoint)
{
// Because vehicles can include turrets, the default implementation
// is not suitable. For example, bodies can be rendered southward of turrets
// facing north, leading the bodies to have higher depth and overlapping turrets.
//
// Instead, we calculate a positional depth value using the vehicle's cell.
// This depth value is identical for the base vehicle sprite and turret,
// making it easy to draw the turret either above or below the vehicle
// by applying DepthEpsilon.
var cell = Map.GetTile(gameObject.Position);

int height = 0;
if (cell != null)
{
height = cell.Level;
}

return ((CellMath.CellTopLeftPointFromCellCoords(cell.CoordsToPoint(), Map).Y + Constants.CellSizeY) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
(height * Constants.DepthRenderStep);
}

protected override float GetDepthAddition(Unit gameObject)
{
return Constants.DepthEpsilon * ObjectDepthAdjustments.Vehicle;
Expand Down

0 comments on commit 0cc2e76

Please sign in to comment.