OpenGL programming based on MFC Part 6 keyboard and Mouse control

Source: Internet
Author: User

Add an event handler for the keyboard and mouse, based on the previous article, to control the rotation and movement of 3D objects.

1, the event handler is added first in the Ccy457openglview class for Wm_keydown, Wm_lbuttondown, Wm_lbuttonup, and wm_mousemove four events.

2, add the following variables for controlling rotation and movement in CCY457OpenGLView.h:

GLfloat m_xAngle;
GLfloat m_yAngle;
GLfloat m_xPos;
GLfloat m_yPos;
CPoint m_MouseDownPoint;

and initialize it in the constructor:

CCY457OpenGLView::CCY457OpenGLView()
{
  m_xPos = 0.0f;
  m_yPos = 0.0f;
  m_xAngle = 0.0f;
  m_yAngle = 0.0f;
}

3, add the drawing code:

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.