private void CreateElement() { var element = new DiffuseReflectionPointLightRenderer(factories[currentModelIndex].Create(this.radius)); element.Initialize(); this.newRenderer = element; }
//Camera modelRotationCamera; //SatelliteRotator modelRotator; //private float rotateAngle; public FormDiffuseReflectionPointLight() { 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 DiffuseReflectionPointLightRenderer(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; }
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 FormDiffuseReflectionPointLightController(this.renderer); this.frmController.Show(); this.frmDisplay.Close(); this.frmDisplay = new FormDiffuseReflectionPointLightDisplay(this.renderer); this.frmDisplay.Show(); this.newRenderer = null; } this.renderer.Render(arg); }
public FormDiffuseReflectionPointLightController(DiffuseReflectionPointLightRenderer 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(); } }
public FormDiffuseReflectionPointLightDisplay(DiffuseReflectionPointLightRenderer renderer) { InitializeComponent(); this.renderer = renderer; }