示例#1
0
        public Bitmap TransformCube(CustomCube cube, Matrix <double> matrix, Bitmap bitmap)
        {
            List <CustomTriangle> newTriangles = new List <CustomTriangle>();

            foreach (CustomTriangle triangle in cube.triangles)
            {
                List <Vector <double> > points = new List <Vector <double> >();
                foreach (CustomVertex vertex in triangle.vertices)
                {
                    Vector <double> temp = Vector <double> .Build.DenseOfArray(new double[] { vertex.x, vertex.y, vertex.z, 1 });

                    Vector <double> point = temp * matrix;
                    points.Add(point);
                }

                Vector <double> normal = CrossProduct(points[1] - points[0], points[2] - points[0]);

                Vector <double> normalTemp = Vector <double> .Build.DenseOfArray(
                    new double[] { Math.Pow(normal[0], 3), Math.Pow(normal[1], 3), Math.Pow(normal[2], 3) });

                normal = normal / Math.Sqrt(normalTemp.Sum());

                foreach (Vector <double> point in points)
                {
                    Vector <double> temp = (point * matrix / point[2] + Shift) / 2;
                }

                CustomTriangle newTriangle = new CustomTriangle(
                    new CustomVertex(points[0][0], points[0][1], points[0][2]),
                    new CustomVertex(points[1][0], points[1][1], points[1][2]),
                    new CustomVertex(points[2][0], points[2][1], points[2][2])
                    );
                newTriangles.Add(newTriangle);
            }

            List <CustomVertex> newVertices = new List <CustomVertex>();

            foreach (CustomTriangle triangle in newTriangles)
            {
                newVertices.AddRange(triangle.vertices);
            }

            cube.triangles = newTriangles;
            cube.vertices  = newVertices;
            bitmap         = cube.Draw(bitmap);

            return(bitmap);
        }
示例#2
0
        private void PrepareScene()
        {
            Image imageControl = (Image)this.FindName("SceneImage");

            imageControl.Width  = sceneWidth;
            imageControl.Height = sceneHeight;

            Bitmap bitmap = new Bitmap(sceneWidth, sceneHeight);

            using (Graphics graph = Graphics.FromImage(bitmap))
            {
                Rectangle ImageSize = new Rectangle(0, 0, sceneWidth, sceneHeight);
                graph.FillRectangle(Brushes.Black, ImageSize);
            }

            cube1 = new CustomCube(700, 300, 50, 100);
            cube2 = new CustomCube(550, 300, 10, 50);

            bitmap = cube1.Draw(bitmap);
            bitmap = cube2.Draw(bitmap);

            Scene = ImageConverters.Bitmap2BitmapImage(bitmap);

            imageControl.Source = Scene;

            double tanValue = 1 / Math.Tan(theta / 2);

            //T[3, 1] = cube1.GetCenterY();

            //Zoom[3, 1] = cube1.GetCenterY();
            Zoom[3, 2]   = 5;
            ZoomProperty = 30;

            M = DenseMatrix.OfArray(new double[, ] {
                { tanValue, 0, 0, 0 },
                { 0, tanValue, 0, 0 },
                { 0, 0, -far / (far - near), -1 },
                { 0, 0, (-far * near) / (far - near), 0 }
            });
        }