【问题标题】:Replicating GLM::perspective in code在代码中复制 GLM::perspective
【发布时间】:2014-03-25 00:43:37
【问题描述】:

我无法理解 glm::perspective。我知道它的作用,但不了解其机制。有谁知道源代码/程序是什么?

【问题讨论】:

标签: c++ opengl glm-math


【解决方案1】:

都是开源的,看the code

template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat4x4<valType, defaultp> perspective
(
    valType const & fovy,
    valType const & aspect,
    valType const & zNear,
    valType const & zFar
)
{
    assert(aspect != valType(0));
    assert(zFar != zNear);

#ifdef GLM_FORCE_RADIANS
    valType const rad = fovy;
#else
#   pragma message("GLM: perspective function taking degrees as a parameter is deprecated.     #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
    valType const rad = glm::radians(fovy);
#endif

    valType tanHalfFovy = tan(rad / valType(2));

    detail::tmat4x4<valType, defaultp> Result(valType(0));
    Result[0][0] = valType(1) / (aspect * tanHalfFovy);
    Result[1][1] = valType(1) / (tanHalfFovy);
    Result[2][2] = - (zFar + zNear) / (zFar - zNear);
    Result[2][3] = - valType(1);
    Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
    return Result;
}

...根据gluPerspective() documentation 创建一个矩阵。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 2019-11-05
    • 1970-01-01
    • 2022-06-20
    • 2018-04-24
    • 2013-02-09
    • 2012-12-23
    相关资源
    最近更新 更多