Beispiel #1
0
    private static int FindHoleClosestToEdge(ISpline mainSpline, List <ISpline> holes)
    {
        int   holeIndex    = 0;
        float holeDistance = 0;

        for (int i = 0; i < holes.Count; i++)
        {
            float   cutPointSplinePosition     = 0;
            float   holeCutPointSplinePosition = 0;
            Vector3 cutPointPosition           = mainSpline.GetPointAt(0).Position;
            Vector3 holeCutPointPosition       = holes[i].GetPointAt(0).Position;
            float   cutPointDistance           = 0;

            GetCutPointData(mainSpline, holes[i], ref cutPointSplinePosition, ref holeCutPointSplinePosition, ref cutPointPosition, ref holeCutPointPosition, ref cutPointDistance);

            if (i == 0)
            {
                holeDistance = cutPointDistance;
                continue;
            }

            if (cutPointDistance >= holeDistance)
            {
                continue;
            }

            holeIndex    = i;
            holeDistance = cutPointDistance;
        }
        return(holeIndex);
    }
Beispiel #2
0
    private static bool IsInsideSpline(ISpline mainSpline, ISpline subSpline)
    {
        if (mainSpline.PointsCount < 3)
        {
            return(false);
        }
        if (subSpline.PointsCount < 3)
        {
            return(false);
        }
        bool pointsInSpline = true;

        for (int i = 0; i < subSpline.PointsCount; i++)
        {
            var point = subSpline.GetPointAt(i).Position;
            pointsInSpline = SplineContainsPoint(mainSpline, point);
            if (!pointsInSpline)
            {
                break;
            }
        }
        if (!pointsInSpline)
        {
            return(false);
        }
        return(true);
    }
 /// <summary> Caches the original world position of the spline points. Very useful for Pivotools. </summary>
 private static void CachePointsDefaultData(ISpline path, RageGroupElement item, int pathPointCount)
 {
     for (int i = 0; i < pathPointCount; i++)
     {
         item.GroupPointCache[i] = new RageGroupPointCache();
         ISplinePoint point = path.GetPointAt(i);
         item.GroupPointCache[i].PointPos   = point.Position;
         item.GroupPointCache[i].InCtrlPos  = point.InTangent;
         item.GroupPointCache[i].OutCtrlPos = point.OutTangent;
     }
 }
Beispiel #4
0
    private static bool SplineContainsPoint(ISpline spline, Vector2 point)
    {
        var j        = spline.PointsCount - 1;
        var oddNodes = false;

        for (var i = 0; i < spline.PointsCount; i++)
        {
            var iPoint = spline.GetPointAt(i).Position;
            var jPoint = spline.GetPointAt(j).Position;
            if (iPoint.y < point.y && jPoint.y >= point.y || jPoint.y < point.y && iPoint.y >= point.y)
            {
                if (iPoint.x + (point.y - iPoint.y) / (jPoint.y - iPoint.y) * (jPoint.x - iPoint.x) < point.x)
                {
                    oddNodes = !oddNodes;
                }
            }
            j = i;
        }

        return(oddNodes);
    }
    private void FeedColliderData(ICollection <RageMagnetPoint> pointList, ISpline spline, int index)
    {
        ISpline rageSpline = spline;

        if (!this.ActiveColliderContains(rageSpline, index))
        {
            return;
        }

        float pointOffset   = 1;
        float inCtrlOffset  = 1;
        float outCtrlOffset = 1;

        var point      = rageSpline.GetPointAt(index);
        var inCtrlPos  = point.InTangent;
        var outCtrlPos = point.OutTangent;
        var pointPos   = point.Position;

        if (VaryStrength)
        {
            RageMagnetMath.AdjustOffsetCheck(ActiveCollider, pointPos, inCtrlPos, outCtrlPos,
                                             ref pointOffset, ref inCtrlOffset, ref outCtrlOffset, StrengthMin, StrengthMax,
                                             Quaternion.Inverse(transform.rotation));
        }

        if (!this.ActiveInnerColliderContains(rageSpline, index))
        {
            var nullifyRotation = Quaternion.Inverse(transform.rotation);
            var centerPosition  = ActiveCollider.bounds.center;

            pointOffset *= Mathf.InverseLerp(ColliderRadius, InnerColliderRadius,
                                             this.SphericalProjectionDistance(centerPosition, pointPos, nullifyRotation));

            if (!ActiveInnerCollider.bounds.Contains(inCtrlPos))
            {
                inCtrlOffset *= Mathf.InverseLerp(ColliderRadius, InnerColliderRadius,
                                                  this.SphericalProjectionDistance(centerPosition, inCtrlPos, nullifyRotation));
            }

            if (!ActiveInnerCollider.bounds.Contains(outCtrlPos))
            {
                outCtrlOffset *= Mathf.InverseLerp(ColliderRadius, InnerColliderRadius,
                                                   this.SphericalProjectionDistance(centerPosition, outCtrlPos, nullifyRotation));
            }
        }

        var containedPoint = RageMagnetPoint.Instantiate(this, rageSpline, index, pointOffset, inCtrlOffset,
                                                         outCtrlOffset, pointPos, inCtrlPos, outCtrlPos, RestPosition);

        pointList.Add(containedPoint);
    }
