Camera

public class Camera

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:

All other functionality in Node is supported. You can access the position and rotation of the camera, assign a collision shape to the camera, or add children to the camera. Disabling the camera turns off rendering.

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
setLocalPosition(Vector3 position)
Set the position of the camera.
void
setLocalRotation(Quaternion rotation)
Set the rotation of the camera.
void
setParent(NodeParent parent)
Unsupported operation.
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.
Vector3
worldToScreenPoint(Vector3 point)
Convert a point from world space into screen space.

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.