Beispiel #1
0
        public LedgeAnchor UpdateAnchor(LedgeAnchor anchor, float3 position)
        {
            int a = anchor.index;
            int b = GetNextEdgeIndex(anchor.index);

            float3 closestPoint =
                ClosestPoint.FromPosition(position,
                                          vertices[a], vertices[b]);

            LedgeAnchor result;

            float length   = math.length(vertices[b] - vertices[a]);
            float distance = math.length(closestPoint - vertices[a]);

            if (distance > length)
            {
                result.distance = distance - length;
                result.index    = GetNextEdgeIndex(anchor.index);

                return(result);
            }
            else if (distance < 0.0f)
            {
                result.index    = GetPreviousEdgeIndex(anchor.index);
                result.distance = GetLength(result.index) + distance;

                return(result);
            }

            result.distance = distance;
            result.index    = anchor.index;

            return(result);
        }
Beispiel #2
0
        public void DebugDraw(ref LedgeAnchor state)
        {
            float3 position = GetPosition(state);
            float3 normal   = GetNormal(state);

            Debug.DrawLine(position, position + normal * 0.3f, Color.red);
        }
Beispiel #3
0
        public LedgeAnchor GetAnchor(float3 position)
        {
            LedgeAnchor result = new LedgeAnchor();

            float3 closestPoint =
                ClosestPoint.FromPosition(position,
                                          vertices[0], vertices[1]);
            float minimumDistance =
                math.length(closestPoint - position);

            result.distance = math.length(closestPoint - vertices[0]);

            int numEdges = vertices.Length;

            for (int i = 1; i < numEdges; ++i)
            {
                closestPoint =
                    ClosestPoint.FromPosition(position,
                                              vertices[i], vertices[GetNextEdgeIndex(i)]);
                float distance =
                    math.length(closestPoint - position);
                if (distance < minimumDistance)
                {
                    minimumDistance = distance;
                    result.index    = i;
                    result.distance =
                        math.length(closestPoint - vertices[i]);
                }
            }

            result.distance = math.clamp(
                result.distance, 0.0f, GetLength(result.index));

            return(result);
        }
Beispiel #4
0
        public LedgeAnchor UpdateAnchor(LedgeAnchor anchor, float displacement)
        {
            LedgeAnchor result;

            int a = anchor.index;
            int b = GetNextEdgeIndex(anchor.index);

            float length   = math.length(vertices[b] - vertices[a]);
            float distance = anchor.distance + displacement;

            if (distance > length)
            {
                result.distance = distance - length;
                result.index    = GetNextEdgeIndex(anchor.index);

                return(result);
            }
            else if (distance < 0.0f)
            {
                result.index    = GetPreviousEdgeIndex(anchor.index);
                result.distance = GetLength(result.index) + distance;

                return(result);
            }

            result.distance = distance;
            result.index    = anchor.index;

            return(result);
        }
Beispiel #5
0
        public AffineTransform GetTransform(LedgeAnchor anchor)
        {
            float3 p    = GetPosition(anchor);
            float3 edge = GetNormalizedEdge(anchor.index);
            float3 up   = Missing.up;
            float3 n    = GetNormal(anchor);

            return(new AffineTransform(p,
                                       math.quaternion(math.float3x3(edge, up, n))));
        }
    public override void OnEnable()
    {
        base.OnEnable();

        state         = State.Suspended;
        previousState = State.Suspended;

        climbingState              = ClimbingState.Idle;
        previousClimbingState      = ClimbingState.Idle;
        lastCollidingClimbingState = ClimbingState.None;

        clothComponents = GetComponentsInChildren <Cloth>();

        ledgeGeometry = LedgeGeometry.Create();
        wallGeometry  = WallGeometry.Create();

        ledgeAnchor = LedgeAnchor.Create();
        wallAnchor  = WallAnchor.Create();

        transition = MemoryIdentifier.Invalid;
        locomotion = MemoryIdentifier.Invalid;
    }
Beispiel #7
0
    public override void OnEnable()
    {
        base.OnEnable();

        kinematica = GetComponent <Kinematica>();

        state         = State.Suspended;
        previousState = State.Suspended;

        climbingState              = ClimbingState.Idle;
        previousClimbingState      = ClimbingState.Idle;
        lastCollidingClimbingState = ClimbingState.None;

        clothComponents = GetComponentsInChildren <Cloth>();

        ledgeGeometry = LedgeGeometry.Create();
        wallGeometry  = WallGeometry.Create();

        ledgeAnchor = LedgeAnchor.Create();
        wallAnchor  = WallAnchor.Create();

        anchoredTransition = AnchoredTransitionTask.Invalid;
    }
Beispiel #8
0
 public float3 GetNormal(LedgeAnchor anchor)
 {
     return(-math.cross(
                GetNormalizedEdge(anchor.index), Missing.up));
 }
Beispiel #9
0
 public float3 GetPosition(LedgeAnchor anchor)
 {
     return(vertices[anchor.index] +
            GetNormalizedEdge(anchor.index) * anchor.distance);
 }