Exemple #1
0
        //Camera modelRotationCamera;
        //SatelliteRotator modelRotator;
        //private float rotateAngle;

        public FormSimpleRenderer()
        {
            InitializeComponent();

            this.camera          = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
            this.camera.Position = new GLM.vec3(5, 5, 5);

            this.cameraRotator = new SatelliteRotator(this.camera);

            //this.modelRotationCamera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
            //this.modelRotator = new SatelliteRotator(this.modelRotationCamera);
            this.modelRotator = new ArcBallRotator(this.camera);

            {
                const string           strGround = "Ground";
                IConvert2BufferPointer model     = new Ground();
                CodeShader[]           shaders   = new CodeShader[2];
                shaders[0] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.VertexShader);
                shaders[1] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.FragmentShader);
                PropertyNameMap propertyNameMap = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadPropertyNameMap(strGround);
                UniformNameMap  uniformNameMap  = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadUniformNameMap(strGround);
                this.groundRenderer = new ModernRenderer(model, shaders, propertyNameMap, uniformNameMap);
                this.groundRenderer.Initialize();
            }

            Padding        uiPadding = new System.Windows.Forms.Padding(10, 10, 10, 10);
            Size           uiSize    = new System.Drawing.Size(50, 50);
            IUILayoutParam uiParam   = new IUILayoutParam(AnchorStyles.Left | AnchorStyles.Bottom, uiPadding, uiSize);

            uiAxis = new SimpleUIAxis(uiParam);
            uiAxis.Initialize();

            {
                IModel model = (new TeapotFactory()).Create(1.0f);
                this.renderer = new SimpleRenderer(model);
                this.renderer.Initialize();//不在此显式初始化也可以。
            }

            this.glCanvas1.MouseWheel += glCanvas1_MouseWheel;
            this.glCanvas1.KeyPress   += glCanvas1_KeyPress;
            this.glCanvas1.MouseDown  += glCanvas1_MouseDown;
            this.glCanvas1.MouseMove  += glCanvas1_MouseMove;
            this.glCanvas1.MouseUp    += glCanvas1_MouseUp;
            this.glCanvas1.OpenGLDraw += glCanvas1_OpenGLDraw;
            this.glCanvas1.Resize     += glCanvas1_Resize;
        }
 private void Form01ModernRenderer_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         camera.Position = new vec3(0, 0, 5);
         var rotator = new SatelliteRotator(camera);
         this.camera  = camera;
         this.rotator = rotator;
     }
     {
         IBufferable  bufferable = new BigDipperAdapter(new BigDipper());
         ShaderCode[] shaders    = new ShaderCode[2];
         shaders[0] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.vert"), ShaderType.VertexShader);
         shaders[1] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("in_Position", "position");
         propertyNameMap.Add("in_Color", "color");
         var renderer = new ModernRenderer(bufferable, shaders, propertyNameMap, "position");
         renderer.Initialize();
         GLSwitch lineWidthSwitch = new LineWidthSwitch(10.0f);
         renderer.SwitchList.Add(lineWidthSwitch);
         GLSwitch pointSizeSwitch = new PointSizeSwitch(10.0f);
         renderer.SwitchList.Add(pointSizeSwitch);
         this.renderer = renderer;
     }
     {
         var frmBulletinBoard = new FormBulletinBoard();
         frmBulletinBoard.Dump = true;
         frmBulletinBoard.Show();
         this.bulletinBoard = frmBulletinBoard;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.rendererPropertyGrid = frmPropertyGrid;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.camera);
         frmPropertyGrid.Show();
         this.cameraPropertyGrid = frmPropertyGrid;
     }
 }
        private void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            GL.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            ModernRenderer renderer = this.renderer;

            if (renderer != null)
            {
                if (cameraUpdated)
                {
                    mat4 projectionMatrix = camera.GetProjectionMat4();
                    mat4 viewMatrix       = camera.GetViewMat4();
                    mat4 modelMatrix      = mat4.identity();
                    renderer.SetUniformValue("projectionMatrix", projectionMatrix);
                    renderer.SetUniformValue("viewMatrix", viewMatrix);
                    renderer.SetUniformValue("modelMatrix", modelMatrix);
                    cameraUpdated = false;
                }
                renderer.Render(new RenderEventArgs(RenderModes.Render, this.camera));
            }
        }
