eye.X = posx(sel) + Sin(((hang) / 57.2958 - heading(sel) / 57.29)) * zoom * Cos(vang / 57.2958)

eye.Y = posy(sel) + Sin(vang / 57.2958 - roly(sel) / rad) * zoom

eye.z = posz(sel) + Cos(((hang) / 57.2958 - heading(sel) / 57.29)) * zoom * -1 * Cos(vang / 57.2958)

In the above code snippet. POSX, POSY, POSZ are then x,y,z coordinates of the object in space. ZOOM is the distance to the object. VANG = vertical angular offset (the tilt) and HANG = horizontal angular offset. When I want to pan and tilt the camera around an object, I merely assign the mouse x and y co ordinates to HANG and VANG. ROLY is the pitch of the object being viewed. In other words, if in this case, the aircraft goes nose down, the camera angle in increased so as to keep a constant vertical viewing angle to the craft. Likewise, heading is the direction that the target craft is facing. If the target turns right or left, so the camera turns, maintaining a constant orientation to the target.

In order to translate an X,Y,Z coordinate into a XANG, YANG, RANGE co ordinate, use the following routine.

ixdif = eyeposx - targetposx

iydif = eyeposz - targetposz

getcord

xang = itnang

ixdif = itargetrange

iydif = eyeposy - targetposy

getcord

yang = itnang

range = itargetrange

Sub getcord()

itargetrange = Sqr(ixdif ^ 2 + iydif ^ 2)

If iydif <> 0 Then itgan = Atn(ixdif / iydif) * 57.2958

If iydif = 0 And ixdif = 0 Then itgan = 0: itgang = 0

If iydif = 0 And ixdif < 0 Then itgan = 270

If iydif = 0 And ixdif > 0 Then itgan = 90

itgang = itgan

If iydif < 0 Then itgang = 180 + itgan

If ixdif < 0 And iydif > 0 Then itgang = 360 + itgan

itnang = ina + itgang

If itnang > 360 Then itnang = itnang - 360

If itnang < 0 Then itnang = itnang + 360

End Sub

Unfortunately the code is in visual basic ... but the math is correct. Let me know if u need any further assistance

Regards

Cybermike.