<s> from __future__ import division <EOL> import numpy as np <EOL> from ... util . quaternion import Quaternion <EOL> from ... visuals . transforms import MatrixTransform <EOL> from . perspective import Base3DRotationCamera <EOL> class ArcballCamera ( Base3DRotationCamera ) : <EOL> """<STR_LIT>""" <EOL> _state_props = Base3DRotationCamera . _state_props <EOL> def __init__ ( self , fov = <NUM_LIT:0.0> , distance = None , ** kwargs ) : <EOL> super ( ArcballCamera , self ) . __init__ ( fov = fov , ** kwargs ) <EOL> self . _quaternion = Quaternion ( ) <EOL> self . distance = distance <EOL> def _update_rotation ( self , event ) : <EOL> """<STR_LIT>""" <EOL> p2 = event . mouse_event . pos <EOL> if self . _event_value is None : <EOL> self . _event_value = p2 <EOL> wh = self . _viewbox . size <EOL> self . _quaternion = ( Quaternion ( * _arcball ( p2 , wh ) ) * <EOL> Quaternion ( * _arcball ( self . _event_value , wh ) ) * <EOL> self . _quaternion ) <EOL> self . _event_value = p2 <EOL> self . view_changed ( ) <EOL> def _rotate_tr ( self ) : <EOL> """<STR_LIT>""" <EOL> rot , x , y , z = self . _quaternion . get_axis_angle ( ) <EOL> up , forward , right = self . _get_dim_vectors ( ) <EOL> self . transform . rotate ( <NUM_LIT> * rot / np . pi , ( x , z , y ) ) <EOL> def _dist_to_trans ( self , dist ) : <EOL> """<STR_LIT>""" <EOL> rot , x , y , z = self . _quaternion . get_axis_angle ( ) <EOL> tr = MatrixTransform ( ) <EOL> tr . rotate ( <NUM_LIT> * rot / np . pi , ( x , y , z ) ) <EOL> dx , dz , dy = np . dot ( tr . matrix [ : <NUM_LIT:3> , : <NUM_LIT:3> ] , ( dist [ <NUM_LIT:0> ] , dist [ <NUM_LIT:1> ] , <NUM_LIT:0.> ) ) <EOL> return dx , dy , dz <EOL> def _get_dim_vectors ( self ) : <EOL> return np . eye ( <NUM_LIT:3> ) [ : : - <NUM_LIT:1> ] <EOL> def _arcball ( xy , wh ) : <EOL> """<STR_LIT>""" <EOL> x , y = xy <EOL> w , h = wh <EOL> r = ( w + h ) / <NUM_LIT> <EOL> x , y = - ( <NUM_LIT> * x - w ) / r , ( <NUM_LIT> * y - h ) / r <EOL> h = np . sqrt ( x * x + y * y ) <EOL> return ( <NUM_LIT:0.> , x / h , y / h , <NUM_LIT:0.> ) if h > <NUM_LIT:1.> else ( <NUM_LIT:0.> , x , y , np . sqrt ( <NUM_LIT:1.> - h * h ) ) </s>