Exemple #4
0
        //Camera modelRotationCamera;
        //SatelliteRotator modelRotator;
        //private float rotateAngle;

        public FormNewNormalLine()
        {
            InitializeComponent();

            this.camera          = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
            this.camera.Position = new GLM.vec3(50, 5, 5);

            this.cameraRotator = new SatelliteRotator(this.camera);

            //this.modelRotationCamera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
            //this.modelRotator = new SatelliteRotator(this.modelRotationCamera);
            this.modelRotator = new ArcBallRotator(this.camera);

            {
                const string           strGround = "Ground";
                IConvert2BufferPointer model     = new Ground();
                CodeShader[]           shaders   = new CodeShader[2];
                shaders[0] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.VertexShader);
                shaders[1] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.FragmentShader);
                PropertyNameMap propertyNameMap = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadPropertyNameMap(strGround);
                UniformNameMap  uniformNameMap  = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadUniformNameMap(strGround);
                this.groundRenderer = new ModernRenderer(model, shaders, propertyNameMap, uniformNameMap);
                this.groundRenderer.Initialize();
            }

            Padding        uiPadding = new System.Windows.Forms.Padding(10, 10, 10, 10);
            Size           uiSize    = new System.Drawing.Size(50, 50);
            IUILayoutParam uiParam   = new IUILayoutParam(AnchorStyles.Left | AnchorStyles.Bottom, uiPadding, uiSize);

            uiAxis = new SimpleUIAxis(uiParam);
            uiAxis.Initialize();

            //IModel model = (new TeapotFactory()).Create(1.0f);
            {
                IConvert2BufferPointer model       = new NewNormalLineDemoModel();
                CodeShader[]           codeShaders = new CodeShader[3];
                codeShaders[0] = new CodeShader(ShaderHelper.Load("NewNormalLine.vert"), CodeShader.GLSLShaderType.VertexShader);
                codeShaders[1] = new CodeShader(ShaderHelper.Load("NewNormalLine.geom"), CodeShader.GLSLShaderType.GeometryShader);
                codeShaders[2] = new CodeShader(ShaderHelper.Load("NewNormalLine.frag"), CodeShader.GLSLShaderType.FragmentShader);
                var propertyNameMap = new PropertyNameMap();
                propertyNameMap.Add("in_Position", NewNormalLineDemoModel.strPosition);
                propertyNameMap.Add("in_Normal", NewNormalLineDemoModel.strNormal);
                var uniformNameMap = new UniformNameMap();
                uniformNameMap.Add("model matrix", "modelMatrix");
                uniformNameMap.Add("view matrix", "viewMatrix");
                uniformNameMap.Add("projection matrix", "projectionMatrix");
                uniformNameMap.Add("show model", "showModel");
                uniformNameMap.Add("show normal", "showNormal");
                uniformNameMap.Add("normal length", "normalLength");
                this.renderer = new ModernRenderer(model, codeShaders, propertyNameMap, uniformNameMap);
                this.renderer.Initialize();//不在此显式初始化也可以。
                this.renderer.SetUniformValue("show model", 1.0f);
                this.renderer.SetUniformValue("show normal", 1.0f);
                this.renderer.SetUniformValue("normal length", 1.0f);
            }

            //this.demoLifebar = new DemoLifeBar(0.2f, 0.02f, 4);
            //this.demolifebarRenderer = new NormalLineRenderer(this.demoLifebar);
            //this.demolifebarRenderer.Initialize();

            this.lifebarRenderer = new LifeBarRenderer(new LifeBar(2f, 0.2f, 4f));
            this.lifebarRenderer.Initialize();

            //StringModel stringModel = DummyStringModelFactory.GetModel("teapot");
            this.stringRenderer = new StringRenderer("teapot".GetDummyModel());
            this.stringRenderer.Initialize();

            uiParam    = new IUILayoutParam(AnchorStyles.Right | AnchorStyles.Bottom, new Padding(10, 10, 120, 10), new Size(50, 50));
            this.label = new DummyLabel(uiParam, "Hello Label!");
            this.label.Initialize();

            this.glCanvas1.MouseWheel += glCanvas1_MouseWheel;
            this.glCanvas1.KeyPress   += glCanvas1_KeyPress;
            this.glCanvas1.MouseDown  += glCanvas1_MouseDown;
            this.glCanvas1.MouseMove  += glCanvas1_MouseMove;
            this.glCanvas1.MouseUp    += glCanvas1_MouseUp;
            this.glCanvas1.OpenGLDraw += glCanvas1_OpenGLDraw;
            this.glCanvas1.Resize     += glCanvas1_Resize;

            Application.Idle += Application_Idle;
        }
