Пример #1
0
        // отрисовка треуголниками с помощью z буфера объемного изображения
        public static cls2D_Picture drawTriangleWithZBuffer()
        {
            cls2D_Picture polygonsImage = new cls2D_Picture(1700, 1500);
            clsZbuffer    zBuffer       = new clsZbuffer(1700, 1500);

            for (int i = 0; i < clsLoadData.polygonsForLineTrans.Count - 1; i++)
            {
                createTriangleWithZBuffer(clsLoadData.polygonsForLineTrans[i], polygonsImage,
                                          new clsRGB((int)Math.Abs(clsVectorsOperations.cosDirectionEarthNormal(clsLoadData.polygonsForLineTrans[i]) * 128),
                                                     (int)Math.Abs(clsVectorsOperations.cosDirectionEarthNormal(clsLoadData.polygonsForLineTrans[i]) * 128), 0), zBuffer);
            }
            return(polygonsImage);
        }
Пример #2
0
        public static cls2D_Picture drawTriangleWithZBufferForTransformationWithModifiedLight()
        {
            cls2D_Picture polygonsImage = new cls2D_Picture(5000, 5000);
            clsZbuffer    zBuffer       = new clsZbuffer(5000, 5000);

            for (int i = 0; i < clsLoadData.polygonsForTransformation.Count; i++)
            {
                if (clsVectorsOperations.getCosNormal(clsLoadData.polygonsForTransformation[i]) < 0)
                {
                    createTriangleWithZBufferForTransformationWithModifiedLight(clsLoadData.polygonsForTransformation[i], clsLoadData.normPolygons[i], polygonsImage, zBuffer, i);
                }
                else
                {
                    continue;
                }
            }
            return(polygonsImage);
        }
Пример #3
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);
                        }
                    }
                }
            }
        }
Пример #4
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);
                        }
                    }
                }
            }
        }
Пример #5
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));
                        }
                    }
                }
            }
        }