我想使用glutTimerFunc将相机移动到由一些网格模型组成的场景周围。相机路径使用Bezier曲线构建,如下所示:
if(sel == MODE_CAMERA_MOTION) {
mode = MODE_CAMERA_MOTION;
stepsCounter = 0;
// Building camera track
int i, j, k;
for(j=0; j<MAX_CV; j++) {
tmpCV[j][0] = CV[j][0];
tmpCV[j][1] = CV[j][1];
tmpCV[j][2] = CV[j][2];
}
for(i=0; i<STEPS; i++) {
for(j=1; j<MAX_CV; j++) {
for(k=0; k<MAX_CV-j; k++) {
lerp(i/(float)(STEPS*10), tmpCV[k], tmpCV[k+1], tmpCV[k]);
}
}
cameraPosition[i][0] = tmpCV[0][0];
cameraPosition[i][1] = tmpCV[0][1];
cameraPosition[i][2] = tmpCV[0][2];
}
glutTimerFunc(250, moveCamera, STEPS);
}
其中moveCamera函数是:
void moveCamera() {
if (mode == MODE_CAMERA_MOTION) {
camE[0] = cameraPosition[stepsCounter][0];
camE[1] = cameraPosition[stepsCounter][1];
camE[2] = cameraPosition[stepsCounter][2];
if(stepsCounter < STEPS) {
stepsCounter++;
}
else {
/* come back to the first point */
camE[0] = 8.8;
camE[1] = 4.9;
camE[2] = 9.0;
stepsCounter = 0;
}
glutPostRedisplay();
}
}
但没有动静。也许我误解了那个功能的行为。 我哪里错了?
答案 0 :(得分:1)
传递给glutTimerFunc的函数的原型应该是
<canvas></canvas>
<div id="canvas"></div>
<div id="canvas2"></div>
其中glutTimerFunc的最后一个参数是传递的值。所以你的moveCamera应该是:
void (*func)(int value)
此外,即便如此,moveCamera函数也会被调用一次。您需要在执行结束时重新注册。这可能是一个可能的解决方案:
void moveCamera( int STEPS )