-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,206 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Collections.Generic; | ||
using AstroDX.Contexts.Gameplay.PlayerScope; | ||
using AstroDX.Utilities; | ||
using SimaiSharp.Structures; | ||
using UnityEngine; | ||
|
||
namespace AstroDX.Contexts.Gameplay.SlideGenerators | ||
{ | ||
public sealed class CurveCcwGenerator : SlideGenerator | ||
{ | ||
private const float CurveRadius = RenderManager.CenterRadius; | ||
private const float RingRadius = RenderManager.PlayFieldRadius; | ||
private readonly float _curveLength; | ||
private readonly float _endForward; | ||
private readonly Vector2 _endPoint; | ||
|
||
private readonly float _startForward; | ||
|
||
private readonly float _startLength; | ||
|
||
private readonly Vector2 _startPoint; | ||
private readonly Vector2 _tangentInPoint; | ||
private readonly float _tangentInRotation; | ||
private readonly Vector2 _tangentOutPoint; | ||
private readonly float _totalLength; | ||
|
||
public CurveCcwGenerator(IReadOnlyList<Location> vertices) | ||
{ | ||
var startRotation = GetRotation(vertices[0]); | ||
var endRotation = GetRotation(vertices[1]); | ||
|
||
_tangentInRotation = startRotation + | ||
Trigonometry.GetTangentAngleDelta(CurveRadius, RingRadius, false); | ||
var tangentOutRotation = endRotation + | ||
Trigonometry.GetTangentAngleDelta(CurveRadius, RingRadius, true); | ||
|
||
_startPoint = GetPositionRadial(startRotation); | ||
_tangentInPoint = GetPositionRadial(_tangentInRotation, CurveRadius); | ||
_tangentOutPoint = GetPositionRadial(tangentOutRotation, CurveRadius); | ||
_endPoint = GetPositionRadial(endRotation); | ||
|
||
var startSegment = _tangentInPoint - _startPoint; | ||
_startLength = startSegment.magnitude; | ||
_startForward = Mathf.Atan2(startSegment.y, startSegment.x); | ||
|
||
_curveLength = Trigonometry.GetAngleSpan(_tangentInRotation, tangentOutRotation, | ||
false) * CurveRadius; | ||
|
||
var endSegment = _endPoint - _tangentOutPoint; | ||
var endLength = endSegment.magnitude; | ||
_endForward = Mathf.Atan2(endSegment.y, endSegment.x); | ||
|
||
_totalLength = _startLength + _curveLength + endLength; | ||
} | ||
|
||
public override float GetLength() | ||
{ | ||
return _totalLength; | ||
} | ||
|
||
public override void GetPoint(float t, out Vector2 position, out float rotation) | ||
{ | ||
var distanceFromStart = t * _totalLength; | ||
|
||
if (distanceFromStart < _startLength) | ||
{ | ||
position = Vector2.Lerp(_startPoint, | ||
_tangentInPoint, | ||
Mathf.InverseLerp(0, | ||
_startLength, | ||
distanceFromStart)); | ||
|
||
rotation = _startForward; | ||
} | ||
else if (distanceFromStart < _startLength + _curveLength) | ||
{ | ||
var localT = Mathf.InverseLerp(_startLength, _startLength + _curveLength, distanceFromStart); | ||
position = new Vector2(Mathf.Cos(_tangentInRotation + _curveLength / CurveRadius * localT) * | ||
CurveRadius, | ||
Mathf.Sin(_tangentInRotation + _curveLength / CurveRadius * localT) * | ||
CurveRadius); | ||
|
||
var forward = position.Rotate(Trigonometry.Tau / 4); | ||
rotation = Mathf.Atan2(forward.y, forward.x); | ||
} | ||
else | ||
{ | ||
position = Vector2.Lerp(_tangentOutPoint, | ||
_endPoint, | ||
Mathf.InverseLerp(_startLength + _curveLength, | ||
_totalLength, | ||
distanceFromStart)); | ||
|
||
rotation = _endForward; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Collections.Generic; | ||
using AstroDX.Contexts.Gameplay.PlayerScope; | ||
using AstroDX.Utilities; | ||
using SimaiSharp.Structures; | ||
using UnityEngine; | ||
|
||
namespace AstroDX.Contexts.Gameplay.SlideGenerators | ||
{ | ||
public sealed class CurveCwGenerator : SlideGenerator | ||
{ | ||
private const float CurveRadius = RenderManager.CenterRadius; | ||
private const float RingRadius = RenderManager.PlayFieldRadius; | ||
private readonly float _curveLength; | ||
private readonly float _endForward; | ||
private readonly Vector2 _endPoint; | ||
|
||
private readonly float _startForward; | ||
|
||
private readonly float _startLength; | ||
|
||
private readonly Vector2 _startPoint; | ||
private readonly Vector2 _tangentInPoint; | ||
private readonly float _tangentInRotation; | ||
private readonly Vector2 _tangentOutPoint; | ||
private readonly float _totalLength; | ||
|
||
public CurveCwGenerator(IReadOnlyList<Location> vertices) | ||
{ | ||
var startRotation = GetRotation(vertices[0]); | ||
var endRotation = GetRotation(vertices[1]); | ||
|
||
_tangentInRotation = startRotation + | ||
Trigonometry.GetTangentAngleDelta(CurveRadius, RingRadius, true); | ||
var tangentOutRotation = endRotation + | ||
Trigonometry.GetTangentAngleDelta(CurveRadius, RingRadius, false); | ||
|
||
_startPoint = GetPositionRadial(startRotation); | ||
_tangentInPoint = GetPositionRadial(_tangentInRotation, CurveRadius); | ||
_tangentOutPoint = GetPositionRadial(tangentOutRotation, CurveRadius); | ||
_endPoint = GetPositionRadial(endRotation); | ||
|
||
var startSegment = _tangentInPoint - _startPoint; | ||
_startLength = startSegment.magnitude; | ||
_startForward = Mathf.Atan2(startSegment.y, startSegment.x); | ||
|
||
_curveLength = Trigonometry.GetAngleSpan(_tangentInRotation, tangentOutRotation, | ||
true) * CurveRadius; | ||
|
||
var endSegment = _endPoint - _tangentOutPoint; | ||
var endLength = endSegment.magnitude; | ||
_endForward = Mathf.Atan2(endSegment.y, endSegment.x); | ||
|
||
_totalLength = _startLength + _curveLength + endLength; | ||
} | ||
|
||
public override float GetLength() | ||
{ | ||
return _totalLength; | ||
} | ||
|
||
public override void GetPoint(float t, out Vector2 position, out float rotation) | ||
{ | ||
var distanceFromStart = t * _totalLength; | ||
|
||
if (distanceFromStart < _startLength) | ||
{ | ||
position = Vector2.Lerp(_startPoint, | ||
_tangentInPoint, | ||
Mathf.InverseLerp(0, | ||
_startLength, | ||
distanceFromStart)); | ||
|
||
rotation = _startForward; | ||
} | ||
else if (distanceFromStart < _startLength + _curveLength) | ||
{ | ||
var localT = Mathf.InverseLerp(_startLength, _startLength + _curveLength, distanceFromStart); | ||
position = new Vector2(Mathf.Cos(_tangentInRotation - _curveLength / CurveRadius * localT) * | ||
CurveRadius, | ||
Mathf.Sin(_tangentInRotation - _curveLength / CurveRadius * localT) * | ||
CurveRadius); | ||
|
||
var forward = position.Rotate(-Trigonometry.Tau / 4); | ||
rotation = Mathf.Atan2(forward.y, forward.x); | ||
} | ||
else | ||
{ | ||
position = Vector2.Lerp(_tangentOutPoint, | ||
_endPoint, | ||
Mathf.InverseLerp(_startLength + _curveLength, | ||
_totalLength, | ||
distanceFromStart)); | ||
|
||
rotation = _endForward; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System.Collections.Generic; | ||
using AstroDX.Contexts.Gameplay.PlayerScope; | ||
using AstroDX.Utilities; | ||
using SimaiSharp.Structures; | ||
using UnityEngine; | ||
|
||
namespace AstroDX.Contexts.Gameplay.SlideGenerators | ||
{ | ||
public sealed class EdgeCurveCcwGenerator : SlideGenerator | ||
{ | ||
private const float CurveRadius = RenderManager.CenterRadius * 1.2f; | ||
private const float CenterAngularOffset = Trigonometry.Tau / 4 - Trigonometry.Tau / 16; | ||
private const float CenterRadialOffset = RenderManager.PlayFieldRadius * 0.4662f; | ||
|
||
private readonly Vector2 _centerPosition; | ||
private readonly float _curveLength; | ||
private readonly Vector2 _endPoint; | ||
|
||
private readonly float _startRotation; | ||
private readonly float _endRotation; | ||
|
||
private readonly float _startLength; | ||
private readonly Vector2 _startPoint; | ||
private readonly Vector2 _tangentInPoint; | ||
private readonly float _tangentInRotation; | ||
private readonly Vector2 _tangentOutPoint; | ||
private readonly float _totalLength; | ||
|
||
public EdgeCurveCcwGenerator(IReadOnlyList<Location> vertices) | ||
{ | ||
var startRotation = GetRotation(vertices[0]); | ||
var endRotation = GetRotation(vertices[1]); | ||
|
||
var centerAngle = startRotation - CenterAngularOffset; | ||
_centerPosition = new Vector2(CenterRadialOffset * Mathf.Cos(centerAngle), | ||
CenterRadialOffset * Mathf.Sin(centerAngle)); | ||
|
||
_startPoint = GetPositionRadial(startRotation); | ||
|
||
var relativeStartRotation = Trigonometry.ToPolarAngle(_startPoint, _centerPosition); | ||
|
||
var magnitude = (_centerPosition - _startPoint).magnitude; | ||
var startDelta = Trigonometry.GetTangentAngleDelta(CurveRadius, magnitude, false); | ||
|
||
_tangentInRotation = relativeStartRotation + startDelta; | ||
_tangentInPoint = GetPositionRadial(_tangentInRotation, CurveRadius) + | ||
_centerPosition; | ||
|
||
_endPoint = GetPositionRadial(endRotation); | ||
|
||
var relativeEndRotation = Trigonometry.ToPolarAngle(_endPoint, _centerPosition); | ||
var endMagnitude = (_endPoint - _centerPosition).magnitude; | ||
var endDelta = Trigonometry.GetTangentAngleDelta(CurveRadius, endMagnitude, true); | ||
|
||
var tangentOutRotation = relativeEndRotation + endDelta; | ||
_tangentOutPoint = GetPositionRadial(tangentOutRotation, CurveRadius) + | ||
_centerPosition; | ||
|
||
var startSegment = _tangentInPoint - _startPoint; | ||
_startLength = startSegment.magnitude; | ||
_startRotation = Mathf.Atan2(startSegment.y, startSegment.x); | ||
|
||
_curveLength = Trigonometry.GetAngleSpan(_tangentInRotation, tangentOutRotation, | ||
false, Trigonometry.Tau / 4f) * CurveRadius; | ||
|
||
var endSegment = _endPoint - _tangentOutPoint; | ||
var endLength = endSegment.magnitude; | ||
_endRotation = Mathf.Atan2(endSegment.y, endSegment.x); | ||
|
||
_totalLength = _startLength + _curveLength + endLength; | ||
} | ||
|
||
public override float GetLength() | ||
{ | ||
return _totalLength; | ||
} | ||
|
||
public override void GetPoint(float t, out Vector2 position, out float rotation) | ||
{ | ||
var distanceFromStart = t * _totalLength; | ||
|
||
if (distanceFromStart < _startLength) | ||
{ | ||
position = Vector2.Lerp(_startPoint, | ||
_tangentInPoint, | ||
Mathf.InverseLerp(0, | ||
_startLength, | ||
distanceFromStart)); | ||
|
||
rotation = _startRotation; | ||
} | ||
else if (distanceFromStart < _startLength + _curveLength) | ||
{ | ||
var localT = Mathf.InverseLerp(_startLength, _startLength + _curveLength, distanceFromStart); | ||
position = new Vector2(Mathf.Cos(_tangentInRotation + _curveLength / CurveRadius * localT) * | ||
CurveRadius, | ||
Mathf.Sin(_tangentInRotation + _curveLength / CurveRadius * localT) * | ||
CurveRadius); | ||
|
||
var forward = position.Rotate(Trigonometry.Tau / 4); | ||
rotation = Mathf.Atan2(forward.y, forward.x); | ||
position += _centerPosition; | ||
} | ||
else | ||
{ | ||
position = Vector2.Lerp(_tangentOutPoint, | ||
_endPoint, | ||
Mathf.InverseLerp(_startLength + _curveLength, | ||
_totalLength, | ||
distanceFromStart)); | ||
|
||
rotation = _endRotation; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.