Ejemplo n.º 1
0
    void Awake()
    {
        matWorld = transform.localToWorldMatrix;

        if (isCenterPivot)
        {
            matWorld *= SBSMatrix4x4.TRS(-Vector3.forward * lengthOrRadius * 0.5f, SBSQuaternion.identity, SBSVector3.one);
        }

        matInvWorld = matWorld.inverseFast;
    }
Ejemplo n.º 2
0
    void OnDrawGizmosSelected()
    {
        matWorld = transform.localToWorldMatrix;

        if (isCenterPivot)
        {
            matWorld *= SBSMatrix4x4.TRS(-Vector3.forward * lengthOrRadius * 0.5f, SBSQuaternion.identity, SBSVector3.one);
        }

        matInvWorld = matWorld.inverseFast;

        Gizmos.color = Color.white;
        Gizmos.DrawSphere(transform.position, HandleUtility.GetHandleSize(transform.position) * 0.1f);

        this.DrawGizmos(-1.0f, Color.white);
        this.DrawGizmos(1.0f, Color.white);
    }
Ejemplo n.º 3
0
    public void TokenToWorld(float longitudinal, float trasversal, out SBSVector3 pos, out SBSVector3 tang)
#endif
    {
        switch (type)
        {
        case TokenType.Cross:
        case TokenType.Rect:
#if UNITY_FLASH
            matWorld.MultiplyPoint3x4(SBSVector3.right * (trasversal * width * 0.5f) + SBSVector3.forward * (longitudinal * lengthOrRadius), pos);
            matWorld.MultiplyVector(SBSVector3.forward, tang);
#else
            pos  = matWorld.MultiplyPoint3x4(SBSVector3.right * (trasversal * width * 0.5f) + SBSVector3.forward * (longitudinal * lengthOrRadius));
            tang = matWorld.MultiplyVector(SBSVector3.forward);
#endif
            break;

        case TokenType.Curve:
            SBSVector3 center   = (-curveDir * lengthOrRadius) * SBSVector3.right,
                       offset   = ((trasversal * width * 0.5f) + (curveDir * lengthOrRadius)) * SBSVector3.right;
            SBSMatrix4x4 matTr  = SBSMatrix4x4.TRS(center, SBSQuaternion.identity, SBSVector3.one),
                         matRot = SBSMatrix4x4.TRS(SBSVector3.zero, SBSQuaternion.AngleAxis(-arcAngle * curveDir * longitudinal, SBSVector3.up), SBSVector3.one);

#if UNITY_FLASH
            (matWorld * matTr * matRot).MultiplyPoint3x4(offset, pos);
            (matWorld * matRot).MultiplyVector(SBSVector3.forward, tang);
#else
            pos  = (matWorld * matTr * matRot).MultiplyPoint3x4(offset);
            tang = (matWorld * matRot).MultiplyVector(SBSVector3.forward);
#endif
            break;

        default:
            pos.x  = pos.y = pos.z = 0.0f;
            tang.x = tang.y = tang.z = 0.0f;
            break;
        }
    }