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

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.

主站蜘蛛池模板: 宁都县| 孝义市| 临潭县| 白河县| 梧州市| 崇礼县| 繁峙县| 青河县| 麟游县| 潮州市| 句容市| 武胜县| 榆树市| 偃师市| 宣威市| 车险| 左贡县| 若尔盖县| 慈溪市| 孝昌县| 崇信县| 咸丰县| 郎溪县| 建昌县| 三都| 达日县| 蓬溪县| 富顺县| 驻马店市| 镇平县| 武川县| 班玛县| 休宁县| 柏乡县| 防城港市| 仪征市| 来安县| 文化| 上高县| 门头沟区| 竹山县|