home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / polygon / polyctl.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  1KB  |  47 lines

  1. // PolyCtl.cpp : Implementation of CPolyCtl
  2.  
  3. #include "stdafx.h"
  4. #include "Polygon.h"
  5. #include "PolyCtl.h"
  6.  
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CPolyCtl
  9.  
  10.  
  11. STDMETHODIMP CPolyCtl::get_Sides(short *pVal)
  12. {
  13.     *pVal = m_nSides;
  14.     return S_OK;
  15. }
  16.  
  17. STDMETHODIMP CPolyCtl::put_Sides(short newVal)
  18. {
  19.     if (newVal > 2 && newVal < 101)
  20.     {
  21.         m_nSides = newVal;
  22.         FireViewChange();
  23.         return S_OK;
  24.     }
  25.     else
  26.         return Error(_T("Shape must have between 3 and 100 sides"));
  27. }
  28.  
  29. void CPolyCtl::CalcPoints(const RECT& rc)
  30. {
  31.     const double pi = 3.14159265358979;
  32.     POINT   ptCenter;   double  dblRadiusx = (rc.right - rc.left) / 2;
  33.     double  dblRadiusy = (rc.bottom - rc.top) / 2;
  34.     double  dblAngle = 3 * pi / 2;          // Start at the top
  35.     double  dblDiff  = 2 * pi / m_nSides;   // Angle each side will make
  36.     ptCenter.x = (rc.left + rc.right) / 2;
  37.     ptCenter.y = (rc.top + rc.bottom) / 2;
  38.  
  39.     // Calculate the points for each side
  40.     for (int i = 0; i < m_nSides; i++)
  41.         {
  42.         m_arrPoint[i].x = (long)(dblRadiusx * cos(dblAngle) + ptCenter.x + 0.5);
  43.         m_arrPoint[i].y = (long)(dblRadiusy * sin(dblAngle) + ptCenter.y + 0.5);
  44.         dblAngle += dblDiff;
  45.         }
  46.     }
  47.