transmode.cpp
来自「计算机图形学实验设计 计算机图形学实验设计」· C++ 代码 · 共 145 行
CPP
145 行
// TransMode.cpp : implementation file
//
#include "stdafx.h"
#include "cgDemo.h"
#include "TransMode.h"
#include "math.h"
#include "cgDemoDoc.h"
#include "TransMatrix.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTransMode
IMPLEMENT_DYNCREATE(CTransMode, CFormView)
CTransMode::CTransMode()
: CFormView(CTransMode::IDD)
{
//{{AFX_DATA_INIT(CTransMode)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_transMode = 0;
m_transMatrixp = new CTransMatrix();
}
CTransMode::~CTransMode()
{
}
void CTransMode::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTransMode)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTransMode, CFormView)
//{{AFX_MSG_MAP(CTransMode)
ON_BN_CLICKED(IDC_XLEFT, OnXleft)
ON_BN_CLICKED(IDC_XRIght, OnXRIght)
ON_BN_CLICKED(IDC_YUP, OnYup)
ON_BN_CLICKED(IDC_YDOWN, OnYdown)
ON_BN_CLICKED(IDC_TRANSMODE, OnTransmode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTransMode diagnostics
#ifdef _DEBUG
void CTransMode::AssertValid() const
{
CFormView::AssertValid();
}
void CTransMode::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTransMode message handlers
void CTransMode::OnXleft()
{
// TODO: Add your control notification handler code here
CCgDemoDoc* pDoc = (CCgDemoDoc *)GetDocument();
switch (m_transMode) {
case 0:
m_transMatrixp->Translate2Dmatrix(-10, 0, pDoc->m_transMatrix);
break;
case 1:
m_transMatrixp->Rotate2Dmatrix(sin(5*3.14/180),
cos(5*3.14/180), pDoc->m_transMatrix);
break;
}
pDoc->UpdateAllViews(this);
}
void CTransMode::OnXRIght()
{
// TODO: Add your control notification handler code here
CCgDemoDoc* pDoc = (CCgDemoDoc *)GetDocument();
switch (m_transMode) {
case 0:
m_transMatrixp->Translate2Dmatrix(10, 0, pDoc->m_transMatrix);
break;
case 1:
m_transMatrixp->Rotate2Dmatrix(-sin(5*3.14/180),
cos(5*3.14/180), pDoc->m_transMatrix);
break;
}
pDoc->UpdateAllViews(this);
}
void CTransMode::OnYup()
{
// TODO: Add your control notification handler code here
CCgDemoDoc* pDoc = (CCgDemoDoc *)GetDocument();
m_transMatrixp->Translate2Dmatrix(0, 10, pDoc->m_transMatrix);
pDoc->UpdateAllViews(this);
}
void CTransMode::OnYdown()
{
// TODO: Add your control notification handler code here
CCgDemoDoc* pDoc = (CCgDemoDoc *)GetDocument();
m_transMatrixp->Translate2Dmatrix(0, -10, pDoc->m_transMatrix);
pDoc->UpdateAllViews(this);
}
void CTransMode::OnTransmode()
{
// TODO: Add your control notification handler code here
char text[10];
CButton *transMode = (CButton *)GetDlgItem(IDC_TRANSMODE);
transMode->GetWindowText(text, 10);
text[transMode->GetWindowTextLength()] = '\0';// End character
if(strcmp(text, "Move") == 0) //If it's "Move",change to "Rotate"
{
transMode->SetWindowText("Rotate");
m_transMode = 1;
}
else
{
transMode->SetWindowText("Move");
m_transMode = 0;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?