Простое отсечение в DirectX 9

Меня интересует простое отсечение прямоугольников в Directx9. введите описание изображения здесьНа верхней картинке вы видите, что я получаю. Я хочу получить то, что на нижней картинке, без изменения координат и/или области просмотра. Это означает, что я нарисую весь круг, а Directx9 просто обрежет его.

Было бы предпочтительнее, чтобы прямоугольник клипа был задан в координатах WINDOW, чтобы на него не влияли преобразования текущего состояния. Кроме того, это должно повлиять на все, что теперь происходит в окне, включая полигоны, спрайты, текстуры, текст и т. д.

Может кто подскажет как это сделать?


person Iron-Eagle    schedule 31.01.2013    source источник
comment
Помогает ли это: toymaker.info/Games/html/clipping.html ?   -  person Deukalion    schedule 02.02.2013


Ответы (2)


Вы описываете ножничный тест, встроенный в устройство DirectX.

См. проверку ножницами.

В частности, вы просто устанавливаете прямоугольник в координатах экрана, используя SetScissorRect

А затем включите тест ножниц, позвонив

device->SetRenderState( D3DRS_SCISSORTESTENABLE , TRUE );
person default    schedule 14.02.2013

У меня был тот же вопрос месяц назад, и я сам придумал решение после попытки найти метод отсечения, поэтому мне пришлось разработать свой собственный... Это должно работать:

void Clip(LPDIRECT3DDEVICE9 device, LPDIRECT3DSURFACE9 surface, LPDIRECT3DSURFACE9 backbuffer, int x, int y, int width, int height, int destX, int destY, int destWidth, int destHeight)
{
    RECT source;

    if (x >= destX && (x+width) <= (destX+destWidth))
    {
        source.left = 0;
        source.right = width;
    }
    else if ( (x >= destX && x <= (destX+destWidth)) && ((x+width) > (destX+destWidth)))
    {
        source.left = 0;
        source.right = width - ((x+width) - (destX+destWidth));
        source.right = abs(source.right);
    }
    else if (x < destX && (x+width) < (destX+destWidth))
    {
        source.left = abs(x);
        source.right = width;
    }
    else if ( (x < destX) && ((x+width) > (destX+destWidth)))
    {
        source.left = abs(x);
        source.right = source.left + (destWidth);
    }
    else
    {   
        return;
    }


    if (y >= destY && (y+height) <= (destY+destHeight))
    {
        source.top = 0;
        source.bottom = height;
    }
    else if ( (y >= destY && y <= (destY+destHeight)) && ((y+height) > (destY+destHeight)) )
    {
        source.top = 0;
        source.bottom = height - ((y+height) - (destY+destHeight));
        source.bottom = abs(source.bottom);
    }
    else if (y < destY && (y+height) > destY && (y+height) <= (destY+destHeight))
    {
        source.top = abs(y);
        source.bottom = height;
    }
    else if ( (y < destY) && ((y+height) > (destY+destHeight)))
    {
        source.top = abs(y);    
        source.bottom = source.top + (destHeight);
    }
    else
    {
        return;
    }


    RECT destination;

    if (x >= destX && (x+width) <= (destX+destWidth))
    {
        destination.left = x;
        destination.right = x + width;
    }
    else if ( (x >= destX && x <= (destX+destWidth)) && ((x+width) > (destX+destWidth)))
    {
        destination.left = x;
        destination.right = (destX+destWidth);
    }
    else if ( (x < destX) && ((x+width) < (destX+destWidth)) && ((x+width) >= x))
    {
        destination.left = destX;
        destination.right = width - abs(x);
    }
    else if ( (x < destX) && ((x+width) > (destX+destWidth)))
    {
        destination.left = destX;
        destination.right = (destX+destWidth);
    }
    else
    {   
        return;
    }

    if (y >= destY && (y+height) <= (destY+destHeight))
    {
        destination.top = y;
        destination.bottom = y + height;
    }
    else if ( (y >= destY && y <= (destY+destHeight)) && (y+height) > (destY+destHeight))
    {
        destination.top = y;
        destination.bottom = (destY+destHeight);
    }
    else if (y < destY && (y+height) > destY && (y+height) <= (destY+destHeight))
    {
        destination.top = destY;
        destination.bottom = height - abs(y);
    }
    else if ( (y < destY) && ((y+height) > (destY+destHeight)))
    {
        destination.top = destY;
        destination.bottom = (destY+destHeight);
    }
    else
    {
        return;
    }

    device->StretchRect(surface, &source, backbuffer, &destination, D3DTEXF_NONE);      

    DeleteObject(&source);
    DeleteObject(&destination);
};
person Deukalion    schedule 02.02.2013