I have the following code which works great! To control the camera movement around a point, in this case 0, 0, 0. I can also zoom in and out using right mouse button.
However, I want to be able to calculate the azimuth, bearing and distance, by reading the camera x, y and z positions.
I believe I need to do some inverse calculations, but I am crap at math! Help!
If bLeftMouseButton = True Then
If CURRENTMOUSEX < LASTMOUSEX Then
bearing = oDBCore.WrapValue(bearing + 1)
End If
If CURRENTMOUSEX > LASTMOUSEX Then
bearing = oDBCore.WrapValue(bearing - 1)
End If
If CURRENTMOUSEY < LASTMOUSEY And azimuth < 179 Then
azimuth = oDBCore.WrapValue(azimuth + 1)
End If
If CURRENTMOUSEY > LASTMOUSEY And azimuth > 2 Then
azimuth = oDBCore.WrapValue(azimuth - 1)
End If
End If
If bRightMouseButton = True Then
'*** Zoom with right-click mouse ***
If CURRENTMOUSEY < LASTMOUSEY Then
distance = distance - 10
If distance < 2 Then distance = 2
End If
If CURRENTMOUSEY > LASTMOUSEY Then
distance = distance + 10
If distance > 1000 Then distance = 1000
End If
End If
'*** Calculate camera position ***
x = distance * oDBCore.SIN(azimuth) * oDBCore.COS(bearing)
z = distance * oDBCore.SIN(azimuth) * oDBCore.SIN(bearing)
y = distance * oDBCore.COS(azimuth)
'*** Position and point camera ***
oDBCamera.PositionCamera(x, y, z)
oDBCamera.PointCamera(0, 0, 0)
Thanks in advance!