Ejemplo n.º 1
0
        public void Transform(SBSMatrix4x4 matrix)
        {
            int i = 0;

            SBSVector3[] vertices = this.GetVertices();

            for (; i < 8; ++i)
#if UNITY_FLASH
            { matrix.MultiplyPoint3x4(vertices[i], vertices[i]); }
#else
            { matrix.MultiplyPoint3x4(vertices[i], out vertices[i]); }
#endif

            this.Reset();
            for (i = 0; i < 8; ++i)
            {
                this.Encapsulate(vertices[i]);
            }
        }
Ejemplo n.º 2
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;
        }
    }
Ejemplo n.º 3
0
    public void WorldToToken(SBSVector3 worldPos, out float longitudinal, out float trasversal)
    {
        switch (type)
        {
        case TokenType.Cross:
        case TokenType.Rect:
            SBSVector3 localPos = matInvWorld.MultiplyPoint3x4(worldPos);
            longitudinal = SBSVector3.Dot(localPos, SBSVector3.forward) / lengthOrRadius;
            trasversal   = SBSVector3.Dot(localPos, SBSVector3.right) * 2.0f / width;
            break;

        case TokenType.Curve:
            SBSVector3 c  = this.Center,
                       p0 = matWorld.position - c,
                       p1 = worldPos - c;

            p0.DecrementBy(SBSVector3.Dot(p0, SBSVector3.up) * SBSVector3.up);
            p1.DecrementBy(SBSVector3.Dot(p1, SBSVector3.up) * SBSVector3.up);

            float sign  = SBSMath.Sign(SBSVector3.Dot(SBSVector3.Cross(p0, p1), SBSVector3.up));
            float angle = SBSVector3.Angle(p0, p1);

            longitudinal = angle / arcAngle;
            if (sign == curveDir)
            {
                longitudinal *= -1.0f;
            }
            trasversal = (p1.magnitude - lengthOrRadius) * 2.0f * curveDir / width;
            break;

        default:
            longitudinal = 0.0f;
            trasversal   = 0.0f;
            break;
        }
    }