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 camera as the camera moves forward and/or backward, but as I rotate the camera (look right or left) the car remais still. I mean, it still moves forward and backward but it's not in front of the camera (it's on the side).
Here is my code (the part where I try to implement it):
void updateCam() {
gluLookAt(posX,posY + 0.025 * std::abs(sin(headPosAux*PI/180)),posZ,
posX + sin(roty*PI/180),posY + 0.025 * std::abs(sin(headPosAux*PI/180)) + cos(rotx*PI/180),posZ -cos(roty*PI/180),
0.0,1.0,0.0);
listenerPos[0] = posX;
listenerPos[1] = posY;
listenerPos[2] = posZ;
source0Pos[0] = posX;
source0Pos[1] = posY;
source0Pos[2] = posZ;
GLfloat distD;
distD = posZ - 3.3;
//makes the car "follow" the camera
modelPOR.Translate(posX,posY,distD);
}