d | distance to origin |
angle1 | angle around y-axis, as measured from positive x-axis |
angle2 | angle up from x-z plane, clamped to [0:Pi/2] |
Calculating eye position -
t = d*cos(angle2) // distance to y-axis after being rotated up y = d*sin(angle2) x = t*cos(angle1) z = t*sin(angle1)
For the mouse interaction -
dx = gain*(x-mx)/width; dy = gain*(y-my)/height;And set the new angles:
angle1 = tempAngle1 + dx; angle2 = tempAngle2 + dy; (clamp as necessary)