void RestoreDrawState(LSystem.Token token, LSystem system)
        {
            DrawState drawState = _savedPositions.Pop();

            _currentPosition = drawState.Position;
            _currentAngle    = drawState.Angle;
            _lineLength      = drawState.LineLength;
            _segmentCount    = drawState.SegmentCount;
        }
        void DrawCircle(LSystem.Token token, LSystem system)
        {
            float sizeStart = _lineLength;
            float sizeEnd   = sizeStart;

            if (token.Parent == null || token.Parent.Sign != 'C')
            {
                // New circle
                sizeStart = 0f;
            }
            _RenderManager.CreateInterpolableCircle(token.Depth + token.DrawableId, _currentPosition, _currentPosition, sizeStart, sizeEnd);

            token.Start = _currentPosition;
            token.End   = _currentPosition;
        }
Beispiel #3
0
        public override string Evaluate(LSystem.Token token)
        {
            Assert.IsNotNull(_ruleParams, "StochasticRule.Evaluate: There are no entries.");
            Assert.IsTrue(_ruleParams.Count > 0, "StochasticRule.Evaluate: There are no entries.");

            float rand        = Random.value;
            float probability = 0f;

            foreach (RuleParam param in _ruleParams)
            {
                probability += param.Probability;
                if (rand <= probability)
                {
                    return(param.Result);
                }
            }

            return(_ruleParams[_ruleParams.Count - 1].Result);
        }
        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++;
        }
        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);
        }
 void DivideLineLength(LSystem.Token token, LSystem system)
 {
     _lineLength /= _lineLengthScaleFactor;
 }
 void MultiplyLineLength(LSystem.Token token, LSystem system)
 {
     _lineLength *= _lineLengthScaleFactor;
 }
 void SaveDrawState(LSystem.Token token, LSystem system)
 {
     _savedPositions.Push(new DrawState(_currentPosition, _currentAngle, _lineLength, _segmentCount));
 }
 void DecreaseAngle(LSystem.Token token, LSystem system)
 {
     _currentAngle -= system.Data.Angle.Value();
 }