Beispiel #1
0
            // yes duplicate code, f**k all, I just want to be done with this.
            public void tri_(object owner, vec6[] points)
            {
                if (points[0].z < 1 || points[1].z < 1 || points[2].z < 1)
                {
                    return;
                }
                Array.Sort(points, sorter6.instance);
                if (points[0].y == points[1].y)
                {
                    toptri_(owner, points[0], points[1], points[2]);
                    return;
                }
                if (points[1].y == points[2].y)
                {
                    bottri_(owner, points[0], points[1], points[2]);
                    return;
                }
                float perc = progress(points[0].y, points[2].y, points[1].y);
                // lerp of z & uv need to be corrected (perspective correction thingies)
                float actualz = 1f / lerp(1f / points[0].w, 1f / points[2].w, perc);
                vec2  uv      = lerp(points[0].uv / points[0].w, points[2].uv / points[2].w, perc) * actualz;
                vec6  phantom = v6(v4(lerp(points[0].xyz, points[2].xyz, perc), actualz), uv);

                bottri_(owner, points[0], phantom, points[1]);
                toptri_(owner, phantom, points[1], points[2]);
            }
Beispiel #2
0
            private void bottri_(object owner, vec6 p0, vec6 p1, vec6 p2)
            {
                if (p2.x < p1.x)
                {
                    vec6 _ = p2;
                    p2 = p1;
                    p1 = _;
                }
                if (p0.y - p2.y == 0)
                {
                    return;
                }

                /*
                 * 0
                 * /\
                 * 1 2
                 */

                float minx = min(p0.x, p1.x);
                float miny = p0.y;
                float maxx = max(p0.x, p2.x);
                float maxy = p2.y;

                int p_minx = -hpixeloffset + (int)minx / pixelsize;
                int p_miny = -vpixeloffset + (int)miny / pixelsize;
                int p_maxx = -hpixeloffset + (int)maxx / pixelsize + 1;
                int p_maxy = -vpixeloffset + (int)maxy / pixelsize + 1;

                p_miny = max(0, min(p_miny, vpixels - 1));
                p_minx = max(0, min(p_minx, hpixels - 1));
                p_maxy = max(0, min(p_maxy, vpixels));
                p_maxx = max(0, min(p_maxx, hpixels));

                for (int y = p_miny; y < p_maxy; y++)
                {
                    float realy = this.y + y * pixelsize + pixelsize / 2f;

                    for (int x = p_minx; x < p_maxx; x++)
                    {
                        float realx = this.x + x * pixelsize + pixelsize / 2f;

                        if (realy <= p0.y)
                        {
                            continue;
                        }
                        if (realy >= p2.y)
                        {
                            continue;
                        }

                        float ypercleft = progress(p0.y, p1.y, realy);
                        float xminbound = lerp(p0.x, p1.x, ypercleft);

                        float ypercright = progress(p0.y, p2.y, realy);
                        float xmaxbound  = lerp(p0.x, p2.x, ypercright);

                        if (realx < xminbound)
                        {
                            continue;
                        }
                        if (realx >= xmaxbound)
                        {
                            continue;
                        }

                        float xperc = progress(xminbound, xmaxbound, realx);

                        float zleft  = 1f / lerp(1f / p0.w, 1f / p1.w, ypercleft);
                        float zright = 1f / lerp(1f / p0.w, 1f / p2.w, ypercright);
                        float zreal  = 1f / lerp(1f / zleft, 1f / zright, xperc);

                        /*
                         * if (realz < 1f) {
                         *      continue;
                         * }
                         */
                        if (this.owner[x, y] != null && zbuf[x, y] < zreal)
                        {
                            continue;
                        }
                        vec2 uvleft  = lerp(p0.uv / p0.w, p1.uv / p1.w, ypercleft) /** zleft*/;
                        vec2 uvright = lerp(p0.uv / p0.w, p2.uv / p2.w, ypercright) /** zright*/;
                        vec2 uvreal  = lerp(uvleft /*/ zleft*/, uvright /*/ zright*/, xperc) * zreal;
                        uv[x, y]         = uvreal;
                        zbuf[x, y]       = zreal;
                        this.owner[x, y] = owner;
                    }
                }
            }