If you don't need to know how the maths works, here's a piece of code that people may find useful - it gives you the rotating camera positioning that you'll see in games like Dungeon Siege.
It works by positioning the camera at the same place as the object you want to look at, arranging the camera rotation as you've specified, then moving the camera backwards into position. It relies on having the rotation order set to ZYX (which is the default anyway).
I've also added an extra object to make the rotation easier to see.
Use the cursor keys to rotate.
flush video memory
sync on
sync rate 0
autocam off
make object cube 1,10
make object sphere 2, 10
position object 2, 30, 0, 0
ha as float
va as float
va=30
do
if upkey() and va < 90.0 then inc va
if downkey() and va > 30.0 then dec va
if leftkey() then ha=wrapvalue(ha+1.0)
if rightkey() then ha=wrapvalue(ha-1.0)
FloatCamera(1, 100.0, ha, va)
text 0,0,str$( screen fps() )
text 0,15,str$( ha )
text 0,30,str$( va )
sync
loop
function FloatCamera(Ob as integer, Dist as float, HAngle as float, VAngle as float)
position camera object position x(Ob), object position y(Ob), object position z(Ob)
rotate camera VAngle, HAngle, 0
move camera 0.0-Dist
endfunction