Class Manipulator


  • public class Manipulator
    extends java.lang.Object
    Helper that enables camera interaction similar to sketchfab or Google Maps. Clients notify the camera manipulator of various mouse or touch events, then periodically call its getLookAt() method so that they can adjust their camera(s). Three modes are supported: ORBIT, MAP, and FREE_FLIGHT. To construct a manipulator instance, the desired mode is passed into the create method.
    See Also:
    Bookmark
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void finalize()  
      Bookmark getCurrentBookmark()
      Gets a handle that can be used to reset the manipulator back to its current position.
      Bookmark getHomeBookmark()
      Gets a handle that can be used to reset the manipulator back to its home position.
      void getLookAt​(double[] eyePosition, double[] targetPosition, double[] upward)  
      void getLookAt​(float[] eyePosition, float[] targetPosition, float[] upward)
      Gets the current orthonormal basis.
      Manipulator.Mode getMode()
      Gets the immutable mode of the manipulator.
      void grabBegin​(int x, int y, boolean strafe)
      Starts a grabbing session (i.e.
      void grabEnd()
      Ends a grabbing session.
      void grabUpdate​(int x, int y)
      Updates a grabbing session.
      void jumpToBookmark​(Bookmark bookmark)
      Sets the manipulator position and orientation back to a stashed state.
      void keyDown​(Manipulator.Key key)
      Keys used to translate the camera in FREE_FLIGHT mode.
      void keyUp​(Manipulator.Key key)
      Signals that a key is now in the up state.
      float[] raycast​(int x, int y)
      Given a viewport coordinate, picks a point in the ground plane.
      void scroll​(int x, int y, float scrolldelta)
      In MAP and ORBIT modes, dollys the camera along the viewing direction.
      void setViewport​(int width, int height)
      Sets the viewport dimensions in terms of pixels.
      void update​(float deltaTime)
      Processes input and updates internal state.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • finalize

        public void finalize()
        Overrides:
        finalize in class java.lang.Object
      • getMode

        public Manipulator.Mode getMode()
        Gets the immutable mode of the manipulator.
      • setViewport

        public void setViewport​(int width,
                                int height)
        Sets the viewport dimensions in terms of pixels. The manipulator uses this only in the grab and raycast methods, since those methods consume coordinates in viewport space.
      • getLookAt

        public void getLookAt​(@NonNull @Size(min=3L)
                              float[] eyePosition,
                              @NonNull @Size(min=3L)
                              float[] targetPosition,
                              @NonNull @Size(min=3L)
                              float[] upward)
        Gets the current orthonormal basis. This is usually called once per frame.
      • getLookAt

        public void getLookAt​(@NonNull @Size(min=3L)
                              double[] eyePosition,
                              @NonNull @Size(min=3L)
                              double[] targetPosition,
                              @NonNull @Size(min=3L)
                              double[] upward)
      • raycast

        @Nullable
        @Size(min=3L)
        public float[] raycast​(int x,
                               int y)
        Given a viewport coordinate, picks a point in the ground plane.
      • grabBegin

        public void grabBegin​(int x,
                              int y,
                              boolean strafe)
        Starts a grabbing session (i.e. the user is dragging around in the viewport). In MAP mode, this starts a panning session. In ORBIT mode, this starts either rotating or strafing. In FREE_FLIGHT mode, this starts a nodal panning session.
        Parameters:
        x - X-coordinate for point of interest in viewport space
        y - Y-coordinate for point of interest in viewport space
        strafe - ORBIT mode only; if true, starts a translation rather than a rotation
      • grabUpdate

        public void grabUpdate​(int x,
                               int y)
        Updates a grabbing session. This must be called at least once between grabBegin / grabEnd to dirty the camera.
      • grabEnd

        public void grabEnd()
        Ends a grabbing session.
      • keyDown

        public void keyDown​(Manipulator.Key key)
        Keys used to translate the camera in FREE_FLIGHT mode. UP and DOWN dolly the camera forwards and backwards. LEFT and RIGHT strafe the camera left and right. UP and DOWN boom the camera upwards and downwards.
      • scroll

        public void scroll​(int x,
                           int y,
                           float scrolldelta)
        In MAP and ORBIT modes, dollys the camera along the viewing direction. In FREE_FLIGHT mode, adjusts the move speed of the camera.
        Parameters:
        x - X-coordinate for point of interest in viewport space, ignored in FREE_FLIGHT mode
        y - Y-coordinate for point of interest in viewport space, ignored in FREE_FLIGHT mode
        scrolldelta - In MAP and ORBIT modes, negative means "zoom in", positive means "zoom out" In FREE_FLIGHT mode, negative means "slower", positive means "faster"
      • update

        public void update​(float deltaTime)
        Processes input and updates internal state. This must be called once every frame before getLookAt is valid.
        Parameters:
        deltaTime - The amount of time, in seconds, passed since the previous call to update.
      • getCurrentBookmark

        public Bookmark getCurrentBookmark()
        Gets a handle that can be used to reset the manipulator back to its current position.
        See Also:
        jumpToBookmark(Bookmark)
      • getHomeBookmark

        public Bookmark getHomeBookmark()
        Gets a handle that can be used to reset the manipulator back to its home position. see jumpToBookmark