public static List <clsNormsPolygon> loadNormsPolygonsFromObjectFile() { normsCoordinates = loadCoordinatesNormsFromObjectFile(); // считываем информацию for (int i = 0; i < lines.Length; i++) { words = lines[i].Split(' '); if (words[0] == "f") { words = lines[i].Split(' ', '/'); // считываем координаты полигонов polygon1 = int.Parse(words[3]); polygon2 = int.Parse(words[6]); polygon3 = int.Parse(words[9]); clsNormsPolygon normsPolygon = new clsNormsPolygon(); // записываем полигон normsPolygon[0] = normsCoordinates[polygon1 - 1]; normsPolygon[1] = normsCoordinates[polygon2 - 1]; normsPolygon[2] = normsCoordinates[polygon3 - 1]; normPolygons.Add(normsPolygon); // сохраняем в лист } } return(normPolygons); }
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); } } } } }