Exemplo n.º 1
0
    void Update()
    {
        if (_interpretor != null && !_interpretor.IsDoneExecuting())
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            _currentIndex = _currentIndex > 0 ? _currentIndex - 1 : _systemDatas.Count - 1;
            _system.Data  = _systemDatas[_currentIndex].Data;
            _interpretor.Reset();
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            _currentIndex = _currentIndex < _systemDatas.Count - 1 ? _currentIndex + 1 : 0;
            _system.Data  = _systemDatas[_currentIndex].Data;
            _interpretor.Reset();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            _system.Reset();
            _interpretor.Reset();
        }

        if (Input.GetKey(KeyCode.Space))
        {
            if (_system.Depth() >= 0)
            {
                // Draw
                _interpretor.Reset();
                _interpretor.Execute(_system);
            }

            // Compute next generation
            _system.NextGeneration();
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            _showUI = !_showUI;
        }
    }
Exemplo n.º 2
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++;
        }
Exemplo n.º 3
0
        void Move(LSystem.Token token, LSystem system)
        {
            float lineLength = _lineLength / Mathf.Pow(system.Data.DepthFactor, (system.Depth() - 1));

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