public void printPolyZ(RPolygon pIn)
        {
            if (pIn.isEpsilonGeometry())
            {
                return;
            }

            RPolygon polygon = pIn.reSort();

            if (polygon.isOffScreen(this.pixelLeftTop, this.pixelRightBottom))
            {
                return;
            }

            if (polygon.isFlatTop())
            {
                printPolyFlatTopZ(polygon);
            }
            else
            {
                if (polygon.isFlatBottom())
                {
                    printPolyFlatBottomZ(polygon);
                }
                else
                {
                    RPolygon p1 = polygon.getBottomFlat();
                    printPolyFlatBottomZ(p1);

                    RPolygon p2 = polygon.getTopFlat();
                    printPolyFlatTopZ(p2);
                }
            }
        }
示例#2
0
        public void printPolyZ(RPolygon pIn)
        {
            RPolygon polygon     = pIn.reSort();
            float    area        = polygon.screenArea();
            float    oneOverArea = 1.0f / area;

            Vec3f v0 = polygon.v0;
            Vec3f v1 = polygon.v1;
            Vec3f v2 = polygon.v2;

            if (polygon.isEpsilonGeometry())
            {
                return;
            }

            if (polygon.isOffScreen(this.pixelLeftTop, this.pixelRightBottom))
            {
                return;
            }

            if (area < 1.0f && area > -1.0f)
            {
                return;
            }

            Vec2i leftTop     = polygon.topLeft();
            Vec2i bottomRight = polygon.bottomRight();

            if (leftTop.x < 0)
            {
                leftTop.x = 0;
            }

            if (leftTop.y < 0)
            {
                leftTop.y = 0;
            }

            if (bottomRight.x >= pixelWidth)
            {
                bottomRight.x = pixelWidth - 1;
            }

            if (bottomRight.y >= pixelHeight)
            {
                bottomRight.y = pixelHeight - 1;
            }

            for (int x = leftTop.x; x < bottomRight.x; x++)
            {
                for (int y = leftTop.y; y < bottomRight.y; y++)
                {
                    Vec2f p = new Vec2f(x, y);
                    Vec3f w = polygon.lambdas(p);

                    if ((w.x >= 0.0f && w.y >= 0.0f && w.z >= 0.0f) || (w.x <= 0.0f && w.y <= 0.0f && w.z <= 0.0f))
                    {
                        w *= oneOverArea;

                        float z  = 1.0f / (v0.z * w.x + v1.z * w.y + v2.z * w.z);
                        Vec2f UV = new Vec2f(
                            (polygon.vertex0.textureCoordinates.x * w.x + polygon.vertex1.textureCoordinates.x * w.y + polygon.vertex2.textureCoordinates.x * w.z) * z,
                            (polygon.vertex0.textureCoordinates.y * w.x + polygon.vertex1.textureCoordinates.y * w.y + polygon.vertex2.textureCoordinates.y * w.z) * z
                            );
                        Vec4f texColor = polygon.texture.sampleTextureA(UV);
                        printPixelZ(x, y, z, new Vec3f(texColor));
                    }
                }
            }
        }