private void CalculateContainedPoints()
    {
        TouchingSplines = null;
        RageMagnetPoint.RemoveMagnetsFromPoint(this, Points);

        List <ISpline>         splines = new List <ISpline>();
        List <RageMagnetPoint> points  = new List <RageMagnetPoint>();

        foreach (RageGroupElement item in Group.List)
        {
            ISpline spline = item.Spline;
            if (spline == null)
            {
                continue;
            }
            for (int i = 0; i < (spline).PointsCount; i++)
            {
                FeedColliderData(points, spline, i);
                if (!splines.Contains(spline))
                {
                    splines.Add(spline);
                }
            }
        }

        TouchingSplines = splines.ToArray();
        Points          = points.ToArray();
    }
    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);
    }
예제 #3
0
    public static void CalculateDeformations(this RageMagnet magnet, RageMagnetPoint ragePoint, Vector3 posOffset, Vector3 scaleOffset)
    {
        RageMagnetPointData pointData = ragePoint.FindRelatedData(magnet);

        pointData.PointPos   = pointData.InitialPos;
        pointData.InCtrlPos  = pointData.InitialInCtrlPos;
        pointData.OutCtrlPos = pointData.InitialOutCtrlPos;

        ragePoint.ApplyDeformations(magnet, posOffset, scaleOffset);

        pointData.AbsolutePointPos   = pointData.PointPos + magnet.RestPosition;
        pointData.AbsoluteInCtrlPos  = pointData.InCtrlPos + magnet.RestPosition;
        pointData.AbsoluteOutCtrlPos = pointData.OutCtrlPos + magnet.RestPosition;
    }
    private void NormalizeInfluences()
    {
        var points = RageMagnetPoint.GetAllMagnetPoints(Group);

        foreach (RageMagnetPoint magnetPoint in points)
        {
            var pointOffsetSum   = 0f;
            var inCtrlOffsetSum  = 0f;
            var outCtrlOffsetSum = 0f;
            var pointsData       = magnetPoint.RelatedData;
            int count            = 0;

            foreach (RageMagnetPointData point in pointsData)
            {
                pointOffsetSum   += point.PointOffset;
                inCtrlOffsetSum  += point.InCtrlOffset;
                outCtrlOffsetSum += point.OutCtrlOffset;
                count++;
            }

            if (pointOffsetSum < count && count > 1)
            {
                foreach (var point in pointsData)
                {
                    point.PointOffset   = 1;
                    point.InCtrlOffset  = 1;
                    point.OutCtrlOffset = 1;
                }
                continue;
            }

            bool normalizePos = pointOffsetSum > 1f;
            foreach (var point in pointsData)
            {
                if (!normalizePos)
                {
                    continue;
                }
                point.PointOffset   *= count / pointOffsetSum;
                point.InCtrlOffset  *= count / inCtrlOffsetSum;
                point.OutCtrlOffset *= count / outCtrlOffsetSum;
            }
        }
    }
예제 #5
0
    public static RageMagnetPoint Instantiate(RageMagnet magnet, ISpline rageSpline, int index,
                                              float pointOffset, float inCtrlOffset, float outCtrlOffset,
                                              Vector3 pointPos, Vector3 inCtrlPos, Vector3 outCtrlPos,
                                              Vector3 currentPosition)
    {
        List <RageMagnetPoint> points = GetAllMagnetPoints();
        RageMagnetPoint        result = null;

        foreach (RageMagnetPoint point in points)
        {
            if (rageSpline.Oid != point.Spline.Oid)
            {
                continue;
            }
            if (index != point.Index)
            {
                continue;
            }
            result = point;
            break;
        }

        if (result == null)
        {
            result = CreateInstance(typeof(RageMagnetPoint)) as RageMagnetPoint;
        }

        result.Spline = rageSpline;
        result.Index  = index;

        result.RemovePointData(magnet);
        var magnetPointData = RageMagnetPointData.Instantiate(magnet, pointPos, inCtrlPos, outCtrlPos, currentPosition);

        result.AddRelatedData(magnetPointData);

        magnetPointData.PointOffset   = pointOffset;
        magnetPointData.InCtrlOffset  = inCtrlOffset;
        magnetPointData.OutCtrlOffset = outCtrlOffset;

        return(result);
    }
예제 #6
0
    public static void AverageMagnetPoint(this RageMagnetPoint ragePoint)
    {
        var pointsData = ragePoint.RelatedData;

        Vector3 pointPosSum   = Vector3.zero;
        Vector3 inCtrlPosSum  = Vector3.zero;
        Vector3 outCtrlPosSum = Vector3.zero;

        foreach (var relativeData in pointsData)
        {
            pointPosSum   += relativeData.AbsolutePointPos;
            inCtrlPosSum  += relativeData.AbsoluteInCtrlPos;
            outCtrlPosSum += relativeData.AbsoluteOutCtrlPos;
        }

        ISplinePoint point = ragePoint.Spline.GetPointAt(ragePoint.Index);

        point.Position   = pointPosSum / pointsData.Length;
        point.InTangent  = inCtrlPosSum / pointsData.Length;
        point.OutTangent = outCtrlPosSum / pointsData.Length;
    }