官术网_书友最值得收藏!

Frustum

Visually, a frustum looks like a pyramid with the tip cut off. A frustum has six sides; it represents the space that a camera can see. Create the frustum function in mat4.cpp. This function takes left, right, bottom, top, near, and far values:

mat4 frustum(float l, float r, float b,

             float t, float n, float f) {

    if (l == r || t == b || n == f) {

        std::cout << "Invalid frustum\n";

        return mat4(); // Error

    }

    return mat4(

        (2.0f * n) / (r - l),0, 0, 0,

        0,  (2.0f * n) / (t - b), 0, 0,

        (r+l)/(r-l), (t+b)/(t-b), (-(f+n))/(f-n), -1,

        0, 0, (-2 * f * n) / (f - n), 0

    );

}

Important note

The details of deriving the frustum matrix are beyond the scope of this book. For more information on how to derive the function, check out http://www.songho.ca/opengl/gl_projectionmatrix.html.

The frustum function can be used to construct a view frustum, but the function parameters are not intuitive. In the next section, you will learn how to create a view frustum from more intuitive arguments.

主站蜘蛛池模板: 沁阳市| 瑞昌市| 和林格尔县| 巨鹿县| 延吉市| 台州市| 天柱县| 保亭| 巴林左旗| 成安县| 油尖旺区| 沧源| 吴旗县| 文山县| 大邑县| 濉溪县| 五常市| 嘉黎县| 六枝特区| 渭南市| 临沧市| 连城县| 高碑店市| 霸州市| 共和县| 湖南省| 武宁县| 崇信县| 石狮市| 阿坝| 金溪县| 大荔县| 手机| 滁州市| 镇远县| 清流县| 南阳市| 古浪县| 历史| 赣州市| 泰兴市|