Esempio n. 1
0
 public object RightReplacementMultiBranches(
     A a,
     LSystems.StartBranchModule open0, LSystems.EndBranchModule close0,
     LSystems.StartBranchModule open1, B b, LSystems.EndBranchModule close1,
     D d)
 {
     return new OK();
 }
Esempio n. 2
0
        public void Draw(LSystems.Turtle.F f)
        {
            this.Turtle.Thickness = 33;
            this.Turtle.SetColor(1, color, 0);
            this.Turtle.Forward(100, true);

            color += delta;
            if (color > 1)
            {
                color = 1;
                delta = -delta;
            }
            else if (color < 0)
            {
                color = 0;
                delta = -delta;
            }
        }
        public void SetSystem(LSystems.System system)
        {
            this.system = system;

            // Rebuild system.
            Clear(ref this.vertexesPtr);
            Clear(ref this.colorsPtr);
            Clear(ref this.normalsPtr);
            Clear(ref this.triVertexesPtr);
            Clear(ref this.triColorsPtr);
            Clear(ref this.triNormalsPtr);

            this.numQuadVertexes = 0;
            this.numTriVertexes = 0;

            this.vertexes.Clear();
            this.normals.Clear();
            this.colors.Clear();
            this.triVertexes.Clear();
            this.triNormals.Clear();
            this.triColors.Clear();

            this.helperLines.Clear();

            ResetState();

            this.Push();

            if (this.system != null)
            {
                //Debug.WriteLine("---------------------");
                //foreach (object obj in (IEnumerable)this.system.String)
                //{
                //    Debug.WriteLine(string.Format("{0}", obj.GetType()));
                //}

                if (this.system.Definition is LSystems.Turtle.SystemDefinition)
                {
                    ((LSystems.Turtle.SystemDefinition)this.system.Definition).Turtle = this;
                }

                var interpreter = new LSystems.Turtle.Interpreter();
                interpreter.RegisterExternalFunctions(this.system.Definition);
                interpreter.Interpret(this, this.system.String as IEnumerable);
                if (this.system.Definition is LSystems.Turtle.SystemDefinition)
                {
                    ((LSystems.Turtle.SystemDefinition)this.system.Definition).Turtle = null;
                }
            }

            this.Pop();

            // Generate normals.
            for (int i = 0; i < vertexes.Count; i += 12)
            {
                OpenTK.Vector3 normal = CalcNormal(
                    new OpenTK.Vector3(vertexes[i], vertexes[i + 1], vertexes[i + 2]),
                    new OpenTK.Vector3(vertexes[i + 3], vertexes[i + 4], vertexes[i + 5]),
                    new OpenTK.Vector3(vertexes[i + 6], vertexes[i + 7], vertexes[i + 8]));

                for (int j = 0; j < 4; ++j) { Add(normals, normal); }
            }

            for (int i = 0; i < triVertexes.Count; i += 9)
            {
                OpenTK.Vector3 normal = CalcNormal(
                    new OpenTK.Vector3(triVertexes[i], triVertexes[i + 1], triVertexes[i + 2]),
                    new OpenTK.Vector3(triVertexes[i + 3], triVertexes[i + 4], triVertexes[i + 5]),
                    new OpenTK.Vector3(triVertexes[i + 6], triVertexes[i + 7], triVertexes[i + 8]));

                for (int j = 0; j < 3; ++j) { Add(triNormals, normal); }
            }

            // Copy arrays in non-managed memory.
            Create(this.vertexes, ref this.vertexesPtr);
            Create(this.colors, ref this.colorsPtr);
            Create(this.normals, ref this.normalsPtr);

            this.numQuadVertexes = this.vertexes.Count / 3;

            Create(this.triVertexes, ref this.triVertexesPtr);
            Create(this.triColors, ref this.triColorsPtr);
            Create(this.triNormals, ref this.triNormalsPtr);

            this.numTriVertexes = this.triVertexes.Count / 3;

            this.toolStripLabelStatistics.Text =
                string.Format("{0} quads, {1} triangles.", this.numQuadVertexes / 4, this.numTriVertexes / 3);

            // Force redraw.
            glControl1.Invalidate();
        }
Esempio n. 4
0
 public object RightReplacementSkipRestOfBranch(
     A a, LSystems.StartBranchModule open, B b, LSystems.EndBranchModule close, C c)
 {
     return new OK();
 }
Esempio n. 5
0
 public object Rule(LSystems.Turtle.f f)
 {
     return parser.Produce("f+f-f-f+f");
 }
Esempio n. 6
0
 public object InternodeGrow1(Internode i, LSystems.StartBranchModule sb, Internode i2, LSystems.EndBranchModule eb, Internode i3)
 {
     return new Internode(i.Length * LengthGrowRate, i2.Area + i3.Area);
 }
Esempio n. 7
0
 public object Produce(LSystems.Turtle.F f)
 {
     return parser.Produce("S/////F");
 }