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

3D图形编程

开发平台:

Visual C++

  1. // YProject.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Test1.h"
  5. #include "YProject.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. // CYProject
  14. extern GLfloat Databuf[ArrayOne][ArrayTwo];
  15. extern bool gbIsGetData;
  16. extern bool   gbDataIsEmpty;
  17. IMPLEMENT_DYNCREATE(CYProject, CView)
  18. CYProject::CYProject()
  19. {
  20. }
  21. CYProject::~CYProject()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CYProject, CView)
  25. //{{AFX_MSG_MAP(CYProject)
  26. ON_WM_ERASEBKGND()
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CYProject drawing
  31. void CYProject::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,"Y轴投影-中子");
  43. this->DrawYCoordinate(pDC);
  44. this->YProjection(pDC);
  45. pDC->SelectObject(pOldPen);
  46. pDC->SelectObject(OldFont);
  47. delete pen;
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CYProject diagnostics
  51. #ifdef _DEBUG
  52. void CYProject::AssertValid() const
  53. {
  54. CView::AssertValid();
  55. }
  56. void CYProject::Dump(CDumpContext& dc) const
  57. {
  58. CView::Dump(dc);
  59. }
  60. #endif //_DEBUG
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CYProject message handlers
  63. BOOL CYProject::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 CYProject::OnInitialUpdate() 
  74. {
  75. CView::OnInitialUpdate();
  76. this->m_pFr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  77. }
  78. void CYProject::DrawYCoordinate(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 CYProject::YProjection(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_First]/3-30,
  115. (rc.bottom-20)-(Databuf[i][this->m_pFr->m_pView->m_Third]*80-100),RED);
  116. }
  117. }
  118. }