Exemplo n.º 1
0
 public static List <clsPolygon> loadPolygonsFromObjectFileWithCheck()
 {
     pointsForLineTrans = loadTopsFromObjectFileForLineTrans();                     // считываем информацию
     for (int i = 0; i < lines.Length; i++)
     {
         words = lines[i].Split(' ');
         if (words[0] == "f")
         {
             words    = lines[i].Split(' ', '/');                            // считываем координаты полигонов
             polygon1 = int.Parse(words[1]);
             polygon2 = int.Parse(words[4]);
             polygon3 = int.Parse(words[7]);
             clsPolygon polygon = new clsPolygon();                      //  записываем полигон
             polygon[0] = pointsForLineTrans[polygon1 - 1];
             polygon[1] = pointsForLineTrans[polygon2 - 1];
             polygon[2] = pointsForLineTrans[polygon3 - 1];
             clsBarycentricCoordinates barycentricCoordinates = new clsBarycentricCoordinates(polygon);
             barycentricCoordinates.Calculating_lambda_coefficients(polygon[0]);
             if (Math.Abs(1 - barycentricCoordinates.Lambda0 - barycentricCoordinates.Lambda1 -
                          barycentricCoordinates.Lambda2) > 0.001)
             {
                 MessageBox.Show("Сумма барицентрических координат не равна 1!", "Ошибка",
                                 MessageBoxButtons.OK);
             }
             polygonsForLineTrans.Add(polygon);                                          // сохраняем в лист
         }
     }
     return(polygonsForLineTrans);
 }
Exemplo n.º 2
0
        // создание треугольниов с помощью z буфера
        public static void createTriangleWithZBuffer(clsPolygon polygon, cls2D_Picture image, clsRGB colour, clsZbuffer zBuffer)
        {
            minimalX = functionMinimumX(polygon);
            maximalX = functionMaximumX(polygon, image);
            minimalY = functionMinimumY(polygon);
            maximalY = functionMaximumY(polygon, image);
            clsBarycentricCoordinates barycentricPoint = new clsBarycentricCoordinates(polygon);

            for (int x = minimalX; x < maximalX; x++)
            {
                for (int y = minimalY; y < maximalY; y++)
                {
                    barycentricPoint.Calculating_lambda_coefficients(new cls3D_Point(x, y));
                    if (barycentricPoint.Lambda0 >= 0 && barycentricPoint.Lambda1 >= 0 && barycentricPoint.Lambda2 >= 0)
                    {
                        double z = barycentricPoint.Lambda0 * polygon[0].Z + barycentricPoint.Lambda1 * polygon[1].Z + barycentricPoint.Lambda2 * polygon[2].Z;
                        if (z < zBuffer.getZBuffer(x, y))
                        {
                            zBuffer.setZBuffer(x, y, z);
                            image.setPixel(x, y, colour);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void createTriangleWithZBufferForTransformationWithModifiedLight(clsPolygonModified polygon, clsNormsPolygon normsPolygon, cls2D_Picture image, clsZbuffer zBuffer, int i)
        {
            minimalX = funcMinimumX(polygon);
            maximalX = funcMaximumX(polygon, image);
            minimalY = funcMinimumY(polygon);
            maximalY = funcMaximumY(polygon, image);
            clsBarycentricCoordinates barycentricPoint = new clsBarycentricCoordinates(polygon);
            double l0 = clsVectorsOperations.scalarMulty(normsPolygon[0]) / (clsVectorsOperations.lengthNorm(normsPolygon[0]) * clsVectorsOperations.lengthVectorLight());
            double l1 = clsVectorsOperations.scalarMulty(normsPolygon[1]) / (clsVectorsOperations.lengthNorm(normsPolygon[1]) * clsVectorsOperations.lengthVectorLight());
            double l2 = clsVectorsOperations.scalarMulty(normsPolygon[2]) / (clsVectorsOperations.lengthNorm(normsPolygon[2]) * clsVectorsOperations.lengthVectorLight());

            for (int x = minimalX; x <= maximalX; x++)
            {
                for (int y = minimalY; y <= maximalY; y++)
                {
                    barycentricPoint.calc_lambda_for_Transformation(x, y);
                    if (barycentricPoint.lambda0 > 0 && barycentricPoint.lambda1 > 0 && barycentricPoint.lambda2 > 0)
                    {
                        double z = barycentricPoint.lambda0 * polygon[0].originalZ + barycentricPoint.lambda1 * polygon[1].originalZ + barycentricPoint.lambda2 * polygon[2].originalZ;
                        if (z < zBuffer.getZBuffer(x, y))
                        {
                            int brightness = (int)Math.Abs((255 * (barycentricPoint.lambda0 * l0 + barycentricPoint.lambda1 * l1 + barycentricPoint.lambda2 * l2)));
                            image.setPixel(x, y, new clsRGB(brightness, 0, 0));
                            zBuffer.setZBuffer(x, y, z);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void createTriangleWithZBufferForTransformation(clsPolygonModified polygon, cls2D_Picture image, clsZbuffer zBuffer, int i)
        {
            minimalX = funcMinimumX(polygon);
            maximalX = funcMaximumX(polygon, image);
            minimalY = funcMinimumY(polygon);
            maximalY = funcMaximumY(polygon, image);
            clsBarycentricCoordinates barycentricPoint = new clsBarycentricCoordinates(polygon);

            for (int x = minimalX; x <= maximalX; x++)
            {
                for (int y = minimalY; y <= maximalY; y++)
                {
                    barycentricPoint.calc_lambda_for_Transformation(x, y);
                    if (barycentricPoint.lambda0 > 0 && barycentricPoint.lambda1 > 0 && barycentricPoint.lambda2 > 0)
                    {
                        double z = barycentricPoint.lambda0 * polygon[0].originalZ + barycentricPoint.lambda1 * polygon[1].originalZ + barycentricPoint.lambda2 * polygon[2].originalZ;
                        if (z < zBuffer.getZBuffer(x, y))
                        {
                            zBuffer.setZBuffer(x, y, z);
                            image.setPixel(x, y, new clsRGB((int)Math.Abs(clsVectorsOperations.getCosNormal(clsLoadData.polygonsForTransformation[i]) * 255), 0, 0));
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        // создание треугольников
        public static void createTriangle(clsPolygon polygon, cls2D_Picture image, clsRGB colour)
        {
            minimalX = functionMinimumX(polygon);
            maximalX = functionMaximumX(polygon, image);
            minimalY = functionMinimumY(polygon);
            maximalY = functionMaximumY(polygon, image);
            clsBarycentricCoordinates barycentricPoint = new clsBarycentricCoordinates(polygon);

            for (int x = minimalX; x < maximalX; x++)
            {
                for (int y = minimalY; y < maximalY; y++)
                {
                    barycentricPoint.Calculating_lambda_coefficients(new cls3D_Point(x, y));
                    if (barycentricPoint.Lambda0 >= 0 && barycentricPoint.Lambda1 >= 0 && barycentricPoint.Lambda2 >= 0)
                    {
                        image.setPixel(x, y, colour);
                    }
                }
            }
        }