【发布时间】:2020-11-27 04:44:55
【问题描述】:
我知道以前有人问过这个问题,但我还没有找到适合我的答案。 基本上,我希望相机根据鼠标光标位置左右移动。鼠标越向左,相机越向左转动。所以应该可以转身并朝相反的方向移动。我该怎么做?
这是我的相机位置:
GLfloat cameraPosition[] = { 0.0, 0.0, 3.5 };
GLfloat lx = 0.0; GLfloat ly = 0.0;
这是我的投影矩阵:
// set to projection mode
glMatrixMode(GL_PROJECTION);
// clear any previous transformations
glLoadIdentity();
// set the perspective
gluPerspective(45, (float)windowWidth / (float)windowHeight, 0.1, 20);
在 myDisplay 函数中,这是我设置相机位置的方式:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// set the camera position
gluLookAt(cameraPosition[0], cameraPosition[1], cameraPosition[2],
lx, ly, cameraPosition[2] - 100,
0, 1, 0);
glutPassiveMotionFunc 函数应该做什么?
【问题讨论】: