コード例 #1
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            VisualisationParameters param = new VisualisationParameters();

            param.angle     = angle.Value;
            param.length    = length.Value * 0.1;
            param.shortage  = shortage.Value * 0.01;
            param.shrinkage = shrinkage.Value * 0.01;
            int index = resultList.SelectedIndex;

            param.radius = System.Math.Max(0.03, index * generationStep.Value * 0.01);

            string toInterpret = (iterations != null && index >= 0 && index < iterations.Count) ? iterations[index] : "";

            mLSystemRenderer.Render(toInterpret, index, param);

            glCanvas.SwapBuffers();
        }
コード例 #2
0
ファイル: LSystemRenderer.cs プロジェクト: maoap1/grcis-1
        public void Render(string aLSInstance, int aGeneration, VisualisationParameters aParameters)
        {
            #region View setup ...

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            mCamera.SetupGLView();
            GL.Light(LightName.Light0, LightParameter.Position, new Vector4(-50.0f, -50.0f, 150.0f, 1.0f));
            GL.Light(LightName.Light1, LightParameter.Diffuse, new Color4(1.0f, 1.0f, 1.0f, 1.0f));

            #endregion

            GL.MatrixMode(MatrixMode.Modelview);

            #region Render ground ...

            GL.Color3(Color.Green);
            GL.Begin(PrimitiveType.Quads);

            GL.Normal3(0.0f, 0.0f, 1.0f);
            GL.Vertex3(-10.0f, -10.0f, 0.0f);
            GL.Vertex3(10.0f, -10.0f, 0.0f);
            GL.Vertex3(10.0f, 10.0f, 0.0f);
            GL.Vertex3(-10.0f, 10.0f, 0.0f);

            GL.End();

            #endregion

            if (aLSInstance == null || aParameters == null) // exit if nothing to Render
            {
                return;
            }

            // Initialize parameter stack
            Stack <VisualisationParameters> parameterStack    = new Stack <VisualisationParameters>();
            VisualisationParameters         currentParameters = aParameters.Clone();

            GL.Color3(Color.Khaki);
            foreach (char v in aLSInstance)
            {
                switch (v)
                {
                case 'F':
                    ForwardStep(currentParameters.length, currentParameters.radius, currentParameters.radius * currentParameters.shrinkage);
                    currentParameters.length *= currentParameters.shortage;
                    currentParameters.radius *= currentParameters.shrinkage;
                    break;

                case '+':
                    GL.Rotate(currentParameters.angle, 0.0f, 1.0f, 0.0f);
                    break;

                case '-':
                    GL.Rotate(-currentParameters.angle, 0.0f, 1.0f, 0.0f);
                    break;

                case '/':
                    GL.Rotate(90.0f, 0.0f, 0.0f, 1.0f);
                    break;

                case '\\':
                    GL.Rotate(-90.0f, 0.0f, 0.0f, 1.0f);
                    break;

                case '[':         // Save current state to stack
                    GL.PushMatrix();
                    parameterStack.Push(currentParameters.Clone());
                    break;

                case ']':         // Restore state from stack
                    GL.PopMatrix();
                    currentParameters = parameterStack.Pop();
                    break;
                }
            }
        }