3DHelperDemoSimpleDlg.cpp
上传用户:qzpk666
上传日期:2022-08-04
资源大小:59k
文件大小:5k
- // 3DHelperDemoSimpleDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "3DHelperDemoSimple.h"
- #include "3DHelperDemoSimpleDlg.h"
- #include "MemDC.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMy3DHelperDemoSimpleDlg dialog
- CMy3DHelperDemoSimpleDlg::CMy3DHelperDemoSimpleDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMy3DHelperDemoSimpleDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMy3DHelperDemoSimpleDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CMy3DHelperDemoSimpleDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMy3DHelperDemoSimpleDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMy3DHelperDemoSimpleDlg, CDialog)
- //{{AFX_MSG_MAP(CMy3DHelperDemoSimpleDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMy3DHelperDemoSimpleDlg message handlers
- BOOL CMy3DHelperDemoSimpleDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- SetIcon(m_hIcon, TRUE);
- SetIcon(m_hIcon, FALSE);
- // Initialize the 3D system
- initialize();
- return TRUE;
- }
- void CMy3DHelperDemoSimpleDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- void CMy3DHelperDemoSimpleDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- HCURSOR CMy3DHelperDemoSimpleDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMy3DHelperDemoSimpleDlg::OnTimer(UINT nIDEvent)
- {
- // Timer is used to refresh trackball information
- if(nIDEvent == 1) {
- KillTimer(nIDEvent);
- m_c3DHelper.UpdateTrackBall(GetDlgItem(IDC_STATIC_PLACEHOLDER)->GetDC());
- redraw();
- SetTimer(1, 25, NULL);
- }
- CDialog::OnTimer(nIDEvent);
- }
- void CMy3DHelperDemoSimpleDlg::redraw()
- {
- // Create off-screen dc (prevents flickering)
- CRect rcDraw;
- CWnd *pTarget = GetDlgItem(IDC_STATIC_PLACEHOLDER);
- pTarget->GetClientRect(rcDraw);
- // Create the offscreen dc
- CDC *pTDC = pTarget->GetDC();
- CMemDC cDC(pTDC, &rcDraw);
- CDC *pDC = (CDC*)cDC;
- // Clean up the screen an draw a hint
- pDC->FillSolidRect(rcDraw.left, rcDraw.top, rcDraw.Width(),rcDraw.Height(), RGB(0,0,0));
- pDC->SetTextColor(RGB(255,255,0));
- pDC->SetBkMode(OPAQUE);
- pDC->TextOut(1,1, _T("Drag mouse to rotate..."));
- // Calculate screen coordinates of point <1,1,1>
- NeHe::Vector cIn (1.0f, 1.0f, 1.0f);
- NeHe::Vector cOut = m_c3DHelper.RenderPoint(cIn);
- // And display this information
- pDC->SetTextColor(RGB(255,255,255));
- pDC->SetBkMode(OPAQUE);
- pDC->TextOut((int)cOut.x, (int)cOut.y, _T("* <1, 1, 1>"));
- // Ease relative position recognition
- m_c3DHelper.DrawVisibilityCube(pDC);
- // cDC will be automatically destruced
- }
- // Set up initial 3D system
- void CMy3DHelperDemoSimpleDlg::initialize()
- {
- CWnd *pTarget = GetDlgItem(IDC_STATIC_PLACEHOLDER);
- m_c3DHelper.Initialize(pTarget->GetDC(), NeHe::Vector(-2.0f, -2.0f, -2.0f), NeHe::Vector(2.0f,2.0f,2.0f), TRUE);
- // Timer used to refresh "trackball" information
- SetTimer(1, 25, NULL);
- }