Beispiel #1
0
        private PVector MatrixToVec(float[][] m)
        {
            PVector v = new PVector();

            v.X = m[0][0];
            v.Y = m[1][0];
            if (m.Length > 2)
            {
                v.Z = m[2][0];
            }

            return(v);
        }
        public void Draw(Graphics graphics)
        {
            float[][] rotationX =
            {
                new[] { 1.0f,                    0.0f,                     0.0f },
                new[] { 0.0f, (float)Math.Cos(_angle), (float)-Math.Sin(_angle) },
                new[] { 0.0f, (float)Math.Sin(_angle), (float)Math.Cos(_angle)  }
            };

            float[][] rotationY =
            {
                new[] { (float)Math.Cos(_angle), 0.0f, (float)-Math.Sin(_angle) },
                new[] {                    0.0f, 1.0f,                     0.0f },
                new[] { (float)Math.Sin(_angle), 0.0f, (float)Math.Cos(_angle)  }
            };

            float[][] rotationZ =
            {
                new[] { (float)Math.Cos(_angle), (float)-Math.Sin(_angle), 0.0f },
                new[] { (float)Math.Sin(_angle), (float)Math.Cos(_angle),  0.0f },
                new[] {                    0.0f,                     0.0f, 1.0f }
            };

            PVector[] projected = new PVector[4];
            int       index     = 0;

            //float distance = 2.0f;
            //float z = 0f;
            foreach (var node in _vertices)
            {
                PVector rotated = _matrix.MatMul(rotationX, node);
                rotated = _matrix.MatMul(rotationY, rotated);
                rotated = _matrix.MatMul(rotationZ, rotated);

                /*z = 1.0f / (distance - rotated.Z);
                 * float z = (node.Z+node.Z+node.Z)/3;
                 * float[][] projection =
                 * {
                 *  new[] {1.0f, 0.0f, 0.0f},
                 *  new[] {0.0f, 1.0f, 0.0f},
                 *  //new[] {z, 0.0f, 0 },
                 *  //new[] {0.0f, z, 0}
                 * };
                 *
                 * PVector projected2D = _matrix.MatMul(projection, rotated);
                 * projected2D.Scale(_size);
                 * _form1.GetX().Text = "X: " + projected2D.X;
                 * _form1.GetY().Text = "Y: " + projected2D.Y;
                 * _form1.GetZ().Text = "Z: " + projected2D.Z;
                 * projected[index] = projected2D;*/
                _form1.GetX().Text = "X: " + rotated.X;
                _form1.GetY().Text = "Y: " + rotated.Y;
                _form1.GetZ().Text = "Z: " + rotated.Z;
                rotated.Scale(_size);
                projected[index] = rotated;
                index++;
            }

            for (int i = 0; i < 4; i++)
            {
                _borders[i].X = projected[i].X;
                _borders[i].Y = projected[i].Y;
            }

            _d[0] = (projected[0].Z + projected[1].Z + projected[2].Z) / 3;
            _d[1] = (projected[0].Z + projected[1].Z + projected[3].Z) / 3;
            _d[2] = (projected[1].Z + projected[2].Z + projected[3].Z) / 3;
            _d[3] = (projected[0].Z + projected[2].Z + projected[3].Z) / 3;

            PVector.AreaSort(_order, _d, 4, 0);
            PVector.StabilizationPoints(_form1.GetMouseX(), _form1.GetMouseY(), _positionX, _positionY, _positionZ,
                                        projected, _numberX, _nY, _nZ, LoN, _numberZ);

            List <PointF[]> area = new List <PointF[]>
            {
                new PointF[] { _borders[0], _borders[1], _borders[2] },
                new PointF[] { _borders[0], _borders[1], _borders[3] },
                new PointF[] { _borders[1], _borders[2], _borders[3] },
                new PointF[] { _borders[0], _borders[2], _borders[3] }
            };

            List <Color> colorsFigure = new List <Color>
            {
                _colorF, _colorF, _colorF, _colorF
            };

            for (int i = 0; i < 4; i++)
            {
                if (_numberZ[_order[i]] >= 0)
                {
                    _positionX = projected[i].X;
                    _positionY = projected[i].Y;
                    _positionZ = projected[i].Z;

                    int color1 = (int)(double)colorsFigure[_order[i]].A;
                    int color2 = (int)(colorsFigure[_order[i]].R * _numberZ[_order[i]]);
                    int color3 = (int)(colorsFigure[_order[i]].G * _numberZ[_order[i]]);
                    int color4 = (int)(colorsFigure[_order[i]].B * _numberZ[_order[i]]);

                    Color glass = Color.FromArgb(color1, color2, color3, color4);
                    graphics.FillPolygon(new SolidBrush(glass), area[_order[i]]);
                    graphics.DrawPolygon(Pens.White, area[_order[i]]);
                    graphics.FillEllipse(Brushes.White, (int)Math.Round(projected[_order[i]].X) - 4,
                                         (int)Math.Round(projected[_order[i]].Y) - 4, 8, 8);
                }
                if (_numberZ[_order[i]] <= 0)
                {
                    _positionX = projected[i].X;
                    _positionY = projected[i].Y;
                    _positionZ = projected[i].Z;

                    int color1 = (int)Math.Abs((double)colorsFigure[_order[i]].A);
                    int color2 = (int)Math.Abs(colorsFigure[_order[i]].R * _numberZ[_order[i]]);
                    int color3 = (int)Math.Abs(colorsFigure[_order[i]].G * _numberZ[_order[i]]);
                    int color4 = (int)Math.Abs(colorsFigure[_order[i]].B * _numberZ[_order[i]]);

                    Color glass = Color.FromArgb(color1, color2, color3, color4);
                    graphics.FillPolygon(new SolidBrush(glass), area[_order[i]]);
                    graphics.DrawPolygon(Pens.White, area[_order[i]]);
                    graphics.FillEllipse(Brushes.White, (int)Math.Round(projected[_order[i]].X) - 4,
                                         (int)Math.Round(projected[_order[i]].Y) - 4, 8, 8);
                }
            }

            /*foreach (var node in projected)
             *  graphics.FillEllipse(Brushes.White, (int) Math.Round(node.X) - 6,
             *      (int) Math.Round(node.Y) - 6, 12, 12);*/

            /*foreach (var edge in _faces)
             *  Connect(edge, projected, graphics);*/

            _angle += 0.01f;
        }
Beispiel #3
0
 public PVector MatMul(float[][] a, PVector b)
 {
     float[][] m = VecToMatrix(b);
     return(MatrixToVec(MatMul(a, m)));
 }