Exemplo n.º 1
0
 public void ApplyDeformations(RageMagnet magnet, Vector3 posOffset, Vector3 scaleOffset)
 {
     Changed = true;
     ApplyRotation(magnet);
     ApplyPosition(magnet, posOffset);
     ApplyScale(magnet, scaleOffset);
 }
Exemplo n.º 2
0
    private void ApplyScale(RageMagnet magnet, Vector3 scaleOffset)
    {
        RageMagnetPointData pointData = FindRelatedData(magnet);

        ApplyScale(ref pointData.PointPos, Vector3.one + pointData.PointOffset * scaleOffset);
        ApplyScale(ref pointData.InCtrlPos, Vector3.one + pointData.InCtrlOffset * scaleOffset);
        ApplyScale(ref pointData.OutCtrlPos, Vector3.one + pointData.OutCtrlOffset * scaleOffset);
    }
Exemplo n.º 3
0
    private void ApplyPosition(RageMagnet magnet, Vector3 baseOffset)
    {
        RageMagnetPointData pointData = FindRelatedData(magnet);

        pointData.PointPos   += baseOffset * pointData.PointOffset;
        pointData.InCtrlPos  += baseOffset * pointData.InCtrlOffset;
        pointData.OutCtrlPos += baseOffset * pointData.OutCtrlOffset;
    }
Exemplo n.º 4
0
    private void ApplyRotation(RageMagnet magnet)
    {
        var relativeData = FindRelatedData(magnet);

        ApplyRotation(magnet, ref relativeData.PointPos, relativeData.PointOffset);
        ApplyRotation(magnet, ref relativeData.InCtrlPos, relativeData.InCtrlOffset);
        ApplyRotation(magnet, ref relativeData.OutCtrlPos, relativeData.OutCtrlOffset);
    }
Exemplo n.º 5
0
 private static void CenterZCapsuleCollider(RageMagnet rm, float z)
 {
     if (rm.CapsuleCollider == null)
     {
         return;
     }
     rm.CapsuleCollider.center      = new Vector3(rm.CapsuleCollider.center.x, rm.CapsuleCollider.center.y, z);
     rm.InnerCapsuleCollider.center = rm.CapsuleCollider.center;
 }
Exemplo n.º 6
0
    private void RemovePointData(RageMagnet magnet)
    {
        List <RageMagnetPointData> points = new List <RageMagnetPointData>(RelatedData.Length);

        foreach (RageMagnetPointData pointData in RelatedData)
        {
            if (pointData.Magnet != magnet)
            {
                points.Add(pointData);
            }
        }
        RelatedData = points.ToArray();
    }
Exemplo n.º 7
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;
    }
Exemplo n.º 8
0
    private static void CalculateColliderAttributes(RageMagnet rm)
    {
        if (!rm.ResetValues)
        {
            return;
        }
        rm.ResetValues = false;

        if (rm.ActiveCollider == null)
        {
            return;
        }
        CalculateInnerCollider(rm);
    }
Exemplo n.º 9
0
 private static void CalculateInnerCollider(RageMagnet rm)
 {
     if (rm.ActiveCollider == null)
     {
         return;
     }
     rm.InnerCapsuleCollider.radius    = rm.CapsuleCollider.radius * rm.InnerSize / 100;
     rm.InnerCapsuleCollider.direction = rm.CapsuleCollider.direction;
     rm.InnerCapsuleCollider.height    = rm.CapsuleCollider.height - (2 * (rm.CapsuleCollider.radius - rm.InnerCapsuleCollider.radius));
     if (rm.InnerSphereCollider == null || rm.SphereCollider == null)
     {
         return;
     }
     rm.InnerSphereCollider.radius = rm.SphereCollider.radius * rm.InnerSize / 100;
 }
