Skip to content

Commit

Permalink
Merge pull request #61 from StarCoreSE/collision-detection-ui
Browse files Browse the repository at this point in the history
good enough
  • Loading branch information
InvalidArgument3 authored Dec 23, 2024
2 parents 59c7cba + 5982fab commit 56a1ef7
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions CollisionWarning/Data/Scripts/CollisionPredictor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public class CollisionPredictor : MySessionComponentBase

private int updateCounter = 0;
private Random random = new Random();
private IMyEntity currentCollisionTarget = null;
private Vector3D currentCollisionPoint;
private double currentTimeToCollision;

private class CollisionTarget
{
Expand Down Expand Up @@ -104,7 +101,7 @@ public override void UpdateBeforeSimulation()
if (closestCollisionTarget != null && closestCollisionTarget.TimeToCollision < MaxRange / mySpeed)
{
Color warningColor = GetWarningColor(closestCollisionTarget.TimeToCollision * mySpeed);
DrawThickLine(gridCenter, closestCollisionTarget.Position, warningColor);
DrawLine(gridCenter, closestCollisionTarget.Position, warningColor);

if (updateCounter % NotificationInterval == 0)
{
Expand Down Expand Up @@ -163,22 +160,10 @@ private Vector3D GetRandomDirectionInCone(Vector3D mainDirection)
return Vector3D.Normalize(z * mainDirection + x * perp1 + y * perp2);
}

private bool IsOnCollisionCourse(Vector3D currentPosition, Vector3 velocity, Vector3D obstaclePosition)
{
Vector3D predictedPosition = currentPosition + velocity;
return Vector3D.Distance(predictedPosition, obstaclePosition) < 10;
}

private void DrawLine(Vector3D start, Vector3D end, Color color)
{
Vector4 colorVector = color.ToVector4();
MySimpleObjectDraw.DrawLine(start, end, MyStringId.GetOrCompute("Square"), ref colorVector, 1f);
}

private void DrawThickLine(Vector3D start, Vector3D end, Color color)
{
Vector4 colorVector = color.ToVector4();
MySimpleObjectDraw.DrawLine(start, end, MyStringId.GetOrCompute("Square"), ref colorVector, 2f);
MySimpleObjectDraw.DrawLine(start, end, MyStringId.GetOrCompute("Square"), ref colorVector, 0.5f);
}

protected override void UnloadData() { }
Expand Down

0 comments on commit 56a1ef7

Please sign in to comment.