Make an object follow the camera in OpenGL

后端 未结 1 596
梦毁少年i
梦毁少年i 2021-02-11 07:30

I\'m making a racecar game in OpenGL (just a small project) and I\'m having problems trying to make my car follow the camera view.

It wasn\'t hard to make it follow the

相关标签:
1条回答
  • 2021-02-11 08:16

    I think the problem is that you change the center location in gluLookAt and not in the modelPOR.Translate

    the 3 middle parameters of gluLookAt set the center of the view, so the car should be at the exact same position but you modify the center without modifying the car's position.

    gluLookAt(posX,posY + 0.025 * std::abs(sin(headPosAux*PI/180)),posZ,
    
        // center x
        posX + sin(roty*PI/180),
        // center y
        posY + 0.025 * std::abs(sin(headPosAux*PI/180)) + cos(rotx*PI/180),
        // center z
        posZ -cos(roty*PI/180),
    
        0.0,1.0,0.0);
    

    you should probably translate the car by those same values. then it will be centered.

    another problem that seems to be in that code is that you rotate the camera and not the car, so the car probably will not stay pointing in the same direction as the camera. (is that desired or do you do it elswhere?)

    but are you really sure you want to make the car follow the camera? it would probably be better the other way around.

    0 讨论(0)
提交回复
热议问题