
    Ti)                      8    d Z ddlZddlmZ  G d d          ZdS )z2Trackball class for 3D manipulation of viewpoints.    N   )transformationsc                   f    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dS )	TrackballzFA trackball class for creating camera transforms from mouse movements.r      r      Nc                 ,   t          j        |          | _        t          |          | _        || _        || _        |7t          j        g d          | _        t          j        g d          | _        n|| _        || _        t          j
        | _        dS )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        R/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/viewer/trackball.py__init__zTrackball.__init__)   s{    * Xd^^
Ell
>8OOO44DLXooo66DNN!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                     || _         dS )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        |          | _        dS )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     Xd^^


r   c                     t          j        |t           j                  | _        | j        | _        | j        | _        dS )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   s2     huBJ777\
~r   c                    t          j        |t           j                  }|t          | d|          z
  \  }}dt          j        | j                  z  }| j        }| j        dddf                                         }| j        dddf                                         }| j        dddf                                         }| j        dddf                                         }	| j	        t          j        k    rk| |z  }
t          j        |
||          }||z  }t          j        |||          }|                    |                    | j                            | _        dS | j	        t          j        k    r| j        d	z  }| j        |z
  }||z
  }|t           j                            |          z  }|t           j                            |          z  }t          j        |d         |d                    t          j        |d         |d                   z   }t          j        |||          }|                    | j                  | _        dS | j	        t          j        k    rz| d
|z  z  | j        z  }| d
|z  z  | j        z  }||z  ||z  z   }| j        |z   | _        t          j        d          }||dddf<   |                    | j                  | _        dS | j	        t          j        k    rt           j                            |	|z
            }d}|dk    r6t          j        t7          |          d| j        d         z  z            dz
  }n.|dk     r(dt          j        |d| j        d         z  z            z
  }t          j        |           |z  |z  |z  }t          j        d          }||dddf<   |                    | j                  | _        dS dS )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   s    bj111 x777Brvdj)))BQBE"**,,BQBE"**,,BQBE"**,,j!Q'')) ;)000cFlG'7PPI6kG'7PPI$==tz)B)BCCDLLL [I000Z#%F[6)FV^FbinnV444FbinnV444FZq	6!9555
6!9fUVi8X8XXE%5eVVLLG";;tz22DLLL [I///f%3Bf%3Bv+V3K!\K7DN6!99D%D!QK88DJ//DLLL [I000Y^^C&L11FEAvvs2ww#
1*=>??#EabfR3$*Q-+@%ABBB72;;,.7&@K6!99D%D!QK88DJ//DLLL 10r   c                 &   | j         }d}d}|dk    r||z  }n|dk     rd|z  t          |          z  }| j        dddf                                         }| j        dddf                                         }t          j                            ||z
            }||z  |z
  |z  }t	          j        d          }	||	dddf<   |	                    | j                  | _        | j	        dddf                                         }| j	        dddf                                         }t          j                            ||z
            }||z  |z
  |z  }t	          j        d          }	||	dddf<   |	                    | j	                  | _	        dS )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   s    A::&=DDaZZ%KCKK/Dbqb!e$,,..l2A2q5!))++f--f}v-7vayy!RaRUxx--BQBE"**,,j!Q''))f--f}v-7vayy!RaRUXXdj))


r   c                    | j         }| j        dddf                                         }||}t          j        |||          }|                    | j                  | _        | j        dddf                                         }||}t          j        |||          }|                    | j                  | _        dS )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#3GVVLL	 }}T\22BQBE"**,,F#3GVVLL	]]4:..


r   )N)__name__
__module____qualname____doc__r   r7   r3   r9   r   propertyr   r!   r#   r*   rP   rT   rX    r   r   r   r   !   s        PPLIJJ"- "- "- "-H   X
 
 
$ $ $
& 
& 
&D0 D0 D0L *  *  *D/ / / / / /r   r   )r\   numpyr    r   r   r^   r   r   <module>ra      sg   4 9 8          O/ O/ O/ O/ O/ O/ O/ O/ O/ O/r   