Exemple #5
0
        private void LoadModel()
        {
            string datafilePrefix = @"data\floordata";
            int    noneZeroItemCount = 0;
            bool   minSet = false, maxSet = false;
            float  min = 0, max = 0;

            char[] separator = new char[] { ' ', '\t', '\r', '\n' };
            for (int i = 0; i < 20; i++)
            {
                string filename = datafilePrefix + (i + 1).ToString() + ".txt";
                //using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                using (var sr = new StreamReader(filename))
                {
                    while (!sr.EndOfStream)
                    {
                        var line  = sr.ReadLine();
                        var parts = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var part in parts)
                        {
                            float value;
                            if (float.TryParse(part, out value))
                            {
                                if (value != 0.0f)
                                {
                                    noneZeroItemCount++;
                                }
                                if (!minSet)
                                {
                                    min = value; minSet = true;
                                }
                                if (!maxSet)
                                {
                                    max = value; maxSet = true;
                                }

                                if (value < min)
                                {
                                    min = value;
                                }
                                if (max < value)
                                {
                                    max = value;
                                }
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }
                    }
                }
            }

            ColorBar    colorBar = ColorBar.GetDefault();
            int         xSize = 921, ySize = 921, zSize = 20;
            int         vertexIndex  = 0;
            List <vec3> positionList = new List <vec3>();
            List <vec3> colorList    = new List <vec3>();

            for (int i = 0; i < 20; i++)
            {
                string filename = datafilePrefix + (i + 1).ToString() + ".txt";
                using (var sr = new StreamReader(filename))
                {
                    while (!sr.EndOfStream)
                    {
                        var line  = sr.ReadLine();
                        var parts = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var part in parts)
                        {
                            float value;
                            if (float.TryParse(part, out value))
                            {
                                if (value != 0.0f)
                                {
                                    vec3 color = colorBar.GetColor(min, max, value);
                                    //vec3 color = new vec3(1, 1, 1);
                                    colorList.Add(color);

                                    float x = vertexIndex % xSize;
                                    float y = (vertexIndex % (xSize * ySize)) / ySize;
                                    float z = vertexIndex / ySize / xSize;

                                    if (vertexIndex !=
                                        x + y * xSize + z * ySize * xSize)
                                    {
                                        Console.WriteLine("asdf");
                                    }
                                    vec3 position = new vec3(x - xSize / 2, y - ySize / 2, z - zSize / 2);
                                    position = position / 10;
                                    positionList.Add(position);
                                }

                                vertexIndex++;
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }
                    }
                }
            }

            RadarModel model = new RadarModel(positionList, colorList);

            CodeShader[] codeShaders = new CodeShader[2];
            codeShaders[0] = new CodeShader(File.ReadAllText("Radar.vert"), CodeShader.GLSLShaderType.VertexShader);
            codeShaders[1] = new CodeShader(File.ReadAllText("Radar.frag"), CodeShader.GLSLShaderType.FragmentShader);
            PropertyNameMap propertyNameMap = PropertyNameMap.Parse(XElement.Load("Radar.PropertyNameMap.xml"));
            UniformNameMap  uniformNameMap  = UniformNameMap.Parse(XElement.Load("Radar.UniformNameMap.xml"));

            this.modelRenderer = new ModernRenderer(model, codeShaders, propertyNameMap, uniformNameMap);
            this.modelRenderer.SwitchList.Add(new PointSpriteSwitch());
            this.modelRenderer.Initialize();//不在此显式初始化也可以。
            this.modelRenderer.SetUniformValue("canvasWidth", (float)this.glCanvas1.Width);
            this.modelRenderer.SetUniformValue("canvasHeight", (float)this.glCanvas1.Height);
            this.modelRenderer.SetUniformValue("brightness", 1.0f);
            Texture2D texture = new Texture2D();

            texture.Initialize(new Bitmap("cloud30.png"));
            this.modelRenderer.SetUniformValue("cloudTexture", new samplerValue(texture.Name, ActiveTextureIndex.Texture0));
        }