【问题标题】:OpenGL - set a good distance without glScalefOpenGL - 在没有 glScalef 的情况下设置一个很好的距离
【发布时间】:2015-09-14 23:23:32
【问题描述】:

我尝试为粒子圆盘的全视图设置一个合适的距离,同时具有一个有效的线比例,它表示作为鼠标缩放功能的圆盘比例的当前值。

场景有以下参数:

w_width = 600;
w_height = 600;
g_nearPlane = 0.1f;
g_farPlane = 1000.0f;

我使用以下代码示例对 3D 场景进行图形初始化:

// Reset line scale value
lineScaleValue = 100.0f;
// Initialize View
glViewport(0, 0, w_width, w_height);

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Perspective with angle set to 45 degrees
gluPerspective(45.0f, (float) w_width / w_height, g_nearPlane, g_farPlane);  

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrixi

gluLookAt (0.0, 0.0, 3, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(0.03f, 0.03f, 0.03f);

gluLookAtglScalef 的上述值是近似选择的,即手动选择,没有精确计算。

我只想查看磁盘的完整视图(白色颗粒)。 为此,我知道磁盘 (x,y) 平面中的最大值和最小值: -25 < x <25-22 < y < 22

从这个帖子set z good distance,我可以做到(Fov/2 = 45 度):

z_distance = 25*tan(pi/4) + dist = 50 

dist = 25 位于磁盘前面。

所以我可以直接在我的示例代码中做(而不是

gluLookAt (0.0, 0.0, 3, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glScalef(0.03f, 0.03f, 0.03f);

) :

gluLookAt (0.0, 0.0, 50, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

?

谢谢

【问题讨论】:

  • 磁盘的确切尺寸是多少,您在哪个世界空间位置绘制它?
  • 磁盘的确切尺寸是 -25

标签: opengl zooming glulookat


【解决方案1】:

可以通过您已经链接的帖子中给出的公式计算最佳距离(不确定您是如何得出 z_distance 方程的?):

visible_range = 2 * tan(fov/2) * distance

在你的情况下:

visible_range = 50 (-25 to 25)
=>
50 = 2 * tan(fov/2) * distance
distance = 50 / (2 * tan(fov/2)) = 25 / tan(fov/2)

由于在您的情况下半视场为 45° 并且 tan(45°) = 1,因此最佳解决方案是

distance = 25

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 2018-02-04
    相关资源
    最近更新 更多