예제 #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();
        }
예제 #2
0
        private void RenderControl_Render_GLSL(object sender, GlControlEventArgs e)
        {
            Control control = (Control)sender;

            PerspectiveProjectionMatrix projectionMatrix = new PerspectiveProjectionMatrix(45.0f, (float)control.Width / (float)control.Height, 0.1f, 100.0f);
            ModelMatrix viewMatrix  = new ModelMatrix();
            ModelMatrix modelMatrix = new ModelMatrix();

            modelMatrix.Translate(new Vertex3f(modelPosition.X, modelPosition.Y, modelPosition.Z));
            modelMatrix.Scale(new Vertex3f(0.2f, 0.2f, 0.2f));

            Gl.Viewport(0, 0, control.Width, control.Height);
            Gl.ClearColor(0.05f, 0.05f, 0.05f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            modelShader.Use();
            modelMatrix.RotateX(modelAngle.X);
            modelMatrix.RotateY(modelAngle.Y);
            modelMatrix.RotateZ(modelAngle.Z);
            //viewMatrix.Translate(new Vertex3f(-2.0f * (float)Math.Sin(modelAngle.Y * PI_OVER_180), 0.0f, -2.0f*(float)Math.Cos(modelAngle.Y*PI_OVER_180)));
            Gl.UniformMatrix4(modelShader.uLocation_Projection, 1, false, projectionMatrix.ToArray());
            Gl.UniformMatrix4(modelShader.uLocation_View, 1, false, viewMatrix.ToArray());
            Gl.UniformMatrix4(modelShader.uLocation_Model, 1, false, modelMatrix.ToArray());

            modelNanosuit.Draw(modelShader);
        }
예제 #3
0
        public void MatrixMul2()
        {
            ProjectionMatrix proj  = new OrthoProjectionMatrix(-1.0f, 0.5f, 0.0f, 1.0f, 0.1f, 3.0f);
            ModelMatrix      model = new ModelMatrix();

            model.Translate(2.0f, -4.0f, 1.125f);
            model.RotateX(30.0f);

            Matrix r1 = proj * model;

            Matrix m = new Matrix(proj.ToArray(), 4, 4), n = new Matrix(model.ToArray(), 4, 4);

            Matrix r2 = m * n;
        }
예제 #4
0
        static Matrix4x4Test()
        {
            Random random = new Random();

            _MatArray = new Matrix4x4[MulArraySize];
            for (int i = 0; i < _MatArray.Length; i++)
            {
                ModelMatrix modelMatrix = new ModelMatrix();
                modelMatrix.RotateX(random.NextDouble() * 360.0);
                modelMatrix.RotateY(random.NextDouble() * 360.0);
                modelMatrix.RotateZ(random.NextDouble() * 360.0);
                modelMatrix.Translate(random.NextDouble(), random.NextDouble(), random.NextDouble());

                _MatArray[i] = modelMatrix;
            }
        }