Skip to content

Commit

Permalink
Merge pull request VixenLights#616 from johncbaur/VIX-3586
Browse files Browse the repository at this point in the history
VIX-3586 Fixing Odd Number of Moving Heads Logic
  • Loading branch information
jeffu231 authored Sep 3, 2024
2 parents fded230 + 01945ff commit 63f2d0f
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions src/Vixen.Modules/Effect/LineDance/LineDanceModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private void RenderInnerStaggerLeftNodes(
// Create a curve for the node
// The first argument is taking the PanIncrement slider value and applying it to a max value of 50
// since this is being applied to Mid value of 50
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * offset, width, leftIndex == 0);
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * offset, width, leftIndex == 0 && !ExtraNodeOnRight());

// Render the node
RenderFanCurve(
Expand Down Expand Up @@ -441,7 +441,7 @@ private void RenderOuterStaggerLeftNodes(
// Create a curve for the node
// The first argument is taking the PanIncrement slider value and applying it to a max value of 50
// since this is being applied to Mid value of 50
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * offset, width, leftIndex == leftMiddleIndex);
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * offset, width, leftIndex == leftMiddleIndex && !ExtraNodeOnRight());

// Need to calculate a moving head offset since we are moving from outside to inside
int renderOffset = 1 + (leftMiddleIndex + 1) - offset;
Expand Down Expand Up @@ -684,7 +684,7 @@ private void RenderInnerStaggerRightNodes(
// Create a curve for the node
// The first argument is taking the PanIncrement slider value and applying it to a max value of 50
// since this is being applied to Mid value of 50
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * (int)(Math.Abs(offset)), width, rightIndex == renderNodes.Count - 1);
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * (int)(Math.Abs(offset)), width, rightIndex == renderNodes.Count - 1 && !ExtraNodeOnLeft());

// Render the node
RenderFanCurve(
Expand Down Expand Up @@ -731,7 +731,7 @@ private void RenderOuterStaggerRightNodes(
// Create a curve for the node
// The first argument is taking the PanIncrement slider value and applying it to a max value of 50
// since this is being applied to Mid value of 50
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * (int)(Math.Abs(offset)), width, rightIndex == rightMiddleIndex);
Curve c = CreateStaggerCurve(CalculatePanIncrement(), width * (int)(Math.Abs(offset)), width, rightIndex == rightMiddleIndex && !ExtraNodeOnLeft());

// Need to calculate a moving head offset since we are moving from outside to inside
int renderIndex = (int)(-rightMiddleIndex - offset - 1);
Expand Down Expand Up @@ -1050,23 +1050,68 @@ private double CalculateStartAngle()
return startAngle;
}

/// <summary>
/// Returns true when there is an extra node on the left side.
/// </summary>
/// <returns>True when there is an extra node on the left side</returns>
private bool ExtraNodeOnLeft()
{
// If there is odd number of nodes and
// the node is being included on the left
return (_renderNodes.Count % 2 == 1 &&
CenterHandling == FanCenterOptions.Left);
}

/// <summary>
/// Returns true when there is an extra node on the right side.
/// </summary>
/// <returns>True when there is an extra node on the right side</returns>
private bool ExtraNodeOnRight()
{
// If there is odd number of nodes and
// the node is being included on the right
return (_renderNodes.Count % 2 == 1 &&
CenterHandling == FanCenterOptions.Right);
}


/// <summary>
/// Returns 1 when an odd beam is involved with the fan otherwise zero.
/// </summary>
/// <returns>1 when an odd beam is involved with the fan otherwise zero</returns>
private int GetOddBeam()
{
int oddBeam = 0;

// If the center beam is part of the left or right fan then...
if (_renderNodes.Count % 2 == 1 &&
(CenterHandling == FanCenterOptions.Left ||
CenterHandling == FanCenterOptions.Right))
{
// Increase the number of beams to handle
oddBeam = 1;
}

return oddBeam;
}

/// <summary>
/// Calculates the maximum pan increment angle (0-1). This value is used to scale the Pan Increment angle.
/// The calculation results in the last moving head in the fan to be at the maximum pan of the fixture.
/// </summary>
/// <returns>Maximum pan increment (0-1)</returns>
private double CalculateMaxPanIncrement()
{
{
// Calculate the maximum pan increment with the goal of the last moving head to be at the maximum pan angle
return (1.0 - PanStartAngle / 100.0) / (_renderNodes.Count / 2);
return (1.0 - PanStartAngle / 100.0) / (_renderNodes.Count / 2 + GetOddBeam());
}

/// <summary>
/// Calculates the pan increment given that the middle of the curve represents a pan angle of zero.
/// </summary>
/// <returns>Pan increment value</returns>
private int CalculatePanIncrement()
{
{
// Taking the PanIncrement slider value and applying it to a max value of 50
// since this will be applied to Mid value of 50
int panIncrement = (int)((PanIncrement / 100.0) * 50);
Expand All @@ -1088,7 +1133,7 @@ private int CalculateStaggerWidth()
{
// Calculate the distance between stagger points
// Taking into a hold time at the end of the effect
return (100 - HoldTime) / (_renderNodes.Count / 2);
return (100 - HoldTime) / (_renderNodes.Count / 2 + GetOddBeam());
}

#endregion
Expand Down

0 comments on commit 63f2d0f

Please sign in to comment.