MFC opengl 鼠标旋转、平移、缩放

manji_lee 2013-10-07 10:54:57
void CDrawCubeDemoView::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 CDrawCubeDemoView::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 CDrawCubeDemoView::OnMouseMove(UINT nFlags, CPoint point)
{

// TODO: Add your message handler code here and/or call default

//if (GetCapture()==this)
if (nFlags & MK_LBUTTON == TRUE)
{
//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;


}
}

但是上述简单的代码,旋转效果很差,难以控制,有人用跟踪球做过opengl的旋转平移吗?求大牛指导!!
...全文
539 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly_dragon_fly 2015-03-12
  • 打赏
  • 举报
回复
没看到你怎么使用opengl的,效果差具体是什么? 旋转的nehe的代码可以直接拷过来用,只不过超过窗口边界得注意一下 对于平移来说,只是把鼠标点的偏移值算回到世界坐标的偏移就可以了
manji_lee 2015-03-12
  • 打赏
  • 举报
回复
轨迹球 track ball
赵4老师 2015-03-12
  • 打赏
  • 举报
回复
搜网络教程“学OpenGL编3D游戏”。
就不交话费 2015-03-12
  • 打赏
  • 举报
回复
请问楼主最后如何实现鼠标左键平移效果的啊?
ryfdizuo 2013-10-07
  • 打赏
  • 举报
回复
trackball或者arcball模式,看nehe最后一课。http://www.owlei.com/DancingWind/ win32下的代码可以直接移植mfc。
图灵狗 2013-10-07
  • 打赏
  • 举报
回复
可以先按照http://nehe.gamedev.net/tutorial/lessons_01__05/22004/一步步练习。
引用 楼主 manji_lee 的回复:
void CDrawCubeDemoView::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 CDrawCubeDemoView::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 CDrawCubeDemoView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default //if (GetCapture()==this) if (nFlags & MK_LBUTTON == TRUE) { //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; } } 但是上述简单的代码,旋转效果很差,难以控制,有人用跟踪球做过opengl的旋转平移吗?求大牛指导!!

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