
    j)                      0    d Z ddlZddlmZ  G d d      Zy)z2Trackball class for 3D manipulation of viewpoints.    N   )transformationsc                   ^    e Zd ZdZdZdZdZdZddZe	d        Z
d	 Zd
 Zd Zd Zd ZddZy)	TrackballzFA trackball class for creating camera transforms from mouse movements.r      r      Nc                 0   t        j                  |      | _        t        |      | _        || _        || _        |9t        j                  g d      | _        t        j                  g d      | _        n|| _        || _        t        j                  | _        y)a  Initialize a trackball with an initial camera-to-world pose
        and the given parameters.

        Parameters
        ----------
        pose : [4,4]
            An initial camera-to-world pose for the trackball.

        size : (float, float)
            The width and height of the camera image in pixels.

        scale : float
            The diagonal of the scene's bounding box --
            used for ensuring translation motions are sufficiently
            fast for differently-sized scenes.

        target : (3,) float
            The center of the scene in world coordinates.
            The trackball will revolve around this point.
        N)        r
   r
   )nparray_sizefloat_scale_pose_n_pose_target	_n_targetr   STATE_ROTATE_state)selfposesizescaletargets        E/DATA/.local/lib/python3.12/site-packages/trimesh/viewer/trackball.py__init__zTrackball.__init__)   sl    * XXd^
El
>88O4DLXXo6DN!DL#DN,,    c                     | j                   S )z?autolab_core.RigidTransform : The current camera-to-world pose.)r   )r   s    r   r   zTrackball.poseM   s     ||r   c                     || _         y)a  Set the state of the trackball in order to change the effect of
        dragging motions.

        Parameters
        ----------
        state : int
            One of Trackball.STATE_ROTATE, Trackball.STATE_PAN,
            Trackball.STATE_ROLL, and Trackball.STATE_ZOOM.
        N)r   )r   states     r   	set_statezTrackball.set_stateR   s     r   c                 8    t        j                  |      | _        y)zResize the window.

        Parameters
        ----------
        size : (float, float)
            The new width and height of the camera image in pixels.
        N)r   r   r   )r   r   s     r   resizezTrackball.resize^   s     XXd^
r   c                     t        j                  |t         j                        | _        | j                  | _        | j                  | _        y)zRecord an initial mouse press at a given point.

        Parameters
        ----------
        point : (2,) int
            The x and y pixel coordinates of the mouse press.
        dtypeN)r   r   float32_pdownr   r   r   r   )r   points     r   downzTrackball.downh   s0     hhuBJJ7\\
~~r   c                 0   t        j                  |t         j                        }|t        | d|      z
  \  }}dt        j                  | j
                        z  }| j                  }| j                  dddf   j                         }| j                  dddf   j                         }| j                  dddf   j                         }| j                  dddf   j                         }	| j                  t        j                  k(  ri| |z  }
t        j                  |
||      }||z  }t        j                  |||      }|j                  |j                  | j                              | _        y| j                  t        j                   k(  r| j
                  d	z  }| j"                  |z
  }||z
  }|t         j$                  j'                  |      z  }|t         j$                  j'                  |      z  }t        j(                  |d   |d          t        j(                  |d   |d         z   }t        j                  |||      }|j                  | j                        | _        y| j                  t        j*                  k(  r| d
|z  z  | j,                  z  }| d
|z  z  | j,                  z  }||z  ||z  z   }| j                  |z   | _        t        j0                  d      }||dddf<   |j                  | j                        | _        y| j                  t        j2                  k(  rt         j$                  j'                  |	|z
        }d}|dkD  r5t        j4                  t7        |      d| j
                  d   z  z        dz
  }n0|dk  r+dt        j4                  |d| j
                  d   z  z        z
  }t        j8                  |       |z  |z  |z  }t        j0                  d      }||dddf<   |j                  | j                        | _        yy)aJ  Update the tracball during a drag.

        Parameters
        ----------
        point : (2,) int
            The current x and y pixel coordinates of the mouse during a drag.
            This will compute a movement for the trackball with the relative
            motion between this point and the one marked by down().
        r%   r(   g333333?Nr   r   r   r   g       @g      @   r
   g      ?      ?)r   r   r'   getattrminr   r   r   flattenr   r   r   r   rotation_matrixdotr   
STATE_ROLLr(   linalgnormarctan2	STATE_PANr   r   eye
STATE_ZOOMexpabssign)r   r)   dxdymindimr   x_axisy_axisz_axisr8   x_angle	x_rot_maty_angle	y_rot_matcenterv_initv_currthetarot_mattranslationt_tfradiusratios                          r   dragzTrackball.dragt   sw    bjj1 x77Brvvdjj))BQBE"**,BQBE"**,BQBE"**,jj!Q'') ;;)000cFlG'77PI6kG'77PI$==tzz)BCDL [[I000ZZ#%F[[6)FV^FbiinnV44FbiinnV44FZZq	6!955

6!9fUVi8XXE%55eVVLG";;tzz2DL [[I///f%3Bf%3Bv+V3K!\\K7DN66!9D%D!QK88DJJ/DL [[I000YY^^C&L1FEAvs2w#

1*=>?#EabffR3$**Q-+@%ABB772;,.7&@K66!9D%D!QK88DJJ/DL 1r   c                    | j                   }d}d}|dkD  r||z  }n|dk  rd|z  t        |      z  }| j                  dddf   j                         }| j                  dddf   j                         }t        j
                  j                  ||z
        }||z  |z
  |z  }t	        j                  d      }	||	dddf<   |	j                  | j                        | _        | j                  dddf   j                         }| j                  dddf   j                         }t        j
                  j                  ||z
        }||z  |z
  |z  }t	        j                  d      }	||	dddf<   |	j                  | j                        | _	        y)zZoom using a mouse scroll wheel motion.

        Parameters
        ----------
        clicks : int
            The number of clicks. Positive numbers indicate forward wheel
            movement.
        g?r-   r   Nr   r   r,   )
r   r;   r   r0   r   r4   r5   r8   r2   r   )
r   clicksr   rO   multrB   r8   rN   rL   rM   s
             r   scrollzTrackball.scroll   sr    A:&=DaZ%KCK/Dbqb!e$,,.ll2A2q5!))+f-f}v-7vvay!RaRUxx-BQBE"**,jj!Q'')f-f}v-7vvay!RaRUXXdjj)
r   c                    | j                   }| j                  dddf   j                         }||}t        j                  |||      }|j                  | j                        | _        | j                  dddf   j                         }||}t        j                  |||      }|j                  | j                        | _        y)zRotate the trackball about the "Up" axis by azimuth radians.

        Parameters
        ----------
        azimuth : float
            The number of radians to rotate.
        Nr   r   )r   r   r0   r   r1   r2   r   )r   azimuthaxisr   rA   rD   s         r   rotatezTrackball.rotate   s     bqb!e$,,.F#33GVVL	 }}T\\2BQBE"**,F#33GVVL	]]4::.
r   )N)__name__
__module____qualname____doc__r   r7   r3   r9   r   propertyr   r!   r#   r*   rP   rT   rX    r   r   r   r   !   sT    PLIJJ"-H  
$
&D0L *D/r   r   )r\   numpyr    r   r   r^   r   r   <module>ra      s   4 9  O/ O/r   