Основные навыки работы с MFC, страница 3

}

void CMainWnd::OnMenuOptions()

{

COptDlg* ppc;

ppc= new COptDlg(z);

/*

ppc->Create(IDD_OPTIONS, this);

ppc->ShowWindow(SW_SHOW);

*/

if (ppc->DoModal()==IDOK)

      {

      z=ppc->q;

      Invalidate();

      }

delete(ppc);

}

double CMainWnd::myasl (double x)

{

      return x>0?x:(-x);

}

double CMainWnd::fi2(double m)

{

      double q=0;

      CString s;

      switch (z.S0)

      {

      case 0 : q=z.B0+z.A0*m; break;

      case 1 : q=z.B0+z.A0*m+z.A11*myasl(m-z.A11);break;

      case 2 : q=z.B0+z.A0*m+z.A11*myasl(m-z.A11)+z.A12*myasl(m-z.A12);break;

      case 3 : q=z.B0+z.A0*m+z.A11*myasl(m-z.A11)+z.A12*myasl(m-z.A12)+z.A13*myasl(m-z.A13);break;

      case 4 : q=z.B0+z.A0*m+z.A11*myasl(m-z.A11)+z.A12*myasl(m-z.A12)+z.A13*myasl(m-z.A13)+z.A14*myasl(m-z.A14);break;

      };

      switch (z.S1)

      {

      case 0 : q=q; break;

      case 1 : q=q+z.B1*myasl(m-z.A21)/(m-z.A21);break;

      case 2 : q=q+z.B1*myasl(m-z.A21)/(m-z.A21)+z.B2*myasl(m-z.A22)/(m-z.A22);break;

      case 3 : q=q+z.B1*myasl(m-z.A21)/(m-z.A21)+z.B2*myasl(m-z.A22)/(m-z.A22)+z.B3*myasl(m-z.A23)/(m-z.A23);break;

      case 4 : q=q+z.B1*myasl(m-z.A21)/(m-z.A21)+z.B2*myasl(m-z.A22)/(m-z.A22)+z.B3*myasl(m-z.A23)/(m-z.A23)+z.B4*myasl(m-z.A24)/(m-z.A24);break;

      };

//    s.Format("fi2=%4.3f",q);

//    MessageBox(s);

      return q;

}

double CMainWnd::fi3(double m)

{

      return myasl(z.AM+m)/2-myasl(z.AM-m)/2;

}

void CMainWnd::drawit (void)

{

int maxx, maxy,m=0,n=0,k=0;

double *pprev, *pcurr;

CRect CR;

COLORREF CLR;

CPen *pen;

CString s; 

GetClientRect(&CR);

maxx=CR.Width();//Get max coordinates

maxy=CR.Height();

CPaintDC dc(this);//Initalize current window

//Grid

dc.MoveTo(maxx/2, maxy/2);

dc.LineTo(maxx/2, 0);

dc.MoveTo(maxx/2, maxy/2);

dc.LineTo(maxx, maxy/2+maxx/2/tan(3.14/3));

dc.MoveTo(maxx/2, maxy/2);

dc.LineTo(0, maxy/2+maxx/2/tan(3.14/3));

//Drawing Function

pprev=new double[maxx/2+1];

pcurr=new double[maxx/2+1];

for(n=0;n<maxx/2;n++)

      {

      *(pcurr+n)=z.U0K*n+z.U0B;

      }

for (n=0;n<maxx/2;n++)

      {

      for(m=0;m<maxx/2;m++) *(pprev+m)=*(pcurr+m);

      for (m=0;m<maxx/2;m++)

            {

            //if (n!=0) *(pcurr+m)=*(pprev+m)-z.TAU/z.HM/z.HM*(fi2(fi3(*(pprev+m+1))))-fi2(2*fi3(*(pprev+m)))+fi2(fi3(m>0?*(pprev+m-1):*(pprev+m)));

            if (n!=0) *(pcurr+m)=sqrt(300*300-m*m-n*n);

            //s.Format("pcurr=%4.3f",*(pcurr+m));

            //if (m==200) MessageBox(s);

            if (*(pcurr+m)!=*(pprev+m)) k++;

            if (*(pcurr+m)>0 && *(pcurr+m)<240/4) CLR=RGB(0,0,0+k);

            if (*(pcurr+m)>240/4 && *(pcurr+m)<480/4) CLR=RGB(0,k-240,240);

            if (*(pcurr+m)>480/4 && *(pcurr+m)<720/4) CLR=RGB(0,240,240-k-480);

            if (*(pcurr+m)>720/4 && *(pcurr+m)<960/4) CLR=RGB(k-720,240,0);

            if (*(pcurr+m)>960/4 && *(pcurr+m)<1200/4) CLR=RGB(240,240-k-960,0);

            dc.SetPixelV(maxx/2+n*cos(3.14/6)-m*cos(3.14/6),maxy/2+m*sin(3.14/6)+n*sin(3.14/6)-*(pcurr+m),CLR);

            }

      }

delete(pprev);

delete(pcurr);

}

void CMainWnd::OnPaint()

{

drawit ();

}

DlgWnd.h