Advertisement
Guest User

QTS no. 23 - Primitive rectangle and line gradients

a guest
Aug 27th, 2010
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. /*
  2. -----------------------------------------
  3. * Game hacking QTS ( Quickie Tip Series )
  4. * no. 23 - Primitive rectangle and line gradients
  5. -----------------------------------------
  6. * Author: SEGnosis  - GHAnon.net
  7. * Thanks to:
  8. * bitterbanana      - No known site
  9. * Drunken Cheetah   - No known site
  10. * fatboy88      - No known site
  11. * Geek4Ever         - No known site
  12. * learn_more        - www.uc-forum.com
  13. * Novocaine         - http://ilsken.net/blog/?page_id=64
  14. * Philly0494        - No known site
  15. * Roverturbo        - www.uc-forum.com
  16. * SilentKarma       - www.halocoders.com - offline
  17. * Strife        - www.uc-forum.com
  18. * Wieter20      - No known site
  19. */
  20.  
  21. struct FVect3
  22. {
  23.     float x, y, z;
  24. };
  25.  
  26. struct FVect2
  27. {
  28.     float x, y;
  29. };
  30.  
  31. struct FTrigFunc
  32. {
  33.     float   sine,
  34.         cosine,
  35.         tangent,
  36.         hypotenuse,
  37.         radian;
  38. };
  39.  
  40.  
  41.  
  42. void GradientRect( D3DXVECTOR2 vPos, int iWidth, int iHeight, D3DCOLOR coA, D3DCOLOR coB )
  43. {
  44.     CDraw.Rect( vPos.x, vPos.y, iWidth, iHeight, coA );
  45.  
  46.     S_D3DCOLOR* pColor = ( S_D3DCOLOR* )&coB;
  47.  
  48.     pColor->a = 0;
  49.  
  50.     float fRateY = 255 / iHeight;
  51.  
  52.     for( int i = 0; i < iHeight; i++ )
  53.     {
  54.         CDraw.Rect( vPos.x, vPos.y + i, iWidth, 1, coB );
  55.  
  56.         pColor->a = min( 255, pColor->a + fRateY );
  57.     }
  58. }
  59.  
  60. void GradientLine( D3DXVECTOR2 vPosA, D3DXVECTOR2 vPosB, D3DCOLOR coA, D3DCOLOR coB, DWORD dwWidth = 1 )
  61. {
  62.     S_D3DCOLOR* pColor = ( S_D3DCOLOR* )&coB;
  63.  
  64.     FTrigFunc vTrig;
  65.  
  66.     // get total distance and quadrent
  67.     FVect2 vDistance = { vPosA.x - vPosB.x + 0.000001f, vPosA.y - vPosB.y + 0.000001f };
  68.  
  69.     // get trig stats
  70.     vTrig.hypotenuse    = CAimbot.VectToHypot( vDistance ) + 0.000001f;
  71.     vTrig.radian        = acosf( ( vDistance.y ) / vTrig.hypotenuse );
  72.  
  73.     // offset based on quadrent
  74.     if( vDistance.x < 0 && vDistance.y < 0 || vDistance.x < 0 && vDistance.y > 0 ) // in quad 2 - 3
  75.         vTrig.radian    = ( PI - vTrig.radian );
  76.     else
  77.         vTrig.radian    = ( PI + vTrig.radian );
  78.  
  79.     // Ratio to offset by
  80.     vTrig.cosine = cosf( vTrig.radian );
  81.     vTrig.sine   = sinf( vTrig.radian );
  82.  
  83.    
  84.     // Rate that alpha should increase ( must be float or max line distance is 255 D: )
  85.     float   fRateY = 255 / abs( vTrig.hypotenuse ),
  86.             fAlpha = 0;
  87.  
  88.     // Set alpha to 0
  89.     pColor->a = 0;
  90.  
  91.     // Start second line from first line
  92.     D3DXVECTOR2 vPosC = vPosA;
  93.  
  94.     // Draw Underlying Line
  95.     CDraw.Line( vPosA.x, vPosA.y, vPosB.x, vPosB.y, dwWidth, coA );
  96.  
  97.     // Draw overlying line with increasing alpha channel
  98.     for( float i = 0; i < vTrig.hypotenuse; i++ )
  99.     {
  100.         // Draw line from position to second position
  101.         CDraw.Line( vPosC.x, vPosC.y, vPosC.x + vTrig.sine, vPosC.y + vTrig.cosine, dwWidth, coB );
  102.  
  103.         // Offset by ratio
  104.         vPosC.x += vTrig.sine;
  105.         vPosC.y += vTrig.cosine;
  106.  
  107.         // Increase alpha
  108.         if( fAlpha + fRateY < 255.0000f )
  109.             fAlpha += fRateY;
  110.  
  111.         // set alpha
  112.         pColor->a = fAlpha;
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement