private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; GraphicsSurface framebuffer = e.Framebuffer; if (_AnimationBegin == DateTime.MinValue) { _AnimationBegin = DateTime.UtcNow; } PerspectiveProjectionMatrix matrixProjection = new PerspectiveProjectionMatrix(); Matrix4x4 matrixView; // Set projection matrixProjection.SetPerspective(60.0f, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, 1000.0f); // Set view ModelMatrix matrixViewModel = new ModelMatrix(); matrixViewModel.RotateX(_ViewElevation); matrixViewModel.RotateY(_ViewAzimuth); matrixViewModel.Translate(0.0f, 0.0f, _ViewDistance); matrixView = matrixViewModel.GetInverseMatrix(); _NewtonProgram.Bind(ctx); _NewtonProgram.SetUniform(ctx, "hal_ModelViewProjection", matrixProjection * matrixView); _NewtonProgram.SetUniform(ctx, "hal_FrameTimeInterval", (float)(DateTime.UtcNow - _AnimationBegin).TotalSeconds); _NewtonVertexArray.Draw(ctx, _NewtonProgram); SwapNewtonVertexArrays(); // Issue another rendering SampleGraphicsControl.Invalidate(); }
private void SampleGraphicsControl_MouseMove(object sender, MouseEventArgs e) { if ((e.Button & MouseButtons.Left) != 0) { Point delta = e.Location - new Size(_MouseCursor); float xDelta = (float)delta.X / (float)ClientSize.Width; float yDelta = (float)delta.Y / (float)ClientSize.Height; _ViewAzimuth -= xDelta * 180.0f; _ViewElevation -= yDelta * 90.0f; _MouseCursor = e.Location; SampleGraphicsControl.Invalidate(); } }
private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e) { GraphicsContext ctx = e.Context; GraphicsSurface framebuffer = e.Framebuffer; // Update position KeyTimer_Tick(); // Define view _GeometryClipmapScene.CurrentView.LocalModel.SetIdentity(); _GeometryClipmapScene.CurrentView.LocalModel.Translate(_ViewPosition); _GeometryClipmapScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _GeometryClipmapScene.CurrentView.LocalModel.RotateX(_ViewElevation); // Draw geometry clipmap _GeometryClipmapScene.Draw(ctx); SampleGraphicsControl.Invalidate(); }