Esempio n. 1
0
        void DrawLine(LSystem.Token token, LSystem system)
        {
            float   lineLength  = _lineLength;
            Vector3 offset      = Vector3.zero;
            Vector3 pointStartA = _currentPosition;
            Vector3 pointStartB = _currentPosition;

            bool isParentDrawable = false;

            if (token.Parent != null)
            {
                if (ContainsAction(token.Parent.Sign))
                {
                    ActionData data = GetActionData(token.Parent.Sign);
                    isParentDrawable = data.IsDrawable;
                }
            }

            Vector3 pointEndA = _currentPosition;
            Vector3 pointEndB = _currentPosition + Quaternion.Euler(0f, 0f, _currentAngle) * new Vector3(lineLength, 0f, 0f);

            if (token.Parent != null)
            {
                if (token.IsNewBranch || !isParentDrawable)
                {
                    lineLength = _lineLength / Mathf.Pow(system.Data.DepthFactor, (system.Depth() - 1));

                    // Begin of line
                    pointStartA = _currentPosition;
                    pointStartB = _currentPosition;

                    // End of line
                    pointEndA = pointStartA;
                    pointEndB = _currentPosition + Quaternion.Euler(0f, 0f, _currentAngle) * new Vector3(lineLength, 0f, 0f);
                }
                else
                {
                    // Split the current branch
                    float ratioStart = (float)(token.DrawableId - 1) / (float)token.DrawableIdMax;
                    float ratioEnd   = (float)token.DrawableId / (float)token.DrawableIdMax;

                    // Begin of line
                    pointStartA = token.Parent.Start + (token.Parent.End - token.Parent.Start) * ratioStart;
                    pointStartB = token.Parent.Start + (token.Parent.End - token.Parent.Start) * ratioEnd;

                    // End of line
                    pointEndA = pointStartA;
                    pointEndB = pointStartB;
                }
            }

            _currentPosition = pointEndB;

            // if isParentDrawable -> changer l'ordre de dessin
            _RenderManager.CreateInterpolableLine(token.Depth + token.DrawableId, pointStartA, pointEndA, pointStartB, pointEndB);
            //Debug.Log("New line - token: " + token.ToString() + " | pointStartA: " + start1.ToString("F2") + " | pointEndA : " + pointEndA.ToString("F2") + " | pointStartB: " + pointStartB.ToString("F2") + " |pointEndB: " + pointEndB.ToString("F2"));

            token.Start = pointEndA;
            token.End   = pointEndB;
            _segmentCount++;
        }