C++ 中矩阵的透视投影函数

Dis*_*and 4 c++ projection matrix perspective

有没有人有一个函数可以在 C++ 中返回 3x3 矩阵的透视投影?

Matrix Perspective()
{
   Matrix m(0, 0, 0);  // Creates identity matrix
   // Perspective projection formulas here
   return m;
}
Run Code Online (Sandbox Code Playgroud)

Wil*_*ght 7

这里使用 OpenGL gluPerspective 手册页中的公式以 4x4 矩阵返回它:

static void my_PerspectiveFOV(双 fov, 双长宽比, 双近, 双远, 双* mret) {
    双 D2R = M_PI / 180.0;
    双 yScale = 1.0 / tan(D2R * fov / 2);
    双xScale = yScale / 纵横比;
    双nearmfar = 近-远;
    双 m[] = {
        x 比例, 0, 0, 0,
        0, y 比例, 0, 0,
        0, 0, (远 + 近) / 近远, -1,
        0, 0, 2*远*近 / 近远, 0
    };    
    memcpy(mret, m, sizeof(double)*16);
}