Подпишитесь на наш Telegram-канал, чтобы всегда быть в курсе важных обновлений! Перейти

Вопрос Anyone have a radial circle gradient for surface render

  • Автор темы Автор темы Cynical
  • Дата начала Дата начала
C++:
Expand Collapse Copy
void DrawManager::CircleFilledDualColor(float x, float y, float rad, float rotate, int type, int resolution, DWORD color, DWORD color2, IDirect3DDevice9* m_device)
{
    LPDIRECT3DVERTEXBUFFER9 g_pVB2;
 
    std::vector<CUSTOMVERTEX> circle(resolution + 2);
 
    float angle = rotate * D3DX_PI / 180, pi = D3DX_PI;
 
    if (type == 1)
        pi = D3DX_PI; // Full circle
    if (type == 2)
        pi = D3DX_PI / 2; // 1/2 circle
    if (type == 3)
        pi = D3DX_PI / 4; // 1/4 circle
 
    pi = D3DX_PI / type; // 1/4 circle
 
    circle[0].x = x;
    circle[0].y = y;
    circle[0].z = 0;
    circle[0].rhw = 1;
    circle[0].color = color2;
 
    for (int i = 1; i < resolution + 2; i++)
    {
        circle[i].x = (float)(x - rad * cos(pi*((i - 1) / (resolution / 2.0f))));
        circle[i].y = (float)(y - rad * sin(pi*((i - 1) / (resolution / 2.0f))));
        circle[i].z = 0;
        circle[i].rhw = 1;
        circle[i].color = color;
    }
 
    // Rotate matrix
    int _res = resolution + 2;
    for (int i = 0; i < _res; i++)
    {
        circle[i].x = x + cos(angle)*(circle[i].x - x) - sin(angle)*(circle[i].y - y);
        circle[i].y = y + sin(angle)*(circle[i].x - x) + cos(angle)*(circle[i].y - y);
    }
 
    m_device->CreateVertexBuffer((resolution + 2) * sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &g_pVB2, NULL);
 
    VOID* pVertices;
    g_pVB2->Lock(0, (resolution + 2) * sizeof(CUSTOMVERTEX), (void**)&pVertices, 0);
    memcpy(pVertices, &circle[0], (resolution + 2) * sizeof(CUSTOMVERTEX));
    g_pVB2->Unlock();
 
    m_device->SetTexture(0, NULL);
    m_device->SetPixelShader(NULL);
    m_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    m_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    m_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
 
    m_device->SetStreamSource(0, g_pVB2, 0, sizeof(CUSTOMVERTEX));
    m_device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
    m_device->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, resolution);
    if (g_pVB2 != NULL)
        g_pVB2->Release();
}
you're also going to need a struct called CUSTOMVERTEX but thats not hard to figure out on your own

to draw colors you're gonna need to know how D3DCOLOR works but other than that you should be good go to hf with your brand new ""private"" feature
______
Credits: uc
 
Назад
Сверху Снизу