vc6.0 中用OpenGL绘图后用鼠标实现旋转
2014-04-21 18:09
531 查看
定义了物体的平移,旋转,和缩放等需要的参数,把它们在类中声明成员变量,使它们在类中所有模块都有效。这样在鼠标位置发生改变的时候,通过位置变化改变物体的几何参数,然后调用绘制函数,就可以实现物体的变换了
小例子
定义了物体位置参数
在View类声明成员函数 CPoint MouseDownPoint;//记录鼠标的位置信息
GLfloat m_fCorX;
GLfloat m_fCorY;
初始化 m_fCorX;
m_fCorY;
在下面三个函数中填写代码
void CDialog_3D::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// remember where we clicked
MouseDownPoint=point;//记录当前点
// capture mouse movements even outside window borders
SetCapture();//捕获
CDialog::OnLButtonDown(nFlags, point);
}
void CDialog_3D::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// forget where we clicked
MouseDownPoint=CPoint(0,0);//清空位置信息
// release mouse capture
ReleaseCapture();//释放捕获
CDialog::OnLButtonUp(nFlags, point);
}
void CDialog_3D::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)
{
if(nFlags&MK_CONTROL)//如果Ctrl按下了
{
m_fCorX+=double(point.x-MouseDownPoint.x);
m_fCorY+=double(MouseDownPoint.y-point.y);
OnPaint();//重绘
// remember the mouse point
MouseDownPoint=point;//保留当前点
}
}
CDialog::OnMouseMove(nFlags, point);
}
在OnDraw函数中,在绘制图形时,用m_fCorX和m_fCorY来控制物体的位置,这样当鼠标拖动时就会发出绘制命令,实现物体的变换
小例子
定义了物体位置参数
在View类声明成员函数 CPoint MouseDownPoint;//记录鼠标的位置信息
GLfloat m_fCorX;
GLfloat m_fCorY;
初始化 m_fCorX;
m_fCorY;
在下面三个函数中填写代码
void CDialog_3D::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// remember where we clicked
MouseDownPoint=point;//记录当前点
// capture mouse movements even outside window borders
SetCapture();//捕获
CDialog::OnLButtonDown(nFlags, point);
}
void CDialog_3D::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// forget where we clicked
MouseDownPoint=CPoint(0,0);//清空位置信息
// release mouse capture
ReleaseCapture();//释放捕获
CDialog::OnLButtonUp(nFlags, point);
}
void CDialog_3D::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)
{
if(nFlags&MK_CONTROL)//如果Ctrl按下了
{
m_fCorX+=double(point.x-MouseDownPoint.x);
m_fCorY+=double(MouseDownPoint.y-point.y);
OnPaint();//重绘
// remember the mouse point
MouseDownPoint=point;//保留当前点
}
}
CDialog::OnMouseMove(nFlags, point);
}
在OnDraw函数中,在绘制图形时,用m_fCorX和m_fCorY来控制物体的位置,这样当鼠标拖动时就会发出绘制命令,实现物体的变换
相关文章推荐
- unity中用鼠标控制物体实现缩放、平移、旋转
- opengl 鼠标3D旋转简单实现
- MFC单文档结构,实现OpenGL的绘图,移动,旋转,缩放
- OpenGL 鼠标3D旋转简单实现
- Unity通过鼠标或者手势实现拉进拉远,旋转等操作的常用方法
- 用VC6.0与OpenGL实现游戏场景设计
- 20行html代码加40行css代码实现照片墙页面(鼠标hover实现旋转缩放)
- 在unity中用鼠标实现在场景中拖动物体,用鼠标滚轮实现缩放
- 基础代码--通过鼠标的左右滑动来实现摄像机在Y轴上视野旋转
- C#中用鼠标右键选中tabpage选项卡 并且弹出右键菜单,实现选项卡的关闭
- 使用OpenGL实现三维坐标的鼠标拣选(一 )
- uinty实现玩家跟随鼠标位置平滑旋转角度
- java程序实现鼠标绘图
- 使用OpenGL实现三维坐标的鼠标拣选(转)
- 在unity中用鼠标实现在场景中拖动物体,用鼠标滚轮实现缩放
- 转‘OpenGl鼠标控制摄像机camera实现三维漫游
- 使用OpenGL实现三维坐标的鼠标拣选
- Qt+OpenGL实现正方体旋转平移放大缩小,以及六个面贴不同图片
- 使用OpenGL实现三维坐标的鼠标拣选( 二 )
- 用rust + glium实现的一个绘制3D茶壶并实现鼠标拖动旋转的demo