Class Camera
- java.lang.Object
-
- com.google.ar.sceneform.NodeParent
-
- com.google.ar.sceneform.Node
-
- com.google.ar.sceneform.Camera
-
- All Implemented Interfaces:
TransformProvider
,CameraProvider
public class Camera extends Node implements CameraProvider
Represents a virtual camera, which determines the perspective through which the scene is viewed.If the camera is part of an
ArSceneView
, then the camera automatically tracks the camera pose from ARCore. Additionally, the following methods will throwUnsupportedOperationException
when called:setParent(NodeParent)
- Camera's parent cannot be changed, it is always the scene.setLocalPosition(Vector3)
- Camera's position cannot be changed, it is controlled by the ARCore camera pose.setLocalRotation(Quaternion)
- Camera's rotation cannot be changed, it is controlled by the ARCore camera pose.setWorldPosition(Vector3)
- Camera's position cannot be changed, it is controlled by the ARCore camera pose.setWorldRotation(Quaternion)
- Camera's rotation cannot be changed, it is controlled by the ARCore camera pose.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.ar.sceneform.Node
Node.LifecycleListener, Node.OnTapListener, Node.OnTouchListener, Node.TransformChangedListener
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description float
getFarClipPlane()
float
getNearClipPlane()
Matrix
getProjectionMatrix()
float
getVerticalFovDegrees()
Gets the vertical field of view for the camera.Matrix
getViewMatrix()
Ray
screenPointToRay(float x, float y)
Calculates a ray in world space going from the near-plane of the camera and going through a point in screen space.void
setFarClipPlane(float farPlane)
void
setLocalPosition(Vector3 position)
Set the position of the camera.void
setLocalRotation(Quaternion rotation)
Set the rotation of the camera.void
setNearClipPlane(float nearPlane)
void
setParent(NodeParent parent)
Unsupported operation.void
setProjectionMatrix(Matrix matrix)
void
setVerticalFovDegrees(float verticalFov)
Sets the vertical field of view for the non-ar camera in degrees.void
setWorldPosition(Vector3 position)
Set the position of the camera.void
setWorldRotation(Quaternion rotation)
Set the rotation of the camera.void
updateTrackedPose(com.google.ar.core.Camera camera)
Updates the pose and projection of the camera to match the tracked pose from ARCore.Vector3
worldToScreenPoint(Vector3 point)
Convert a point from world space into screen space.-
Methods inherited from class com.google.ar.sceneform.Node
addLifecycleListener, addTransformChangedListener, callOnHierarchy, findInHierarchy, getBack, getCollisionShape, getDown, getForward, getLeft, getLight, getLocalPosition, getLocalRotation, getLocalScale, getName, getParent, getRenderable, getRenderableInstance, getRight, getScene, getUp, getWorldModelMatrix, getWorldPosition, getWorldRotation, getWorldScale, isActive, isDescendantOf, isEnabled, isSelectable, isTopLevel, localToWorldDirection, localToWorldPoint, onActivate, onDeactivate, onTouchEvent, onTransformChange, onUpdate, removeLifecycleListener, removeTransformChangedListener, setCollisionShape, setEnabled, setLight, setLocalScale, setLookDirection, setLookDirection, setName, setOnTapListener, setOnTouchListener, setRenderable, setSelectable, setWorldScale, toString, worldToLocalDirection, worldToLocalPoint
-
Methods inherited from class com.google.ar.sceneform.NodeParent
addChild, findByName, getChildren, removeChild
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.ar.sceneform.rendering.CameraProvider
isActive
-
Methods inherited from interface com.google.ar.sceneform.common.TransformProvider
getWorldModelMatrix
-
-
-
-
Method Detail
-
setNearClipPlane
public void setNearClipPlane(float nearPlane)
-
getNearClipPlane
public float getNearClipPlane()
- Specified by:
getNearClipPlane
in interfaceCameraProvider
-
setFarClipPlane
public void setFarClipPlane(float farPlane)
-
setVerticalFovDegrees
public void setVerticalFovDegrees(float verticalFov)
Sets the vertical field of view for the non-ar camera in degrees. If this is an AR camera, then the fov comes from ARCore and cannot be set so an exception is thrown. The default is 90 degrees.- Throws:
java.lang.UnsupportedOperationException
- if this is an AR camera
-
getVerticalFovDegrees
public float getVerticalFovDegrees()
Gets the vertical field of view for the camera.If this is an AR camera, then it is calculated based on the camera information from ARCore and can vary between device. It can't be calculated until the first frame after the ARCore session is resumed, in which case an IllegalStateException is thrown.
Otherwise, this will return the value set by
setVerticalFovDegrees(float)
, with a default of 90 degrees.- Throws:
java.lang.IllegalStateException
- if called before the first frame after ARCore is resumed
-
getFarClipPlane
public float getFarClipPlane()
- Specified by:
getFarClipPlane
in interfaceCameraProvider
-
getViewMatrix
public Matrix getViewMatrix()
- Specified by:
getViewMatrix
in interfaceCameraProvider
-
getProjectionMatrix
public Matrix getProjectionMatrix()
- Specified by:
getProjectionMatrix
in interfaceCameraProvider
-
updateTrackedPose
public void updateTrackedPose(com.google.ar.core.Camera camera)
Updates the pose and projection of the camera to match the tracked pose from ARCore.- Specified by:
updateTrackedPose
in interfaceCameraProvider
-
screenPointToRay
public Ray screenPointToRay(float x, float y)
Calculates a ray in world space going from the near-plane of the camera and going through a point in screen space. Screen space is in Android device screen coordinates: TopLeft = (0, 0) BottomRight = (Screen Width, Screen Height) The device coordinate space is unaffected by the orientation of the device.- Parameters:
x
- X position in device screen coordinates.y
- Y position in device screen coordinates.
-
worldToScreenPoint
public Vector3 worldToScreenPoint(Vector3 point)
Convert a point from world space into screen space.The X value is negative when the point is left of the viewport, between 0 and the width of the
SceneView
when the point is within the viewport, and greater than the width when the point is to the right of the viewport.The Y value is negative when the point is below the viewport, between 0 and the height of the
SceneView
when the point is within the viewport, and greater than the height when the point is above the viewport.The Z value is always 0 since the return value is a 2D coordinate.
- Parameters:
point
- the point in world space to convert- Returns:
- a new vector that represents the point in screen-space.
-
setParent
public void setParent(@Nullable NodeParent parent)
Unsupported operation. Camera's parent cannot be changed, it is always the scene.- Overrides:
setParent
in classNode
- Parameters:
parent
- The new parent that this node will be a child of. If null, this node will be detached from its parent.- See Also:
Node.getParent()
,Node.getScene()
-
setLocalPosition
public void setLocalPosition(Vector3 position)
Set the position of the camera. The camera alwaysNode.isTopLevel()
, therefore this behaves the same assetWorldPosition(Vector3)
.If the camera is part of an
ArSceneView
, then this is an unsupported operation. Camera's position cannot be changed, it is controlled by the ARCore camera pose.- Overrides:
setLocalPosition
in classNode
- Parameters:
position
- The position to apply.- See Also:
Node.getLocalPosition()
-
setLocalRotation
public void setLocalRotation(Quaternion rotation)
Set the rotation of the camera. The camera alwaysNode.isTopLevel()
, therefore this behaves the same assetWorldRotation(Quaternion)
.If the camera is part of an
ArSceneView
, then this is an unsupported operation. Camera's rotation cannot be changed, it is controlled by the ARCore camera pose.- Overrides:
setLocalRotation
in classNode
- Parameters:
rotation
- The rotation to apply.- See Also:
Node.getLocalRotation()
-
setWorldPosition
public void setWorldPosition(Vector3 position)
Set the position of the camera. The camera alwaysNode.isTopLevel()
, therefore this behaves the same assetLocalPosition(Vector3)
.If the camera is part of an
ArSceneView
, then this is an unsupported operation. Camera's position cannot be changed, it is controlled by the ARCore camera pose.- Overrides:
setWorldPosition
in classNode
- Parameters:
position
- The position to apply.- See Also:
Node.getWorldPosition()
-
setWorldRotation
public void setWorldRotation(Quaternion rotation)
Set the rotation of the camera. The camera alwaysNode.isTopLevel()
, therefore this behaves the same assetLocalRotation(Quaternion)
.If the camera is part of an
ArSceneView
, then this is an unsupported operation. Camera's rotation cannot be changed, it is controlled by the ARCore camera pose.- Overrides:
setWorldRotation
in classNode
- Parameters:
rotation
- The rotation to apply.- See Also:
Node.getWorldRotation()
-
setProjectionMatrix
public void setProjectionMatrix(Matrix matrix)
-
-