예제 #1
0
        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();
        }