Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 摄影机跟随对象OpenGL_C++_Opengl_Camera_Glut_Glulookat - Fatal编程技术网

C++ 摄影机跟随对象OpenGL

C++ 摄影机跟随对象OpenGL,c++,opengl,camera,glut,glulookat,C++,Opengl,Camera,Glut,Glulookat,我想实现一个跟随我的3D对象(汽车)的摄像头。要设置相机,我使用以下结构: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, 1, -5, 5); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(pos_x + (cos(90)*0.5), pos_y + (0.5*sin

我想实现一个跟随我的3D对象(汽车)的摄像头。要设置相机,我使用以下结构:

glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45, 1, -5, 5);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(pos_x + (cos(90)*0.5), pos_y + (0.5*sin(90)), 8, pos_x, pos_y, 6, 0, 1, 0);
//pos are the coordinates of the car 

我的问题是,当我换成那个摄像头时,摄像头不会停在车后,而是停在车上。为什么?

因为你要看的第一个位置在汽车上方。我不知道你想用cos-sin做什么,但是,你只是在pos中添加了0和0.5。你在每次帧更新时都使用
gluLookAt
吗?@Jerem我使用cos-sin,因为我希望相机以与汽车相同的速度移动一样的方式移动,我试过这些角度,只是为了测试相机是否放在车的后部。@DanilProkhorenko Yes glulookat在每一帧中。我有一个定时器函数,它会在每一天更新10ms@Miguel你能提供更多的代码吗?我想看看你如何移动汽车,如何画汽车。因为你要看的第一个位置是汽车上方。我不知道你想用cos-sin做什么,但是,你只是在pos中添加了0和0.5。你在每次帧更新时都使用
gluLookAt
吗?@Jerem我使用cos-sin,因为我希望相机以与汽车相同的速度移动一样的方式移动,我试过这些角度,只是为了测试相机是否放在车的后部。@DanilProkhorenko Yes glulookat在每一帧中。我有一个定时器函数,它会在每一天更新10ms@Miguel你能提供更多的代码吗?我想看看你如何移动汽车,如何画汽车。