示例#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
    void Spawn()
    {
        if (nextCubeID >= maxCubes)                                      //if maxcubes(set in inspector to be 10) have been spawned
        {
            CustomCube[] cubes = GetComponentsInChildren <CustomCube>(); //get an array of all the cubes
            foreach (CustomCube cube in cubes)                           //and for each cube found...
            {
                if (cube.cubeID == nextCubeID - maxCubes)                //if the cube was spawned "maxCubes" ago...
                {
                    Destroy(cube.gameObject);                            //destroy it
                    break;                                               //stop checking more cubes (by exiting the loop
                }
            }
        }
        CustomCube newCube = Instantiate(customCube, new Vector2(this.transform.position.x, this.transform.position.y + nextCubeID), Quaternion.identity).GetComponent <CustomCube>(); //spawn a new cube on top of the last one

        newCube.transform.parent = this.transform;                                                                                                                                     //add it to object pool
        newCube.cubeID           = nextCubeID;                                                                                                                                         //set the cubes id
        nextCubeID++;                                                                                                                                                                  //increment the next cubeid
    }
示例#3
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 }
            });
        }