Class Manipulator
- java.lang.Object
-
- com.google.android.filament.utils.Manipulator
-
public class Manipulator extends java.lang.ObjectHelper 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classManipulator.Builderstatic classManipulator.Fovstatic classManipulator.KeyKeys used to translate the camera in FREE_FLIGHT mode.static classManipulator.Mode
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinalize()BookmarkgetCurrentBookmark()Gets a handle that can be used to reset the manipulator back to its current position.BookmarkgetHomeBookmark()Gets a handle that can be used to reset the manipulator back to its home position.voidgetLookAt(double[] eyePosition, double[] targetPosition, double[] upward)voidgetLookAt(float[] eyePosition, float[] targetPosition, float[] upward)Gets the current orthonormal basis.Manipulator.ModegetMode()Gets the immutable mode of the manipulator.voidgrabBegin(int x, int y, boolean strafe)Starts a grabbing session (i.e.voidgrabEnd()Ends a grabbing session.voidgrabUpdate(int x, int y)Updates a grabbing session.voidjumpToBookmark(Bookmark bookmark)Sets the manipulator position and orientation back to a stashed state.voidkeyDown(Manipulator.Key key)Keys used to translate the camera in FREE_FLIGHT mode.voidkeyUp(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.voidscroll(int x, int y, float scrolldelta)In MAP and ORBIT modes, dollys the camera along the viewing direction.voidsetViewport(int width, int height)Sets the viewport dimensions in terms of pixels.voidupdate(float deltaTime)Processes input and updates internal state.
-
-
-
Method Detail
-
finalize
public void finalize()
- Overrides:
finalizein classjava.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 spacey- Y-coordinate for point of interest in viewport spacestrafe- 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.
-
keyUp
public void keyUp(Manipulator.Key key)
Signals that a key is now in the up state.
-
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 modey- Y-coordinate for point of interest in viewport space, ignored in FREE_FLIGHT modescrolldelta- 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
-
jumpToBookmark
public void jumpToBookmark(Bookmark bookmark)
Sets the manipulator position and orientation back to a stashed state.- See Also:
getCurrentBookmark(),getHomeBookmark()
-
-