c++ - 在代码中复制 GLM::perspective

标签 c++ opengl glm-math

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

最佳答案

全部开源,看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 创建一个矩阵.

关于c++ - 在代码中复制 GLM::perspective,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22623405/

相关文章:

c++ - CMakeLists.txt 中的 GLM 链接

c++ - Arduino编译错误: xxx does not name a type (despite it being declared 10 lines before)

c++ - 如果我有一个顶点数组,我怎样才能以一种适合循环和绘制三角形带的方式对它们进行排序?

c++ - ifstream 的 std::getline,使用参数字符串或 char *

opengl - 什么时候应该使用多个纹理单元?

opengl - OpenGL 有多强大?

c++ - 沿 3d 曲线渲染圆

c++ - 带有 __declspec(align ('16' )) 的形式参数不会对齐

c++ - Calculator 08 错误程序 - 调试问题

c++ - 同一模式多次出现的 Horspool 算法