Advertisement
Guest User

Untitled

a guest
Jun 8th, 2018
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. void gui::CircleFilledDualColor(float x, float y, float rad, float rotate, int type, int resolution, DWORD color, DWORD color2, IDirect3DDevice9* m_device)
  2. {
  3.  
  4. std::vector<CUSTOMVERTEX> circle(resolution + 2);
  5.  
  6. float angle = rotate * D3DX_PI2 / 180, pi = D3DX_PI2;
  7.  
  8. if (type == full)
  9. pi = D3DX_PI2; // Full circle
  10. if (type == half)
  11. pi = D3DX_PI2 / 2; // 1/2 circle
  12. if (type == quarter)
  13. pi = D3DX_PI2 / 4; // 1/4 circle
  14.  
  15. pi = D3DX_PI2 / type; // 1/4 circle
  16.  
  17. circle[0].x = x;
  18. circle[0].y = y;
  19. circle[0].z = 0;
  20. circle[0].rhw = 1;
  21. circle[0].color = color2;
  22.  
  23. for (int i = 1; i < resolution + 2; i++)
  24. {
  25. circle[i].x = (float)(x - rad * cos(pi*((i - 1) / (resolution / 2.0f))));
  26. circle[i].y = (float)(y - rad * sin(pi*((i - 1) / (resolution / 2.0f))));
  27. circle[i].z = 0;
  28. circle[i].rhw = 1;
  29. circle[i].color = color;
  30. }
  31.  
  32. // Rotate matrix
  33. int _res = resolution + 2;
  34. for (int i = 0; i < _res; i++)
  35. {
  36. circle[i].x = x + cos(angle)*(circle[i].x - x) - sin(angle)*(circle[i].y - y);
  37. circle[i].y = y + sin(angle)*(circle[i].x - x) + cos(angle)*(circle[i].y - y);
  38. }
  39.  
  40. m_device->CreateVertexBuffer((resolution + 2) * sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &g_pVB2, NULL);
  41.  
  42. VOID* pVertices;
  43. g_pVB2->Lock(0, (resolution + 2) * sizeof(CUSTOMVERTEX), (void**)&pVertices, 0);
  44. memcpy(pVertices, &circle[0], (resolution + 2) * sizeof(CUSTOMVERTEX));
  45. g_pVB2->Unlock();
  46.  
  47. m_device->SetTexture(0, NULL);
  48. m_device->SetPixelShader(NULL);
  49. m_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  50. m_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
  51. m_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
  52.  
  53. m_device->SetStreamSource(0, g_pVB2, 0, sizeof(CUSTOMVERTEX));
  54. m_device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
  55. m_device->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, resolution);
  56. if (g_pVB2 != NULL)
  57. g_pVB2->Release();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement