主题:鼠标指定位置缩放 opengl(牛仔救命!) 急!
鼠标指定位置缩放 opengl
就是鼠标移动到某点,以那点为中心,缩放整个场景。提供下思路啊!
[code=c]
// true放大, false缩小
void CEasyGL::Zoom(BOOL bLarge)
{
RECT rcWnd;
::GetClientRect(m_hWnd, &rcWnd);
//鼠标点在视口(离左边界距离, 下边界距离)
GLdouble viewX = m_curMousePt.s.X - m_viewPort.x;
GLdouble viewY = (rcWnd.bottom - m_curMousePt.s.Y) - m_viewPort.y;
// 视口转为世界窗口坐标 (离左边界距离, 下边界距离)
GLdouble windowX = m_window.left +
(viewX / m_viewPort.width) * m_window.xSize;
GLdouble windowY = m_window.bottom +
(viewY / m_viewPort.height) * m_window.ySize;
// 鼠标在世界窗口坐标
//GLdouble newX = windowX - m_window.xSize / 2;
//GLdouble newY = windowY - m_window.ySize / 2;
static GLdouble dBigX = 1.0, dBigY = 1.0;
if (bLarge)
{
// 世界零点移到鼠标世界点坐标,放大, 再移回来,
glLoadIdentity();
//windowX /= 1.1;
//windowY /= 1.1;
glTranslated(windowX, windowY, 0);
dBigX *= 1.1;
dBigY *= 1.1;
glScalef(dBigX, dBigY, 1.0f);
glTranslated(-windowX, -windowY, 0);
}
else
{
glTranslated(windowX, windowY, 0);
glScalef(0.9f, 0.9f, 1.0f);
glTranslated(-windowX, -windowY, 0);
}
}[/code]
就是鼠标移动到某点,以那点为中心,缩放整个场景。提供下思路啊!
[code=c]
// true放大, false缩小
void CEasyGL::Zoom(BOOL bLarge)
{
RECT rcWnd;
::GetClientRect(m_hWnd, &rcWnd);
//鼠标点在视口(离左边界距离, 下边界距离)
GLdouble viewX = m_curMousePt.s.X - m_viewPort.x;
GLdouble viewY = (rcWnd.bottom - m_curMousePt.s.Y) - m_viewPort.y;
// 视口转为世界窗口坐标 (离左边界距离, 下边界距离)
GLdouble windowX = m_window.left +
(viewX / m_viewPort.width) * m_window.xSize;
GLdouble windowY = m_window.bottom +
(viewY / m_viewPort.height) * m_window.ySize;
// 鼠标在世界窗口坐标
//GLdouble newX = windowX - m_window.xSize / 2;
//GLdouble newY = windowY - m_window.ySize / 2;
static GLdouble dBigX = 1.0, dBigY = 1.0;
if (bLarge)
{
// 世界零点移到鼠标世界点坐标,放大, 再移回来,
glLoadIdentity();
//windowX /= 1.1;
//windowY /= 1.1;
glTranslated(windowX, windowY, 0);
dBigX *= 1.1;
dBigY *= 1.1;
glScalef(dBigX, dBigY, 1.0f);
glTranslated(-windowX, -windowY, 0);
}
else
{
glTranslated(windowX, windowY, 0);
glScalef(0.9f, 0.9f, 1.0f);
glTranslated(-windowX, -windowY, 0);
}
}[/code]