本文主要是介绍vc6.0 中用OpenGL绘图后用鼠标实现旋转,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
定义了物体的平移,旋转,和缩放等需要的参数,把它们在类中声明成员变量,使它们在类中所有模块都有效。这样在鼠标位置发生改变的时候,通过位置变化改变物体的几何参数,然后调用绘制函数,就可以实现物体的变换了小例子
定义了物体位置参数
在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来控制物体的位置,这样当鼠标拖动时就会发出绘制命令,实现物体的变换
这篇关于vc6.0 中用OpenGL绘图后用鼠标实现旋转的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!