
使用OPENGL控制鼠标和键盘移动3D物体。
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
The OpenGL implementation allows for the movement of 3D objects using mouse and keyboard controls. The function `CCY457OpenGLView::OnKeyDown` handles key presses, specifically updating the object’s position based on the pressed keys: upward movement increases the y-coordinate (`m_yPos`), downward movement decreases it, leftward movement reduces the x-coordinate (`m_xPos`), and rightward movement increases it. If any other key is pressed, a message box alerts the user to utilize the arrow keys. Following each key press, the view is refreshed using `InvalidateRect`, and the default `OnKeyDown` message handler is called.
The function `CCY457OpenGLView::OnLButtonDown` registers the mouse position when the left mouse button is initially pressed, storing it in `m_MouseDownPoint`, acquires capture to ensure exclusive mouse control, and then calls the default `OnLButtonDown` handler. The function `CCY457OpenGLView::OnLButtonUp` releases mouse capture when the left mouse button is released, resetting `m_MouseDownPoint` to a default value and subsequently calling the default `OnLButtonUp` handler.
Finally, the function `CCY457OpenGLView::OnMouseMove` detects mouse movements while the mouse button is held down. If this view currently has mouse capture, it calculates changes in rotation angles based on the difference between the current mouse position (`point`) and previously captured position (`m_MouseDownPoint`), divided by 3.6 to scale these changes. The view is then redrawn via `InvalidateRect`, and the current mouse position is updated to be stored in `m_MouseDownPoint`. The default `OnMouseMove` message handler is also invoked.
全部评论 (0)


