protected override void update()
        {
            RotationMatrixY = new Matrix
                              (
                new double[4][]
            {
                new double[] { Math.Cos(Alpha), 0, Math.Sin(Alpha), 0 },
                new double[] { 0, 1, 0, 0 },
                new double[] { -Math.Sin(Alpha), 0, Math.Cos(Alpha), 0 },
                new double[] { 0, 0, 0, 1 },
            }
                              );

            RotationMatrixX = new Matrix
                              (
                new double[4][]
            {
                new double[] { 1, 0, 0, 0 },
                new double[] { 0, Math.Cos(Beta), -Math.Sin(Beta), 0 },
                new double[] { 0, Math.Sin(Beta), Math.Cos(Beta), 0 },
                new double[] { 0, 0, 0, 1 },
            }
                              );

            ScaleMatrix = new Matrix
                          (
                new double[4][]
            {
                new double[] { 1, 0, 0, 0 },
                new double[] { 0, 1, 0, 0 },
                new double[] { 0, 0, 1, 0 },
                new double[] { 0, 0, 0, 1 },
            }
                          );

            TranslationMatrix = new Matrix
                                (
                new double[4][]
            {
                new double[] { 1, 0, 0, X },
                new double[] { 0, 1, 0, Y },
                new double[] { 0, 0, 1, Z },
                new double[] { 0, 0, 0, 1 },
            }
                                );

            RotationMatrix = MM.Multiply(RotationMatrixX, RotationMatrixY);
            ModelMatrix    = MM.Multiply(RotationMatrix, ScaleMatrix);

            ModelMatrix = MM.Multiply(TranslationMatrix, ModelMatrix);
        }
示例#2
0
        /*******************************************************************/
        /************************* PUBLIC METHODS **************************/
        /*******************************************************************/

        //public abstract void Render(Matrix VP);

        public void Render(Matrix VP)
        {
            update();

            Matrix MVP = MM.Multiply(VP, ModelMatrix);

            Matrix[] transformedPoints = new Matrix[VERTEX_COUNT];

            // Transform the point
            for (int i = 0; i < VERTEX_COUNT; i++)
            {
                transformedPoints[i] = MM.Multiply(MVP, VerticesAffine[i]);

                for (int j = 0; j < 4; j++)
                {
                    transformedPoints[i].MatValues[j][0] /= transformedPoints[i].MatValues[3][0];
                }
            }

            draw(transformedPoints);
        }
        /*******************************************************************/
        /************************* PUBLIC METHODS **************************/
        /*******************************************************************/

        public void Update()
        {
            d  = (width / 2) * (1 / Math.Tan(FOV / 2));
            cx = width / 2;
            cy = height / 2;

            RotationMatrixX = new Matrix
                              (
                new double[4][]
            {
                new double[] { 1, 0, 0, 0 },
                new double[] { 0, Math.Cos(Beta), -Math.Sin(Beta), 0 },
                new double[] { 0, Math.Sin(Beta), Math.Cos(Beta), 0 },
                new double[] { 0, 0, 0, 1 },
            }
                              );

            RotationMatrixY = new Matrix
                              (
                new double[4][]
            {
                new double[] { Math.Cos(Alpha), 0, Math.Sin(Alpha), 0 },
                new double[] { 0, 1, 0, 0 },
                new double[] { -Math.Sin(Alpha), 0, Math.Cos(Alpha), 0 },
                new double[] { 0, 0, 0, 1 },
            }
                              );

            RotationMatrixZ = new Matrix
                              (
                new double[4][]
            {
                new double[] { Math.Cos(Theta), -Math.Sin(Theta), 0, 0 },
                new double[] { Math.Sin(Theta), Math.Cos(Theta), 0, 0 },
                new double[] { 0, 0, 1, 0 },
                new double[] { 0, 0, 0, 1 },
            }
                              );


            TranslationMatrix = new Matrix
                                (
                new double[4][]
            {
                new double[] { 1, 0, 0, X },
                new double[] { 0, 1, 0, Y },
                new double[] { 0, 0, 1, Z },
                new double[] { 0, 0, 0, 1 },
            }
                                );

            ProjectionMatrix = new Matrix
                               (
                new double[4][]
            {
                new double[] { d, 0, cx, 0 },
                new double[] { 0, -d, cy, 0 },
                new double[] { 0, 0, 0, 1 },
                new double[] { 0, 0, 1, 0 },
            }
                               );

            // TransformMatrix = Translate * Rotation
            // Rotation = Rx * Ry * Rz
            RotationMatrix = MM.Multiply(RotationMatrixY, RotationMatrixZ);
            RotationMatrix = MM.Multiply(RotationMatrixX, RotationMatrix);

            ViewMatrix = MM.Multiply(RotationMatrix, TranslationMatrix);

            // The goal of this update method is to compute the View Projection part of MVP
            VP = MM.Multiply(ProjectionMatrix, ViewMatrix);
        }