Exemplo n.º 10
0
 public static void RemoveMagnetsFromPoint(RageMagnet magnet, RageMagnetPoint[] points)
 {
     if (points == null)
     {
         return;
     }
     foreach (RageMagnetPoint point in points)
     {
         if (point == null)
         {
             continue;
         }
         point.RemovePointData(magnet);
     }
 }
    public static RageMagnetPointData Instantiate(RageMagnet magnet, Vector3 pointPos, Vector3 inCtrlPos, Vector3 outCtrlPos, Vector3 currentPosition)
    {
        var point = (RageMagnetPointData)CreateInstance(typeof(RageMagnetPointData));

        point.Magnet             = magnet;
        point.AbsolutePointPos   = pointPos;
        point.AbsoluteInCtrlPos  = inCtrlPos;
        point.AbsoluteOutCtrlPos = outCtrlPos;

        point.PointPos   = point.InitialPos = pointPos - currentPosition;
        point.InCtrlPos  = point.InitialInCtrlPos = inCtrlPos - currentPosition;
        point.OutCtrlPos = point.InitialOutCtrlPos = outCtrlPos - currentPosition;

        return(point);
    }
Exemplo n.º 12
0
    private static bool Contains(RageMagnet rm, Collider collider, Vector3 worldPointPos)
    {
        // ATTENTION: Collider radius and height is in local space! Bounds data is in world space.
        // To normalize, we'll convert everything-world to local space using InverseTransformPoint
        if (!collider.bounds.Contains(worldPointPos))
        {
            return(false);
        }
        Vector3 localPointPos       = rm.transform.InverseTransformPoint(worldPointPos);
        Vector3 localColliderCenter = rm.transform.InverseTransformPoint(rm.ActiveCollider.bounds.center);

        if (rm.ActiveColliderIsSphere)
        {
            var sphere = (SphereCollider)collider;
            return((localPointPos - localColliderCenter).magnitude <= sphere.radius);
        }

        var capsule = (CapsuleCollider)collider;

        //Debug.Log(" point local x: "+ localPointPos.x + " | local collider center x: "+ localColliderCenter.x + " | Capsule Radius: " + capsule.radius);

        if (Mathf.Abs(localPointPos.x - localColliderCenter.x) > capsule.radius)
        {
            return(false);
        }

        float cylinderHalfHeight = (capsule.height / 2) - capsule.radius;

        if (cylinderHalfHeight <= 0)
        {
            return((localPointPos - localColliderCenter).magnitude <= capsule.radius);
        }

        float minY = localColliderCenter.y - cylinderHalfHeight;
        float maxY = localColliderCenter.y + cylinderHalfHeight;

        if (localPointPos.y >= minY && localPointPos.y <= maxY)
        {
            return(true);
        }

        if (localPointPos.y > localColliderCenter.y)
        {
            return(Vector3.Distance(new Vector3(localColliderCenter.x, maxY, localColliderCenter.z), localPointPos) <= capsule.radius);
        }

        return(Vector3.Distance(new Vector3(localColliderCenter.x, minY, localColliderCenter.z), localPointPos) <= capsule.radius);
    }
Exemplo n.º 13
0
    public static void AddInnerColliders(this RageMagnet rm, ref GameObject innerColliders)
    {
        if (innerColliders != null)
        {
            return;
        }

        innerColliders = new GameObject {
            name = RageMagnet.InnerRadiusId
        };
        innerColliders.transform.position = rm.gameObject.transform.position;
        innerColliders.transform.rotation = rm.gameObject.transform.rotation;
        innerColliders.transform.parent   = rm.gameObject.transform;

        AddColliders(innerColliders);
    }
Exemplo n.º 14
0
    public static Vector3 SphericalProjection(this RageMagnet magnet, Vector3 pointPosition, Quaternion nullifyRotation)
    {
        Collider cl = magnet.ActiveInnerCollider;

        if (cl == null)
        {
            throw new Exception("Null collider");
        }

        float clRadius;
        float clHeight;

        if (cl is CapsuleCollider)
        {
            var capsuleCollider = (CapsuleCollider)cl;
            clHeight = capsuleCollider.height;
            clRadius = capsuleCollider.radius;
        }
        else
        {
            clRadius = ((SphereCollider)cl).radius;
            clHeight = 0;
        }

        if ((2 * clRadius) >= clHeight)
        {
            return(pointPosition);
        }

        Vector3 relativePos = pointPosition - cl.bounds.center;

        pointPosition = (nullifyRotation * relativePos) + cl.bounds.center;

        float halfHeightOffset = (clHeight / 2) - clRadius;
        float yCenterPosition  = cl.bounds.center.y;

        if ((new Vector3(0f, pointPosition.y - yCenterPosition, 0f).magnitude <= halfHeightOffset))
        {
            return(new Vector3(pointPosition.x, yCenterPosition, pointPosition.z));
        }

        return(new Vector3(pointPosition.x, pointPosition.y > yCenterPosition ?
                           pointPosition.y - halfHeightOffset :
                           pointPosition.y + halfHeightOffset, pointPosition.z));
    }
