Example #1
0
        private void CreateElement()
        {
            var element = new NormalLineRenderer(factories[currentModelIndex].Create(this.radius));

            element.Initialize();
            this.newRenderer = element;
        }
Example #2
0
        void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            if (this.newRenderer != null)
            {
                this.renderer    = newRenderer;
                this.newRenderer = null;
            }

            var  arg = new RenderEventArgs(RenderModes.Render, this.camera);
            mat4 projectionMatrix = camera.GetProjectionMat4();
            mat4 viewMatrix       = camera.GetViewMat4();
            //mat4 modelMatrix = glm.rotate(rotateAngle, new vec3(0, 1, 0)); //modelRotationCamera.GetViewMat4(); //mat4.identity();
            //rotateAngle += 0.03f;
            //mat4 modelMatrix = this.modelRotator.GetModelRotation();//glm.rotate(rotateAngle, new vec3(0, 1, 0)); //modelRotationCamera.GetViewMat4(); //mat4.identity();
            mat4 modelMatrix = this.modelRotator.GetRotationMatrix();

            this.renderer.projectionMatrix = projectionMatrix;
            this.renderer.viewMatrix       = glm.translate(viewMatrix, translate);
            this.renderer.modelMatrix      = modelMatrix;

            //this.demolifebarRenderer.projectionMatrix = projectionMatrix;
            //this.demolifebarRenderer.viewMatrix = AlwaysFaceCamera(glm.translate(viewMatrix, translate));
            //this.demolifebarRenderer.modelMatrix = AlwaysSameSize(
            //    (this.camera.Target - this.camera.Position).Magnitude(), this.demoLifebar.Height);

            this.lifebarRenderer.projectionMatrix = projectionMatrix;
            this.lifebarRenderer.viewMatrix       =
                alwaysFaceCamera ? AlwaysFaceCamera(glm.translate(viewMatrix, translate)) : glm.translate(viewMatrix, translate);
            this.lifebarRenderer.modelMatrix =
                alwaysSameSize ?
                AlwaysSameSize(
                    (this.camera.Target - this.camera.Position).Magnitude() / 10,
                    this.lifebarRenderer.model.Height)
                    : glm.translate(mat4.identity(), new vec3(0, this.lifebarRenderer.model.Height, 0));

            this.stringRenderer.mvp = //projectionMatrix * viewMatrix * modelMatrix;
                                      projectionMatrix
                                      * (alwaysFaceCamera ? AlwaysFaceCamera(glm.translate(viewMatrix, translate)) : glm.translate(viewMatrix, translate))
                                      * (alwaysSameSize ?
                                         AlwaysSameSize(
                                             (this.camera.Target - this.camera.Position).Magnitude() / 10,
                                             this.lifebarRenderer.model.Height + 1)
                    : glm.translate(mat4.identity(), new vec3(0, this.lifebarRenderer.model.Height, 0)));

            this.groundRenderer.projectionMatrix = projectionMatrix;
            this.groundRenderer.viewMatrix       = viewMatrix;
            this.groundRenderer.modelMatrix      = mat4.identity();

            GL.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            this.uiAxis.Render(arg);
            this.label.Render(arg);

            this.renderer.Render(arg);
            //this.demolifebarRenderer.Render(arg);
            this.lifebarRenderer.Render(arg);
            this.stringRenderer.Render(arg);
            this.groundRenderer.Render(arg);
        }
Example #3
0
        //Camera modelRotationCamera;
        //SatelliteRotator modelRotator;
        //private float rotateAngle;

        public FormNormalLine()
        {
            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);

            //this.groundRenderer = new GroundRenderer(new Ground(100, 100, 0.1f, 0.1f));
            this.groundRenderer = new GroundRenderer(new Ground(100, 100, 1f, 1f));
            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 NormalLineRenderer(model);
            this.renderer.Initialize();//不在此显式初始化也可以。

            //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".GetModel());
            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;

            //var displayer = new FormNormalLineDisplay(this.demolifebarRenderer);
            //displayer.Show();
            var displayer = new FormNormalLineDisplay(this.renderer);

            displayer.Show();
            var cameraController = new FormCameraController(this.camera);

            cameraController.Show();

            Application.Idle += Application_Idle;
        }
        public FormNormalLineDisplay(NormalLineRenderer renderer)
        {
            InitializeComponent();

            this.renderer = renderer;
        }
Example #5
0
        //Camera modelRotationCamera;
        //SatelliteRotator modelRotator;
        //private float rotateAngle;

        public FormNormalLine()
        {
            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);
                this.renderer = new NormalLineRenderer(model);
                this.renderer.Initialize();//不在此显式初始化也可以。
            }

            //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;

            //var displayer = new FormNormalLineDisplay(this.demolifebarRenderer);
            //displayer.Show();
            var displayer = new FormNormalLineDisplay(this.renderer);

            displayer.Show();
            var cameraController = new FormCameraController(this.camera);

            cameraController.Show();

            Application.Idle += Application_Idle;
        }