透视投影下的缩放。
double m_dbOrthoZoomRatio和double m_dOrthoScaleRatio是自定义的缩放比率,默认是0.9。
以鼠标的坐标与屏幕中心的差值为基础,将得到的二维值根据_rotation投影到三维上,获得的偏移值transCenter加到_center。
滚动函数,设置中心位置
void OrthoZoom(const GUIEventAdapter& ea)
{
GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();
double dbZoomRatio = sm == GUIEventAdapter::SCROLL_UP ? m_dbOrthoZoomRatio : 1.0 / m_dbOrthoZoomRatio;
float fX = ea.getX();
float fY = ea.getY();
int nViewWidth = pViewer->getCamera()->getViewport()->width();
int nViewHeight = pViewer->getCamera()->getViewport()->height();
double transX = (fX - nViewWidth / 2) * m_dbOrthoScaleRatio * (1 - dbZoomRatio);
double transY = (fY - nViewHeight / 2) * m_dbOrthoScaleRatio * (1 - dbZoomRatio);
Matrixd rotMatrix(_rotation);
Vec3d transCenter = Vec3d(transX, transY, 0) * rotMatrix;
_center += transCenter;
}
帧更新函数,影响缩放
void OrthoUpdateProject()
{
int nViewWidth = pViewer->getCamera()->getViewport()->width();
int nViewHeight = pViewer->getCamera()->getViewport()->height();
double dbLeft = -double(nViewWidth) / 2.0 * m_dbOrthoScaleRatio;
double dbRight = double(nViewWidth) * m_dbOrthoScaleRatio + dbLeft;
double dbBottom = -double(nViewHeight) / 2.0 * m_dbOrthoScaleRatio;
double dbTop = double(nViewHeight) * m_dbOrthoScaleRatio + dbBottom;
pViewer->getCamera()->setProjectionMatrixAsOrtho(dbLeft, dbRight, dbBottom, dbTop -100, USHRT_MAX);
}