double m_dCurSimTime;
double m_dCurAzimuth;
int m_nCurScanFrame;
int m_nCenterX;
int m_nCenterY;
int m_nRadius;
const double PI = 3.14159265358979;
const double d2r = PI/180.0;
const UINT TimeIntervalInMS = 100;
const double BeamWidth = 6.0*d2r;
const double ScanPeriod = 6.0;
const double ScanRate = 360.0/ScanPeriod*d2r;
const double MaxDetectRange = 500.0e3;
const int RANGERINGNUM = 10;
RECT rectTime,rectAzScan,rectFrame;
RECT rectRate,rectDotNum,rectEchoNum,rectTgtNum,rectSysTime;
RECT rectR,rectAz,rectID;
double Rand(double dblStart, double dblFinish)
{
double minVal = min(dblStart, dblFinish);
double maxVal = max(dblStart, dblFinish);
return (maxVal - minVal) * (double)rand() / (RAND_MAX + 1) + minVal;
}
BOOL CPPIDispDemoDlg::OnInitDialog()
{
……
SetTimer(0, TimeIntervalInMS, NULL);
}
void CPPIDispDemoDlg::OnPaint()
{
if (IsIconic())
{
……
}
else
{
CPaintDC dc(this);
CRect rect;
This->GetClientRect(&rect);
int nMargin = 1;
int nHeight = rect.Height() - 2*nMargin;
int nWidth = rect.Width() - 2*nMargin;
m_nCenterX = nWidth/2;
m_nCenterY = nHeight/2;
m_nRadius = min(nWidth,nHeight)/2;
CDC xDC;
CBitmap xBMP;
xDC.CreateCompatibleDC(&dc);
xBMP.CreateCompatibleBitmap(&dc,nWidth,nHeight);
xDC.SelectObject(xBMP);
OnDraw(&xDC);
CDC yDC;
CBitmap yBMP;
yDC.CreateCompatibleDC(&dc);
yBMP.CreateCompatibleBitmap(&dc,nWidth,nHeight);
yDC.SelectObject(&yBMP);
yDC.FillSolidRect(rect,GetSysColor(COLOR_3DFACE));
yDC.BitBlt(nMargin,nMargin,nWidth,nHeight,&xDC,0,0,SRCCOPY);
dc.BitBlt(0,0,nWidth,nHeight,&yDC,0,0,SRCCOPY);
xBMP.DeleteObject();
xDC.DeleteDC();
yBMP.DeleteObject();
yDC.DeleteDC();
}
}
void CPPIDispDemoDlg::OnDraw(CDC *pDC)
{
double deltaT = BeamWidth/255;
for(double dt = 0.0; dt < 1.0*BeamWidth; dt += deltaT)
{
long x = m_nCenterX + m_nRadius*cos(dt + m_dCurAzimuth-BeamWidth);
long y = m_nCenterY + m_nRadius*sin(dt + m_dCurAzimuth-BeamWidth);
pDC->MoveTo(m_nCenterX,m_nCenterY);
xPen.DeleteObject();
xPen.CreatePen(0,4,RGB(0,j++,0));
pDC->SelectObject(&xPen);
pDC->LineTo(x,y);
}
xPen.DeleteObject();
xPen.CreatePen(0,4,RGB(0,255,0));
pDC->SelectObject(&xPen);
pDC->MoveTo(m_nCenterX, m_nCenterY);
pDC->LineTo(m_nCenterX + m_nRadius*cos(m_dCurAzimuth),
m_nCenterY + m_nRadius*sin(m_dCurAzimuth));
xPen.DeleteObject();
int Rmt = int(Rand(10, m_nRadius));
double angleAZ = Rand(m_dCurAzimuth - 2*BeamWidth, m_dCurAzimuth - BeamWidth);
double Threshold = 0.65;
if (Rand(0.0,1.0) >= 1 - Threshold)
{
CPoint dot;
dot.x = m_nCenterX + Rmt*cos(angleAZ);
dot.y = m_nCenterY + Rmt*sin(angleAZ);
pDC->SetPixel(dot,RGB(255,0,0));
pDC->FillSolidRect(dot.x, dot.y, 4, 4, RGB(255,255,0));
}
CFont font;
font.CreateFont(12,6,0,0,600,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_ROMAN,"宋体");
CString str("");
for (i = 0; i < RANGERINGNUM-1; i++)
{
xPen.CreatePen(PS_SOLID,1,RGB(128,118,105));
pDC->SelectObject(&xPen);
pDC->Arc(m_nCenterX - m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterY - m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterX + m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterY + m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,0,0,0,0);
xPen.DeleteObject();
if (i % 2 == 1)
{
pDC->SelectObject(&font);
pDC->SetTextColor(RGB(160,160,164));
pDC->SetBkMode(TRANSPARENT);
str.Format("%d",int((RANGERINGNUM-i)*MaxDetectRange/1.0e3/RANGERINGNUM));
pDC->TextOut(m_nCenterX + m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterY, str);
}
}
xPen.CreatePen(PS_SOLID,1,RGB(128,118,105));
pDC->SelectObject(&xPen);
pDC->MoveTo(m_nCenterX - m_nRadius, m_nCenterY);
pDC->LineTo(m_nCenterX + m_nRadius, m_nCenterY);
pDC->MoveTo(m_nCenterX, m_nCenterY - m_nRadius);
pDC->LineTo(m_nCenterX, m_nCenterY + m_nRadius);
double dTheta = 30.0*d2r;
pDC->MoveTo(m_nCenterX - cos(dTheta)*m_nRadius, m_nCenterY + sin(dTheta)*m_nRadius);
pDC->LineTo(m_nCenterX + cos(dTheta)*m_nRadius, m_nCenterY - sin(dTheta)*m_nRadius);
pDC->MoveTo(m_nCenterX - cos(dTheta)*m_nRadius, m_nCenterY - sin(dTheta)*m_nRadius);
pDC->LineTo(m_nCenterX + cos(dTheta)*m_nRadius, m_nCenterY + sin(dTheta)*m_nRadius);
dTheta = 60.0*d2r;
pDC->MoveTo(m_nCenterX - cos(dTheta)*m_nRadius, m_nCenterY + sin(dTheta)*m_nRadius);
pDC->LineTo(m_nCenterX + cos(dTheta)*m_nRadius, m_nCenterY - sin(dTheta)*m_nRadius);
pDC->MoveTo(m_nCenterX - cos(dTheta)*m_nRadius, m_nCenterY - sin(dTheta)*m_nRadius);
pDC->LineTo(m_nCenterX + cos(dTheta)*m_nRadius, m_nCenterY + sin(dTheta)*m_nRadius);
xPen.DeleteObject();
xPen.CreatePen(PS_SOLID,2,RGB(255,0,0));
pDC->SelectObject(&xPen);
i = RANGERINGNUM-1;
pDC->Arc(m_nCenterX - m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterY - m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterX + m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,
m_nCenterY + m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM,0,0,0,0);
xPen.DeleteObject();
pDC->SelectObject(&font);
pDC->SetTextColor(RGB(160,160,164));
pDC->SetBkMode(TRANSPARENT);
str.Format("%d",int((RANGERINGNUM-i)*MaxDetectRange/1.0e3/RANGERINGNUM)); /单位km
pDC->TextOut(m_nCenterX + m_nRadius*(RANGERINGNUM-i)/RANGERINGNUM, m_nCenterY, str);
str.Format("当前时间(s):%6.3f", m_dCurSimTime);
rectTime.left = 5;
rectTime.top = 5;
rectTime.right = rectTime.left + strlen(str) * 7;
rectTime.bottom = rectTime.top + 12;
pDC->DrawText(str,&rectTime,DT_LEFT);
……
font.DeleteObject();
pDC->SelectObject(oPen);
}
void CPPIDispDemoDlg::OnTimer(UINT_PTR nIDEvent)
{
m_dCurAzimuth += BeamWidth;
m_dCurSimTime += 1.0e-3*TimeIntervalInMS;
if(m_dCurAzimuth > 2*PI)
{
m_dCurAzimuth -= 2*PI;
m_nCurScanFrame++;
}
InvalidateRect(&rectTime);
InvalidateRect(&rectAzScan);
InvalidateRect(&rectFrame);
InvalidateRect(&rectDotNum);
InvalidateRect(&rectEchoNum);
InvalidateRect(&rectTgtNum);
InvalidateRect(&rectSysTime);
InvalidateRect(&rectRate);
InvalidateRect(&rectID);
InvalidateRect(&rectR);
InvalidateRect(&rectAz);
CDC dc;
dc.CreateCompatibleDC(&dc);
dc.SetViewportOrg(m_nCenterX,m_nCenterY);
CPoint topleft,bottomright;
topleft.x = -m_nRadius ;
topleft.y = -m_nRadius;
bottomright.x = m_nRadius ;
bottomright.y = m_nRadius ;
CRgn rgn;
CRect rect(topleft,bottomright);
CPoint pt1, pt2;
pt1.x = m_nRadius*cos(m_dCurAzimuth);
pt1.y = m_nRadius*sin(m_dCurAzimuth);
pt2.x = m_nRadius*cos(m_dCurAzimuth - 2*BeamWidth);
pt2.y = m_nRadius*sin(m_dCurAzimuth - 2*BeamWidth);
dc.BeginPath();
dc.MoveTo(CPoint(0,0));
dc.LineTo(pt1);
dc.ArcTo(rect,pt1,pt2);
dc.LineTo(CPoint(0,0));
dc.EndPath();
rgn.CreateFromPath(&dc);
InvalidateRgn(&rgn,TRUE);
rgn.DeleteObject();
dc.DeleteDC();
CDialog::OnTimer(nIDEvent);
}
void CPPIDispDemoDlg::OnClose()
{
KillTimer(0);
……
}