home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / Affine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  2.9 KB  |  96 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : affine.h                                                             //
  12. //  Description: Affine transformation                                               //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. // eM11 eM12
  17. // eM21 eM22
  18. // eDx  eDy
  19. // x' =    m11 * x + m21 * y + dx
  20. // y' = m12 * x + m22 * y + dy
  21.  
  22. class KAffine
  23. {
  24. public:
  25.     XFORM m_xm;
  26.  
  27.     KAffine()
  28.     {
  29.         Reset();
  30.     }
  31.  
  32.     void Map(int x, int y, float & rx, float & ry)
  33.     {
  34.         rx = m_xm.eM11 * x + m_xm.eM21 * y + m_xm.eDx;
  35.         ry = m_xm.eM12 * x + m_xm.eM22 * y + m_xm.eDy;
  36.     }
  37.     
  38.     void Reset();
  39.     BOOL SetTransform(const XFORM & xm);
  40.     BOOL Combine(const XFORM & b);
  41.     BOOL Invert(void);
  42.  
  43.     BOOL Translate(FLOAT dx, FLOAT dy);
  44.     BOOL Scale(FLOAT sx, FLOAT dy);
  45.     BOOL Rotate(FLOAT angle, FLOAT x0=0, FLOAT y0=0);
  46.  
  47.     BOOL MapTri(FLOAT px0, FLOAT py0, FLOAT qx0, FLOAT qy0, FLOAT rx0, FLOAT ry0);
  48.  
  49.     BOOL MapTri(FLOAT px0, FLOAT py0, FLOAT qx0, FLOAT qy0, FLOAT rx0, FLOAT ry0,
  50.                 FLOAT px1, FLOAT py1, FLOAT qx1, FLOAT qy1, FLOAT rx1, FLOAT ry1);
  51.  
  52.     BOOL MapTriInt(int px0, int py0, int qx0, int qy0, int rx0, int ry0,
  53.                 int px1, int py1, int qx1, int qy1, int rx1, int ry1)
  54.     {
  55.         return MapTri((float) px0, (float) py0, (float) qx0, (float) qy0, (float) rx0, (float) ry0,
  56.                       (float) px1, (float) py1, (float) qx1, (float) qy1, (float) rx1, (float) ry1);
  57.     }
  58.  
  59.     BOOL GetDPtoLP(HDC hDC);
  60. };
  61.  
  62.  
  63. void minmax(int x0, int x1, int x2, int x3, int & minx, int & maxx);
  64.  
  65. class KReverseAffine : public KAffine
  66. {
  67.     int x0, y0, x1, y1, x2, y2;
  68.  
  69. public:
  70.     int minx, maxx, miny, maxy;
  71.  
  72.     KReverseAffine(const POINT * pPoint)
  73.     {
  74.         x0 = pPoint[0].x;    //   P0       P1
  75.         y0 = pPoint[0].y;    //
  76.         x1 = pPoint[1].x;    //
  77.         y1 = pPoint[1].y;    //   P2       P3
  78.         x2 = pPoint[2].x;
  79.         y2 = pPoint[2].y;
  80.     }
  81.  
  82.     bool Simple(void) const
  83.     {
  84.         return (y0==y1) && (x0==x2);
  85.     }
  86.  
  87.     void Setup(int nXSrc, int nYSrc, int nWidth, int nHeight)
  88.     {
  89.         MapTriInt(x0,    y0,      x1,           y1,    x2,    y2, 
  90.                     nXSrc, nYSrc, nXSrc+nWidth, nYSrc, nXSrc, nYSrc+nHeight);
  91.         
  92.         minmax(x0, x1, x2, x2 + x1 - x0, minx, maxx);
  93.         minmax(y0, y1, y2, y2 + y1 - y0, miny, maxy);
  94.     }
  95. };
  96.