Beispiel #6
0
    private static bool Contains(RageMagnet rm, Collider collider, ISpline spline, int index)
    {
        Vector3 worldPos = spline.GetPointAt(index).Position;

        return(Contains(rm, collider, worldPos));
    }
Beispiel #7
0
    private static void MakeHole(ISpline mainSpline, ISpline subSpline)
    {
        float   cutPointSplinePosition     = 0;
        float   holeCutPointSplinePosition = 0;
        Vector3 cutPointPosition           = mainSpline.GetPointAt(0).Position;
        Vector3 holeCutPointPosition       = subSpline.GetPointAt(0).Position;
        float   cutPointDistance           = 0;

        GetCutPointData(mainSpline, subSpline, ref cutPointSplinePosition, ref holeCutPointSplinePosition, ref cutPointPosition, ref holeCutPointPosition, ref cutPointDistance);

        int startCutPointIdx = mainSpline.Rs.spline.GetNearestSplinePointIndex(cutPointSplinePosition);

        if (Vector2.Distance(mainSpline.GetPointAt(startCutPointIdx).Position, cutPointPosition) > 0.1f)
        {
            startCutPointIdx = mainSpline.Rs.AddPoint(cutPointSplinePosition);
        }
        var startCutPoint = mainSpline.GetPointAt(startCutPointIdx);

        var endCutPointIdx = mainSpline.AddPointLocal(startCutPointIdx + 1, startCutPoint.PositionLocal, Vector3.zero, startCutPoint.OutTangentLocal, 1.0f, false).Index;

        startCutPoint.OutTangentLocal = Vector3.zero;

        int holeCutPointIdx = subSpline.Rs.spline.GetNearestSplinePointIndex(holeCutPointSplinePosition);

        if (Vector2.Distance(subSpline.GetPointAt(holeCutPointIdx).Position, holeCutPointPosition) > 0.1)
        {
            holeCutPointIdx = subSpline.Rs.AddPoint(holeCutPointSplinePosition);
        }

        if ((holeCutPointIdx != 0) && (holeCutPointIdx != subSpline.PointsCount - 1))
        {
            while (holeCutPointIdx != 0)
            {
                subSpline.GetPointAt(subSpline.PointsCount - 1).OutTangentLocal = subSpline.GetPointAt(0).OutTangentLocal;
                subSpline.RemovePointAt(0);
                var firstHolePoint = subSpline.GetPointAt(0);
                subSpline.AddPointLocal(subSpline.PointsCount, firstHolePoint.PositionLocal, firstHolePoint.InTangentLocal, firstHolePoint.OutTangentLocal, 1.0f, false);
                holeCutPointIdx--;
            }
        }

        float   distanceOffset = 0.01f;
        Vector3 fowardVector   = subSpline.PointsAreInClockWiseOrder() ? Vector3.forward : Vector3.back;
        Vector3 vectorOffset   = Vector3.Cross(fowardVector, subSpline.GetPointAt(0).Position - startCutPoint.Position);

        vectorOffset = distanceOffset * vectorOffset.normalized;
        subSpline.GetPointAt(0).Position += vectorOffset;
        startCutPoint.Position           += vectorOffset;

        for (int i = 0; i < subSpline.PointsCount; i++)
        {
            var holePoint = subSpline.GetPointAt(i);
            if (i == subSpline.PointsCount - 1)
            {
                mainSpline.AddPointLocal(endCutPointIdx, holePoint.PositionLocal, holePoint.InTangentLocal, Vector3.zero, 1.0f, false);
            }
            else
            if (i == 0)
            {
                mainSpline.AddPointLocal(endCutPointIdx, holePoint.PositionLocal, Vector3.zero, holePoint.OutTangentLocal, 1.0f, false);
            }
            else
            {
                mainSpline.AddPointLocal(endCutPointIdx, holePoint.PositionLocal, holePoint.InTangentLocal, holePoint.OutTangentLocal, 1.0f, false);
            }
            endCutPointIdx++;
        }
    }