Exemplo n.º 15
0
    private static void CheckColliderChange(RageMagnet rm)
    {
        if (rm.CapsuleCollider != null)
        {
            rm.ResetValues                  = true;
            rm.CapsuleCollider.enabled      = (!rm.ActiveColliderIsSphere);
            rm.InnerCapsuleCollider.enabled = rm.CapsuleCollider.enabled;
//          if(!rm.InnerCapsuleCollider.enabled) {
//              rm.CapsuleCollider.radius = 0;
//              rm.CapsuleCollider.height = 0;
//              rm.InnerCapsuleCollider.radius = 0;
//              rm.InnerCapsuleCollider.height = 0;
//          }
        }

        if (rm.SphereCollider != null)
        {
            rm.ResetValues                 = true;
            rm.SphereCollider.enabled      = (rm.ColliderType == RageMagnet.ColliderTypes.Sphere);
            rm.InnerSphereCollider.enabled = rm.SphereCollider.enabled;
//          if(!rm.InnerSphereCollider.enabled) {
//              rm.SphereCollider.radius = 0;
//              rm.InnerSphereCollider.radius = 0;
//          }
        }

        if (rm.SphereCollider != null)
        {
            rm.InnerSphereCollider.center = rm.SphereCollider.center;
        }
        if (rm.CapsuleCollider != null)
        {
            rm.InnerCapsuleCollider.center = rm.CapsuleCollider.center;
        }
        if (rm.ActiveCollider != null)
        {
            return;
        }

        AddColliders(rm.gameObject);
        rm.AddInnerColliders();
    }
Exemplo n.º 16
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);
    }
Exemplo n.º 17
0
 public static bool ActiveColliderContains(this RageMagnet rm, ISpline spline, int index)
 {
     return(Contains(rm, rm.ActiveCollider, spline, index));
 }
Exemplo n.º 18
0
 public static void AddInnerColliders(this RageMagnet rm)
 {
     AddInnerColliders(rm, ref rm.InnerColliders);
 }
Exemplo n.º 19
0
    private static void ApplyRotation(RageMagnet magnet, ref Vector3 position, float offset)
    {
        Quaternion proportionalRotationOffset = magnet.GetTransformRotation(offset);

        position = (proportionalRotationOffset * position);
    }
Exemplo n.º 20
0
 public static float SphericalProjectionDistance(this RageMagnet magnet, Vector3 centerPosition, Vector3 pointPos, Quaternion nullifyRotation)
 {
     return(Vector3.Distance(SphericalProjection(magnet, pointPos, nullifyRotation), centerPosition));
 }
Exemplo n.º 21
0
 public static void CenterZ(RageMagnet rm, float z)
 {
     CenterZSphereCollider(rm, z);
     CenterZCapsuleCollider(rm, z);
 }
Exemplo n.º 22
0
 public static Vector3 CalculateDeformations(this RageMagnet magnet, Vector3 pointPos, Vector3 posOffset)
 {
     return(pointPos + posOffset);
 }
Exemplo n.º 23
0
    private static bool Contains(RageMagnet rm, Collider collider, ISpline spline, int index)
    {
        Vector3 worldPos = spline.GetPointAt(index).Position;

        return(Contains(rm, collider, worldPos));
    }
Exemplo n.º 24
0
 public static bool ActiveColliderContains(this RageMagnet rm, Vector3 worldPos)
 {
     return(Contains(rm, rm.ActiveCollider, worldPos));
 }
Exemplo n.º 25
0
 public static void FixCollidersCheck(this RageMagnet rm)
 {
     CheckColliderChange(rm);
     CalculateColliderAttributes(rm);
     CalculateInnerCollider(rm);
 }
Exemplo n.º 26
0
 public static Quaternion GetTransformRotation(this RageMagnet magnet, float weight)
 {
     return(Quaternion.Slerp(magnet.RestRotation, magnet.transform.rotation, weight) * Quaternion.Inverse(magnet.RestRotation));
 }