Exemple #1
0
        public render_texuv br;                 // bottom-right UV coordinate


        public render_quad_texuv(render_quad_texuv other)
        {
            tl = other.tl;
            tr = other.tr;
            bl = other.bl;
            br = other.br;
        }
Exemple #2
0
        /*-------------------------------------------------
        *   render_clip_quad - clip a quad to a rectangle
        *  -------------------------------------------------*/
        public static bool render_clip_quad(ref render_bounds bounds, render_bounds clip, ref render_quad_texuv texcoords, bool use_texcoords)
        {
            /* ensure our assumptions about the bounds are correct */
            assert(bounds.x0 <= bounds.x1);
            assert(bounds.y0 <= bounds.y1);

            /* trivial reject */
            if (bounds.y1 < clip.y0)
            {
                return(true);
            }
            if (bounds.y0 > clip.y1)
            {
                return(true);
            }
            if (bounds.x1 < clip.x0)
            {
                return(true);
            }
            if (bounds.x0 > clip.x1)
            {
                return(true);
            }

            /* clip top (x0,y0)-(x1,y1) */
            if (bounds.y0 < clip.y0)
            {
                float frac = (clip.y0 - bounds.y0) / (bounds.y1 - bounds.y0);
                bounds.y0 = clip.y0;
                if (use_texcoords)  //if (texcoords != nullptr)
                {
                    texcoords.tl.u += (texcoords.bl.u - texcoords.tl.u) * frac;
                    texcoords.tl.v += (texcoords.bl.v - texcoords.tl.v) * frac;
                    texcoords.tr.u += (texcoords.br.u - texcoords.tr.u) * frac;
                    texcoords.tr.v += (texcoords.br.v - texcoords.tr.v) * frac;
                }
            }

            /* clip bottom (x3,y3)-(x2,y2) */
            if (bounds.y1 > clip.y1)
            {
                float frac = (bounds.y1 - clip.y1) / (bounds.y1 - bounds.y0);
                bounds.y1 = clip.y1;
                if (use_texcoords)  //if (texcoords != nullptr)
                {
                    texcoords.bl.u -= (texcoords.bl.u - texcoords.tl.u) * frac;
                    texcoords.bl.v -= (texcoords.bl.v - texcoords.tl.v) * frac;
                    texcoords.br.u -= (texcoords.br.u - texcoords.tr.u) * frac;
                    texcoords.br.v -= (texcoords.br.v - texcoords.tr.v) * frac;
                }
            }

            /* clip left (x0,y0)-(x3,y3) */
            if (bounds.x0 < clip.x0)
            {
                float frac = (clip.x0 - bounds.x0) / (bounds.x1 - bounds.x0);
                bounds.x0 = clip.x0;
                if (use_texcoords)  //if (texcoords != nullptr)
                {
                    texcoords.tl.u += (texcoords.tr.u - texcoords.tl.u) * frac;
                    texcoords.tl.v += (texcoords.tr.v - texcoords.tl.v) * frac;
                    texcoords.bl.u += (texcoords.br.u - texcoords.bl.u) * frac;
                    texcoords.bl.v += (texcoords.br.v - texcoords.bl.v) * frac;
                }
            }

            /* clip right (x1,y1)-(x2,y2) */
            if (bounds.x1 > clip.x1)
            {
                float frac = (bounds.x1 - clip.x1) / (bounds.x1 - bounds.x0);
                bounds.x1 = clip.x1;
                if (use_texcoords)  //if (texcoords != nullptr)
                {
                    texcoords.tr.u -= (texcoords.tr.u - texcoords.tl.u) * frac;
                    texcoords.tr.v -= (texcoords.tr.v - texcoords.tl.v) * frac;
                    texcoords.br.u -= (texcoords.br.u - texcoords.bl.u) * frac;
                    texcoords.br.v -= (texcoords.br.v - texcoords.bl.v) * frac;
                }
            }

            return(false);
        }