OpenGL鼠标旋转代码
2011-06-21 08:46
337 查看
void COpenGLView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch (nChar)
{
case VK_UP: m_yPos = m_yPos + 0.1f;
break;
case VK_DOWN: m_yPos = m_yPos - 0.1f;
break;
case VK_LEFT: m_xPos = m_xPos - 0.1f;
break;
case VK_RIGHT: m_xPos = m_xPos + 0.1f;
break;
default: MessageBox("Press the arrow keys only");
break;
}
InvalidateRect(NULL,FALSE);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void COpenGLView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MouseDownPoint=point;
SetCapture();
CView::OnLButtonDown(nFlags, point);
}
void COpenGLView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MouseDownPoint=CPoint(0,0);
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}
void COpenGLView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// Check if we have captured the mouse
if (GetCapture()==this)
{
//Increment the object rotation angles
m_xAngle+=(point.y-m_MouseDownPoint.y)/3.6;
m_yAngle+=(point.x-m_MouseDownPoint.x)/3.6;
//Redraw the view
InvalidateRect(NULL,FALSE);
//Set the mouse point
m_MouseDownPoint=point;
};
CView::OnMouseMove(nFlags, point);
}
然后在glRatate(m_xAngle...);方法中设置旋转即可
{
// TODO: Add your message handler code here and/or call default
switch (nChar)
{
case VK_UP: m_yPos = m_yPos + 0.1f;
break;
case VK_DOWN: m_yPos = m_yPos - 0.1f;
break;
case VK_LEFT: m_xPos = m_xPos - 0.1f;
break;
case VK_RIGHT: m_xPos = m_xPos + 0.1f;
break;
default: MessageBox("Press the arrow keys only");
break;
}
InvalidateRect(NULL,FALSE);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void COpenGLView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MouseDownPoint=point;
SetCapture();
CView::OnLButtonDown(nFlags, point);
}
void COpenGLView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_MouseDownPoint=CPoint(0,0);
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}
void COpenGLView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// Check if we have captured the mouse
if (GetCapture()==this)
{
//Increment the object rotation angles
m_xAngle+=(point.y-m_MouseDownPoint.y)/3.6;
m_yAngle+=(point.x-m_MouseDownPoint.x)/3.6;
//Redraw the view
InvalidateRect(NULL,FALSE);
//Set the mouse point
m_MouseDownPoint=point;
};
CView::OnMouseMove(nFlags, point);
}
然后在glRatate(m_xAngle...);方法中设置旋转即可
相关文章推荐
- touch.js 拖动、缩放、旋转 (鼠标手势)功能代码
- 20行html代码加40行css代码实现照片墙页面(鼠标hover实现旋转缩放)
- vc6.0 中用OpenGL绘图后用鼠标实现旋转
- opengl笔记——旋转,一段代码的理解
- OpenGL 鼠标3D旋转简单实现
- OpenGL之鼠标控制坐标系旋转、缩放、移动
- 鼠标放上去Div旋转特效代码
- OpenGL3D图形、旋转、纹理、键盘移动、光照、滤波、透明(完整) 复制代码
- 代码: CSS3动画,简单示例(鼠标移上去后,背景图片旋转)
- openGL程序示例代码——旋转的玉石
- 鼠标放上去Div旋转特效代码
- 基础代码--通过鼠标的左右滑动来实现摄像机在Y轴上视野旋转
- OpenGL学习-2-鼠标事件响应练习工程代码(排错补档)
- OpenGL鼠标旋转图像
- opengl 鼠标3D旋转简单实现
- 为OpenGL考试而准备的代码——鼠标控制视角变换+简单纹理映射+键盘的光照控制+Bezier曲线
- OpenGL鼠标旋转物体
- 鼠标悬停,图片旋转360°特效代码
- OpenGL实现3D模型自由旋转——之代码解析
- 看opengl写代码(3) 实现矩阵的旋转