The 3rd person view is basically formed by offsetting the camera from the player in x,y and z, normally behind to oneside and above the player. This requires subtracting from the players x, y and z a distance. This is what the cam_dist does, note the minus sign.
The probelem comes when the player pans, you want the camera to swing round the player so it is in the same position relative to the player and therfore faithfully tracks a fixed position relative to the player.
Thats what the trigonometry does. The player.pan angle is resolved in x and y and these distances are used to adjust the camera position.
Hope this helps.