我尝试为粒子盘的完整视图设置一个合适的距离,同时具有一个有效的线比例,它表示作为鼠标缩放功能的盘比例的当前值。
场景有以下参数:
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);
上述gluLookAt
和的值glScalef
是近似选择的,即手动选择,没有精确计算。
我只想查看磁盘的完整视图(白色颗粒)。为此,我知道磁盘 (x,y) 平面中的最大值和最小值 :
-25 < x <25
和-22 < y < 22
.
从这篇文章设置 z 好距离,我可以做到(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);
?
谢谢