[英]Initializer element is not a compile-time constant c
我不知道为什么我会收到此错误,但我的代码不符合并抛出错误Initializer element is not a compile-time constant
这是代码
#include <math.h>
#include <stdio.h>
const float near = 0.1f;
const int fov_angle = 90;
const float far = 1000.0f;
const float width = 800.0f;
const float height = 600.0f;
const float aspect_ratio = width / height;
const float fov = (1.0f / tan(fov_angle / 2.0)); <- error
float projMat[4][4] = {
{fov * aspect_ratio, 0, 0, 0}, <- error
{0, fov, 0, 0},
{0, 0, ((far+near)/(far-near)), 1},
{0, 0, ((2*near*far)/(near-far)), 0}
};
如错误消息所述,作为全局变量的fov
的初始化程序无法在编译时计算,因为它包含 function 调用。 可执行代码不能驻留在任何函数之外。 projMat
也有类似的问题,因为它依赖于fov
。
您需要在 function 中设置这些变量的值,可能是main
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.