AI-generated Key Takeaways
-
The
Cameraclass in Sceneform defines the viewpoint within a 3D scene and is automatically synchronized with ARCore's tracking data in AR mode. -
Direct manipulation of the camera's position and rotation is unsupported in AR mode, as these are controlled by ARCore.
-
It provides methods for retrieving camera properties, such as clipping planes and field of view, and for converting between screen and world coordinates.
-
While inheriting various functionalities from the
Nodeclass, certain operations like setting the parent or manually adjusting position/rotation are restricted in AR mode. -
The camera's position and rotation are automatically managed by ARCore when used within an
ArSceneView, ensuring proper integration with the AR environment.
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 throw UnsupportedOperationException 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.
Public Methods
| float | |
| float | |
| float |
getVerticalFovDegrees()
Gets the vertical field of view for the camera.
|
| 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 | |
| void | |
| void | |
| void |
setVerticalFovDegrees(float verticalFov)
Sets the vertical field of view for the non-ar camera in degrees.
|
| void | |
| void | |
| Vector3 |
Inherited Methods
Public Methods
public float getFarClipPlane ()
public float getNearClipPlane ()
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
| IllegalStateException | if called before the first frame after ARCore is resumed |
|---|
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. |
public void setLocalPosition (Vector3 position)
Set the position of the camera. The camera always isTopLevel(), therefore this behaves
the same as setWorldPosition(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.
Parameters
| position | The position to apply. |
|---|
public void setLocalRotation (Quaternion rotation)
Set the rotation of the camera. The camera always isTopLevel(), therefore this behaves
the same as setWorldRotation(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.
Parameters
| rotation | The rotation to apply. |
|---|
public void setParent (NodeParent parent)
Unsupported operation. Camera's parent cannot be changed, it is always the scene.
Parameters
| parent | The new parent that this node will be a child of. If null, this node will be detached from its parent. |
|---|
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.
Parameters
| verticalFov |
|---|
Throws
| UnsupportedOperationException | if this is an AR camera |
|---|
public void setWorldPosition (Vector3 position)
Set the position of the camera. The camera always isTopLevel(), therefore this behaves
the same as setLocalPosition(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.
Parameters
| position | The position to apply. |
|---|
public void setWorldRotation (Quaternion rotation)
Set the rotation of the camera. The camera always isTopLevel(), therefore this behaves
the same as setLocalRotation(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.
Parameters
| rotation | The rotation to apply. |
|---|
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.