Advertisement
Broihon

Untitled

Nov 25th, 2015
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.66 KB | None | 0 0
  1. typedef struct D3D9VERTEX
  2. {
  3.     FLOAT X;
  4.     FLOAT Y;
  5.     FLOAT Z;
  6.     FLOAT RHW;
  7.     DWORD dwColour;
  8. }*PD3D9VERTEX, *LPD3D9VERTEX;
  9.  
  10. void SetVertexArray(D3D9VERTEX* pVertices, UINT Count, D3D9VERTEX Sample)
  11. {
  12.     for (UINT i = 0; i != Count; ++i)
  13.     {
  14.         pVertices[i] = Sample;
  15.     }
  16. }
  17.  
  18. void CreatePrimitive2D(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, FLOAT x3, FLOAT y3, DWORD Colour, D3D9VERTEX* pVertices)
  19. {
  20.     pVertices[0] = { x1, y1, 0.0f, 1.0f, Colour };
  21.     pVertices[1] = { x2, y2, 0.0f, 1.0f, Colour };
  22.     pVertices[2] = { x3, y3, 0.0f, 1.0f, Colour };
  23. }
  24.  
  25. struct D3D9VECT2
  26. {
  27.     FLOAT X;
  28.     FLOAT Y;
  29.  
  30.     D3D9VECT2 operator+ (const D3D9VECT2& v)
  31.     {
  32.         return{ X + v.X, Y + v.Y };
  33.     }
  34.  
  35.     D3D9VECT2 operator- (const D3D9VECT2& v)
  36.     {
  37.         return{ X - v.X, Y - v.Y };
  38.     }
  39.  
  40.     D3D9VECT2& operator+= (const D3D9VECT2& v)
  41.     {
  42.         X += v.X;
  43.         Y += v.Y;
  44.         return *this;
  45.     }
  46.  
  47.     D3D9VECT2& operator-= (const D3D9VECT2& v)
  48.     {
  49.         X -= v.X;
  50.         Y -= v.Y;
  51.         return *this;
  52.     }
  53.  
  54.     D3D9VECT2 operator* (const FLOAT& f)
  55.     {
  56.         return{ X * f, Y * f };
  57.     }
  58.  
  59.     D3D9VECT2 operator/ (const FLOAT& f)
  60.     {
  61.         return{ X / f, Y / f };
  62.     }
  63.  
  64.     D3D9VECT2& operator*= (const FLOAT& f)
  65.     {
  66.         X *= f;
  67.         Y *= f;
  68.         return *this;
  69.     }
  70.  
  71.     D3D9VECT2& operator/= (const FLOAT& f)
  72.     {
  73.         X /= f;
  74.         Y /= f;
  75.         return *this;
  76.     }
  77.  
  78.     FLOAT Length()
  79.     {
  80.         return sqrt(X * X + Y * Y);
  81.     }
  82. };
  83.  
  84. class D3D9ROUNDEDBOX
  85. {
  86. public:
  87.     D3D9ROUNDEDBOX()
  88.     {
  89.         m_X = 0;
  90.         m_Y = 0;
  91.         m_Width = 0;
  92.         m_Height = 0;
  93.         m_Colour = 0;
  94.  
  95.  
  96.         m_Rounding = 0;
  97.         m_PrimCount = 0;
  98.         m_Precision = 0;
  99.         m_Pi = 3.14159236535897932385;
  100.         m_pVertices = nullptr;
  101.     }
  102.  
  103.     void Set(UINT X, UINT Y, UINT Width, UINT Height, UINT Rounding, DWORD Colour, UINT Precision)
  104.     {
  105.         if (m_pVertices)
  106.         {
  107.             Memory::SafeDeleteArr(m_pVertices);
  108.         }
  109.  
  110.         m_X = X;
  111.         m_Y = Y;
  112.         m_Width = Width;
  113.         m_Height = Height;
  114.         m_Rounding = Rounding;
  115.         m_Precision = Precision;
  116.         m_Colour = Colour;
  117.         m_PrimCount = 6 + (m_Precision) * 2 - 1;
  118.  
  119.         D3D9VECT2 Center = { m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2 + m_Rounding };
  120.         D3D9VECT2 StartPoint = { m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2 };
  121.         DOUBLE Step = (DOUBLE)m_Rounding / (DOUBLE)m_Precision;
  122.         DOUBLE Alpha = m_Pi / (m_Precision + 1) / 2;
  123.         DOUBLE CurrAlpha = Alpha;
  124.  
  125.         m_pVertices = new D3D9VERTEX[m_PrimCount * 3 * 4];
  126.         SetVertexArray(m_pVertices, m_PrimCount * 3, { 0.0f, 0.0f, 0.0f, 1.0f, 0 });
  127.         CreatePrimitive2D(m_X - m_Width / 2 + m_Rounding, m_Y - m_Height / 2, m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2, m_X - m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_Colour, &(m_pVertices[0]));
  128.         CreatePrimitive2D(m_X + m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_X + m_Width / 2 - m_Rounding, m_Y - m_Height / 2, m_X - m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_Colour, &(m_pVertices[3]));
  129.         CreatePrimitive2D(m_X + m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_X - m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_X - m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_Colour, &(m_pVertices[6]));
  130.         CreatePrimitive2D(m_X + m_Width / 2, m_Y - m_Height / 2 + m_Rounding, m_X - m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_X + m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_Colour, &(m_pVertices[9]));
  131.         CreatePrimitive2D(m_X - m_Width / 2 + m_Rounding, m_Y + m_Height / 2, m_X - m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_X + m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_Colour, &(m_pVertices[12]));
  132.         CreatePrimitive2D(m_X - m_Width / 2 + m_Rounding, m_Y + m_Height / 2, m_X + m_Width / 2 - m_Rounding, m_Y + m_Height / 2, m_X + m_Width / 2, m_Y + m_Height / 2 - m_Rounding, m_Colour, &(m_pVertices[15]));
  133.  
  134.         for (UINT i = 18; i != (m_PrimCount * 3); StartPoint.X += Step, StartPoint.Y += Step)
  135.         {
  136.             if (i != 18)
  137.             {
  138.                 CurrAlpha += Alpha;
  139.  
  140.                 CreatePrimitive2D(
  141.                     StartPoint.X, StartPoint.Y,
  142.                     StartPoint.X + Step, StartPoint.Y + Step,
  143.                     Center.X + m_Rounding * sin(CurrAlpha), Center.Y - m_Rounding * cos(CurrAlpha),
  144.                     0xFF00FF00, //m_Colour
  145.                     &(m_pVertices[i + 3]));
  146.  
  147.                 CreatePrimitive2D(
  148.                     m_X - (m_pVertices[i + 3].X - m_X), m_pVertices[i + 3].Y,
  149.                     m_X - (m_pVertices[i + 4].X - m_X), m_pVertices[i + 4].Y,
  150.                     m_X - (m_pVertices[i + 5].X - m_X), m_pVertices[i + 5].Y,
  151.                     0xFF00FF00, //m_Colour
  152.                     &(m_pVertices[i + 3 + (m_PrimCount * 3 - 18) * 1]));
  153.  
  154.                 CreatePrimitive2D(
  155.                     m_pVertices[i + 3].X, m_Y + (m_Y - m_pVertices[i + 3].Y),
  156.                     m_pVertices[i + 4].X, m_Y + (m_Y - m_pVertices[i + 4].Y),
  157.                     m_pVertices[i + 5].X, m_Y + (m_Y - m_pVertices[i + 5].Y),
  158.                     0xFF00FF00, //m_Colour
  159.                     &(m_pVertices[i + 3 + (m_PrimCount * 3 - 18) * 2]));
  160.  
  161.                 CreatePrimitive2D(
  162.                     m_X - (m_pVertices[i + 3].X - m_X), m_Y + (m_Y - m_pVertices[i + 3].Y),
  163.                     m_X - (m_pVertices[i + 4].X - m_X), m_Y + (m_Y - m_pVertices[i + 4].Y),
  164.                     m_X - (m_pVertices[i + 5].X - m_X), m_Y + (m_Y - m_pVertices[i + 5].Y),
  165.                     0xFF00FF00, //m_Colour
  166.                     &(m_pVertices[i + 3 + (m_PrimCount * 3 - 18) * 3]));
  167.  
  168.                 CreatePrimitive2D(
  169.                     m_pVertices[i + 3].X, m_pVertices[i + 3].Y,
  170.                     m_pVertices[i + 5].X, m_pVertices[i + 5].Y,
  171.                     m_pVertices[i - 1].X, m_pVertices[i - 1].Y,
  172.                     0xFF0000FF, //m_Colour
  173.                     &(m_pVertices[i]));
  174.  
  175.                 CreatePrimitive2D(
  176.                     m_X - (m_pVertices[i + 0].X - m_X), m_pVertices[i + 0].Y,
  177.                     m_X - (m_pVertices[i + 1].X - m_X), m_pVertices[i + 1].Y,
  178.                     m_X - (m_pVertices[i + 2].X - m_X), m_pVertices[i + 2].Y,
  179.                     0xFF0000FF, //m_Colour
  180.                     &(m_pVertices[i + (m_PrimCount * 3 - 18) * 1]));
  181.  
  182.                 CreatePrimitive2D(
  183.                     m_pVertices[i + 0].X, m_Y + (m_Y - m_pVertices[i + 0].Y),
  184.                     m_pVertices[i + 1].X, m_Y + (m_Y - m_pVertices[i + 1].Y),
  185.                     m_pVertices[i + 2].X, m_Y + (m_Y - m_pVertices[i + 2].Y),
  186.                     0xFF0000FF, //m_Colour
  187.                     &(m_pVertices[i + (m_PrimCount * 3 - 18) * 2]));
  188.  
  189.                 CreatePrimitive2D(
  190.                     m_X - (m_pVertices[i + 0].X - m_X), m_Y + (m_Y - m_pVertices[i + 0].Y),
  191.                     m_X - (m_pVertices[i + 1].X - m_X), m_Y + (m_Y - m_pVertices[i + 1].Y),
  192.                     m_X - (m_pVertices[i + 2].X - m_X), m_Y + (m_Y - m_pVertices[i + 2].Y),
  193.                     0xFF0000FF, //m_Colour
  194.                     &(m_pVertices[i + (m_PrimCount * 3 - 18) * 3]));
  195.  
  196.                 i += 6;
  197.             }
  198.             else
  199.             {
  200.                 CreatePrimitive2D(
  201.                     StartPoint.X, StartPoint.Y,
  202.                     StartPoint.X + Step, StartPoint.Y + Step,
  203.                     Center.X + m_Rounding * sin(CurrAlpha), Center.Y - m_Rounding * cos(CurrAlpha),
  204.                     0xFF00FF00, //m_Colour
  205.                     &(m_pVertices[i]));
  206.                
  207.                 CreatePrimitive2D(
  208.                     m_X - (m_pVertices[i + 0].X - m_X), m_pVertices[i + 0].Y,
  209.                     m_X - (m_pVertices[i + 1].X - m_X), m_pVertices[i + 1].Y,
  210.                     m_X - (m_pVertices[i + 2].X - m_X), m_pVertices[i + 2].Y,
  211.                     0xFF00FF00, //m_Colour
  212.                     &(m_pVertices[i + (m_PrimCount * 3 - 18) * 1]));
  213.  
  214.                 CreatePrimitive2D(
  215.                     m_pVertices[i + 0].X, m_Y + (m_Y - m_pVertices[i + 0].Y),
  216.                     m_pVertices[i + 1].X, m_Y + (m_Y - m_pVertices[i + 1].Y),
  217.                     m_pVertices[i + 2].X, m_Y + (m_Y - m_pVertices[i + 2].Y),
  218.                     0xFF00FF00, //m_Colour
  219.                     &(m_pVertices[i + (m_PrimCount * 3 - 18) * 2]));
  220.  
  221.                 CreatePrimitive2D(
  222.                     m_X - (m_pVertices[i + 0].X - m_X), m_Y + (m_Y - m_pVertices[i + 0].Y),
  223.                     m_X - (m_pVertices[i + 1].X - m_X), m_Y + (m_Y - m_pVertices[i + 1].Y),
  224.                     m_X - (m_pVertices[i + 2].X - m_X), m_Y + (m_Y - m_pVertices[i + 2].Y),
  225.                     0xFF00FF00, //m_Colour
  226.                     &(m_pVertices[i + (m_PrimCount * 3 - 18) * 3]));
  227.  
  228.                 i += 3;
  229.             }
  230.         }
  231.     }
  232.  
  233.     void Draw(IDirect3DDevice9* pDevice)
  234.     {
  235.         pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_PrimCount + (m_PrimCount - 6) * 3, m_pVertices, sizeof(D3D9VERTEX));
  236.     }
  237.  
  238. private:
  239.  
  240.     UINT m_X;
  241.     UINT m_Y;
  242.     UINT m_Width;
  243.     UINT m_Height;
  244.     DWORD m_Colour;
  245.  
  246.     UINT m_Rounding;
  247.     UINT m_PrimCount;
  248.     UINT m_Precision;
  249.     DOUBLE m_Pi;
  250.  
  251.     D3D9VERTEX* m_pVertices;
  252. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement