Ray

  • Ray is a mathematical representation used for intersection and collision tests within Sceneform.

  • It's defined by an origin and a direction, which can be set during creation or later using setOrigin and setDirection .

  • You can retrieve the origin, direction, and calculate points along the ray using provided methods like getOrigin , getDirection , and getPoint .

  • Rays are fundamental for tasks like hit testing and ray casting in AR applications.

public class Ray

Mathematical representation of a ray. Used to perform intersection and collision tests.

Public Constructors

*
Ray ()
Create a ray with an origin of (0,0,0) and a direction of Vector3.forward().
*
Ray ( Vector3 origin, Vector3 direction)
Create a ray with a specified origin and direction.

Public Methods

Vector3
getDirection ()
Get the direction of the ray.
Vector3
getOrigin ()
Get the origin of the ray.
Vector3
getPoint (float distance)
Get a point at a distance along the ray.
void
setDirection ( Vector3 direction)
Set the direction of the ray.
void
setOrigin ( Vector3 origin)
Set the origin of the ray in world coordinates.
String

Inherited Methods

Public Constructors

public Ray ()

Create a ray with an origin of (0,0,0) and a direction of Vector3.forward().

public Ray ( Vector3 origin, Vector3 direction)

Create a ray with a specified origin and direction. The direction will automatically be normalized.

Parameters
origin the ray's origin
direction the ray's direction

Public Methods

public Vector3 getDirection ()

Get the direction of the ray.

Returns
  • a new vector that represents the ray's direction

public Vector3 getOrigin ()

Get the origin of the ray.

Returns
  • a new vector that represents the ray's origin

public Vector3 getPoint (float distance)

Get a point at a distance along the ray.

Parameters
distance
distance along the ray of the point
Returns
  • a new vector that represents a point at a distance along the ray.

public void setDirection ( Vector3 direction)

Set the direction of the ray. The direction will automatically be normalized.

Parameters
direction
the new direction of the ray

public void setOrigin ( Vector3 origin)

Set the origin of the ray in world coordinates.

Parameters
origin
the new origin of the ray.

public String toString ()

Design a Mobile Site
View Site in Mobile | Classic
Share by: