Exemplo n.º 1
0
        private void CreateElement()
        {
            var element = new PhongPointLightRenderer(factories[currentModelIndex].Create(this.radius));

            element.Initialize();
            this.newRenderer = element;
        }
Exemplo n.º 2
0
        void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            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       = viewMatrix;
            this.renderer.modelMatrix      = modelMatrix;

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

            this.uiAxis.Render(arg);
            if (this.newRenderer != null)
            {
                this.renderer = newRenderer;
                this.frmController.Close();
                this.frmController = new FormPhongPointLightController(this.renderer);
                this.frmController.Show();
                this.frmDisplay.Close();
                this.frmDisplay = new FormPhongPointLightDisplay(this.renderer);
                this.frmDisplay.Show();
                this.newRenderer = null;
            }
            this.renderer.Render(arg);
        }
Exemplo n.º 3
0
        //Camera modelRotationCamera;
        //SatelliteRotator modelRotator;
        //private float rotateAngle;

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

            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 PhongPointLightRenderer(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;
        }
        public FormPhongPointLightController(PhongPointLightRenderer renderer)
        {
            InitializeComponent();

            this.renderer = renderer;
            {
                this.trackKd.Value = (int)renderer.Kd;
                this.lblKd.Text    = renderer.Kd.ToShortString();
            }
            {
                vec3  c     = 255 * renderer.lightColor;
                Color color = Color.FromArgb((int)c.x, (int)c.y, (int)c.z);
                this.lblLightColorDisplay.BackColor = color;
                this.lblLightColor.Text             = string.Format("R:{0} G:{1} B:{2}", color.R, color.G, color.B);
            }
            {
                vec3  c     = 255 * renderer.globalAmbientColor;
                Color color = Color.FromArgb((int)c.x, (int)c.y, (int)c.z);
                this.lblGlobalAmbientDisplay.BackColor = color;
                this.lblGlobalAmbient.Text             = string.Format("R:{0} G:{1} B:{2}", color.R, color.G, color.B);
            }
            {
                float value = renderer.lightPosition.x;
                this.trackLightPositionX.Value = (int)value;
                this.lblLightPositionX.Text    = value.ToShortString();
            }
            {
                float value = renderer.lightPosition.y;
                this.trackLightPositionY.Value = (int)value;
                this.lblLightPositionY.Text    = value.ToShortString();
            }
            {
                float value = renderer.lightPosition.z;
                this.trackLightPositionZ.Value = (int)value;
                this.lblLightPositionZ.Text    = value.ToShortString();
            }
            {
                float value = renderer.Ks;
                this.trackKs.Value = (int)value;
                this.lblKs.Text    = value.ToShortString();
            }
            {
                float value = renderer.shininess;
                this.trackShininess.Value = (int)(value * 100);
                this.lblShininess.Text    = value.ToShortString();
            }
        }
Exemplo n.º 5
0
        public FormPhongPointLightDisplay(PhongPointLightRenderer renderer)
        {
            InitializeComponent();

            this.renderer = renderer;
        }