如何通过数组传递多参数函数?-C ++

Met*_*ark 0 c++ arrays opengl floating-point function

我正在尝试将包含X,Y和Z坐标(类型为float)的数组传递给函数glTranslatef(),但是我不知道实现此目的的方法。

作为我要完成的事情的一个例子;

float xyz[3] = {3,2,1};
glTranslatef(xyz);
Run Code Online (Sandbox Code Playgroud)

每当我尝试这样的事情时,我都会收到以下错误

无法将参数'1'的'float *'转换为'GLfloat {aka float}'转换为'void glTranslatef(GLfloat,GLfloat,GLfloat)'

我已经尝试在整个Google上进行搜索,但是找不到我想要的东西。

Lig*_*ica 5

glTranslatef接受三个float参数,而不是一个数组参数。到此为止。

float XYZ[3] = {3,2,1};
glTranslatef(XYZ[0], XYZ[1], XYZ[2]);
Run Code Online (Sandbox Code Playgroud)

如果您真的很绝望,则可以使用宏将其解压缩:

#define UNPACK_TRI_ARRAY(ar) ar[0], ar[1], ar[2]

float XYZ[3] = {3,2,1};
glTranslatef(UNPACK_TRI_ARRAY(XYZ));
Run Code Online (Sandbox Code Playgroud)

但是一旦达到这一点,就必须问自己为什么