首页 / 软件开发 / VC.NET / 《基于MFC的OpenGL编程》Part 6 Keyboard and Mouse Control
《基于MFC的OpenGL编程》Part 6 Keyboard and Mouse Control2010-05-02 博客园 Phinecos(洞庭散人)在上一篇的基础上加入对键盘和鼠标的事件处理程序,以便用其来控制3D物体的旋转和移动。1,首先在CCY457OpenGLView类中为WM_KEYDOWN, WM_LBUTTONDOWN, WM_LBUTTONUP 和 WM_MOUSEMOVE四个事件加入事件处理函数。2,在CCY457OpenGLView.h中加入下列用于控制旋转和移动的变量:GLfloat m_xAngle;
GLfloat m_yAngle;
GLfloat m_xPos;
GLfloat m_yPos;
CPoint m_MouseDownPoint;
并在构造函数中初始化:CCY457OpenGLView::CCY457OpenGLView()
{
m_xPos = 0.0f;
m_yPos = 0.0f;
m_xAngle = 0.0f;
m_yAngle = 0.0f;
}
3,加入绘制代码:void COpenGLView::RenderScene ()
{
glLoadIdentity();
glTranslatef(m_xPos, m_yPos, -5.0f);
glRotatef(m_xAngle, 1.0f,0.0f,0.0f);
glRotatef(m_yAngle, 0.0f,1.0f,0.0f);
glutWireCube(1.0f);
}