【问题标题】:Zooming to point of interest缩放至兴趣点
【发布时间】:2012-04-25 12:21:08
【问题描述】:

我有以下变量:

  • 兴趣点是位置(x,y),以像素为单位 集中注意力。
  • 屏幕宽度、高度是窗口的尺寸。
  • 设置相机缩放级别的缩放级别。

这是我目前的代码。

void Zoom(int pointOfInterestX,int pointOfInterstY,int screenWidth,
   int screenHeight,int zoomLevel)
{   
glScalef(1,1,1);
glTranslatef( (pointOfInterestX/2) - (screenWidth/2), (pointOfInterestY/2) - (screenHeight/2),0);

glScalef(zoomLevel,zoomLevel,1);
}

我想放大/缩小,但将兴趣点保持在屏幕中间。但到目前为止,我所有的尝试都失败了。

【问题讨论】:

  • 缩放会改变你的投影矩阵。你在使用 gluPerspective 吗?
  • 谢谢,但是我如何将屏幕再次居中到兴趣点?
  • 您想通过使用 gluPerspective 设置投影矩阵来开始渲染帧。如果这样做,则可以使用 fovy 参数更改缩放量。屏幕中心的任何内容都将留在中心。
  • hmmm 似乎很难使用:S 编辑:我使用正交 btw
  • 我用的是这个版本:glOrtho(0, WindowW, WindowH, 0, -1, 1);

标签: math opengl graphics


【解决方案1】:

您可以像这样开始渲染框架:

 glViewport(0, 0, w, h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 GLdouble left = (0 - pointOfInterestX) / zoomLevel + pointOfInterestX;
 GLdouble right = (WindowW - pointOfInterestX) / zoomLevel + pointOfInterestX;
 GLdouble bottom = (WindowH - pointOfInterestY) / zoomLevel + pointOfInterestY;
 GLdouble top = (0 - pointOfInterestY) / zoomLevel + pointOfInterestY;
 glOrtho(left, right, bottom, top, -1, 1);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

【讨论】:

    猜你喜欢
    • 2015-11-12
    • 1970-01-01
    • 2016-08-16
    • 2011-04-15
    • 2018-01-18
    • 1970-01-01
    • 2016-02-19
    • 2018-01-13
    • 1970-01-01
    相关资源
    最近更新 更多