1

I'm writing a function to create a perspective projection matrix and I'm getting some errors. Can you help me? I've marked the lines with error with '-'

typedef GLfloat mat4x4[16];

function:

void perspective(float fovy, float aspect, float near, float far, mat4x4& mat)
{
    for(int i=0;i<16;i++)
        mat[i]=0;
    -float range = tan(degreesToRadians(fovy)/2.0f) * near;
    float left = range * aspect;
    float right = range * aspect;
    float bottom = range;
    float top = range;
    -mat[0] = (2.0f * near) / (right - left);
    -mat[5] = (2.0f * near) / (top - bottom);
    --mat[10] = (far + near) / (far - near);
    -mat[11] = 1.0f;
    -mat[14] = (2.0f * far * near) / (far - near);
}

errors:

In function 'void perspective(float, float, float, float, GLfloat (&)[16])':

błąd:expected primary-expression before ';' token
błąd:expected primary-expression before ')' token
błąd:expected primary-expression before ')' token
błąd:expected primary-expression before ')' token
błąd:expected primary-expression before ')' token
błąd:expected primary-expression before ')' token
błąd:expected primary-expression before ')' token
4

1 回答 1

4

我的猜测是你包含了一个定义nearfar作为宏的邪恶标题。这些在古老的 16 位版本的 Windows 上用于限定指针(尽管,如果没有记错的话,我认为 DOS/Windows 标头本身使用了不那么邪恶的NEARand FAR),并且可能仍然存在一些这种怪异的痕迹。

要么避免使用这些名称;或者想办法避免这些宏定义;或切换到向后兼容行李较少的平台以绊倒。

于 2013-06-12T15:52:15.150 回答