XProject.cpp
上传用户:wangdan
上传日期:2022-06-30
资源大小:739k
文件大小:3k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. // XProject.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Test1.h"
  5. #include "XProject.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CXProject
  14. extern GLfloat Databuf[ArrayOne][ArrayTwo];
  15. extern bool gbIsGetData;
  16. extern bool   gbDataIsEmpty;
  17. IMPLEMENT_DYNCREATE(CXProject, CView)
  18. CXProject::CXProject()
  19. {
  20. }
  21. CXProject::~CXProject()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CXProject, CView)
  25. //{{AFX_MSG_MAP(CXProject)
  26. ON_WM_ERASEBKGND()
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CXProject drawing
  31. void CXProject::OnDraw(CDC* pDC)
  32. {
  33. CDocument* pDoc = GetDocument();
  34. CRect rc;
  35. GetClientRect(&rc);
  36. pDC->SetTextAlign(TA_CENTER);
  37. pDC->SetTextColor(YELLOW);
  38. pDC->SetBkMode(1);
  39. CFont *OldFont = pDC->SelectObject(&this->m_pFr->m_13Font);
  40. CPen *pen = new CPen(PS_SOLID,1,GREEN);
  41. CPen *pOldPen = pDC->SelectObject(pen);
  42. pDC->TextOut(rc.right/2,2,"X轴投影-声波");
  43. this->DrawXCoordinate(pDC);
  44. this->XProjection(pDC);
  45. pDC->SelectObject(pOldPen);
  46. pDC->SelectObject(OldFont);
  47. delete pen;
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CXProject diagnostics
  51. #ifdef _DEBUG
  52. void CXProject::AssertValid() const
  53. {
  54. CView::AssertValid();
  55. }
  56. void CXProject::Dump(CDumpContext& dc) const
  57. {
  58. CView::Dump(dc);
  59. }
  60. #endif //_DEBUG
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CXProject message handlers
  63. BOOL CXProject::OnEraseBkgnd(CDC* pDC) 
  64. {
  65. CBrush Brush (BLACK); 
  66.     CBrush* pOldBrush = pDC->SelectObject(&Brush);     
  67. CRect ViewClip; 
  68. pDC->GetClipBox(&ViewClip);     
  69. pDC->PatBlt(ViewClip.left,ViewClip.top,ViewClip.Width(),ViewClip.Height(),PATCOPY);    
  70. pDC->SelectObject (pOldBrush );
  71. return TRUE;
  72. }
  73. void CXProject::OnInitialUpdate() 
  74. {
  75. CView::OnInitialUpdate();
  76. this->m_pFr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  77. }
  78. void CXProject::DrawXCoordinate(CDC *pDC)
  79. {
  80. CRect rc;
  81. this->GetClientRect(&rc);
  82. pDC->SetTextAlign(TA_LEFT);
  83. pDC->TextOut(2,rc.bottom-15,"0");
  84. pDC->TextOut(rc.right-30,rc.bottom-25,"中子");
  85. pDC->TextOut(0,10,"密度");
  86. //x轴
  87. pDC->MoveTo(10,rc.bottom-20);
  88. pDC->LineTo(rc.right-30,rc.bottom-20);
  89. pDC->MoveTo(rc.right-30,rc.bottom-20);
  90. pDC->LineTo(rc.right-30-5,rc.bottom-20-5);
  91. pDC->MoveTo(rc.right-30,rc.bottom-20);
  92. pDC->LineTo(rc.right-30-5,rc.bottom-20+5);
  93. //y轴
  94. pDC->MoveTo(10,rc.bottom-20);
  95. pDC->LineTo(10,25);
  96. pDC->MoveTo(10,25);
  97. pDC->LineTo(5,30);
  98. pDC->MoveTo(10,25);
  99. pDC->LineTo(15,30);
  100. }
  101. void CXProject::XProjection(CDC *pDC)
  102. {
  103. if (::gbIsGetData)
  104. return;
  105. if (::gbDataIsEmpty)
  106. return;
  107. CRect rc;
  108. this->GetClientRect(&rc);
  109. for (int i=0; i<ArrayOne; i++)
  110. {
  111. if ((GLfloat)Databuf[i][0] >= this->m_pFr->m_pView->m_nMinDepth 
  112. && (GLfloat)Databuf[i][0] <= this->m_pFr->m_pView->m_nMaxDepth )
  113. {
  114. pDC->SetPixel(Databuf[i][this->m_pFr->m_pView->m_Second]*4+10,
  115. (rc.bottom-20) - (Databuf[i][this->m_pFr->m_pView->m_Third]*80-90),GREEN);
  116. }
  117. }
  118. }