您的位置:首页 > 运维架构

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来控制物体的位置,这样当鼠标拖动时就会发出绘制命令,实现物体的变换
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: