Ray

class Ray(val origin: Vector3 = Vector3(), val direction: Vector3 = Vector3(0.0, 0.0, -1.0))

A ray that emits from an origin in a certain direction. The class is used by Raycaster to assist with raycasting (e.g. mouse picking, finding which objects in 3D space the pointer is over).

The ray is mutable and not thread-safe; confine an instance (and any object graph holding it) to a single thread, exactly as in three.js.

The constructor stores the given vectors by reference (it does not copy them); sharing a vector with another object means later mutations are visible through every alias. Use set or clone when you need independent storage.

Constructors

Link copied to clipboard
constructor(origin: Vector3 = Vector3(), direction: Vector3 = Vector3(0.0, 0.0, -1.0))

Properties

Link copied to clipboard

The (normalized) direction of the ray.

Link copied to clipboard

The origin of the ray.

Functions

Link copied to clipboard
fun applyMatrix4(matrix4: Matrix4): Ray

Transforms this ray by the 4x4 matrix matrix4.

Link copied to clipboard
fun at(t: Double, target: Vector3): Vector3

Writes the point located distance t along this ray into target.

Link copied to clipboard
fun clone(): Ray

Returns a new ray with copied values from this instance.

Link copied to clipboard

Writes the point on this ray closest to point into target.

Link copied to clipboard
fun copy(ray: Ray): Ray

Copies the values of ray into this instance.

Link copied to clipboard

Returns the squared distance of closest approach between this ray and point.

Link copied to clipboard
fun distanceSqToSegment(v0: Vector3, v1: Vector3, optionalPointOnRay: Vector3? = null, optionalPointOnSegment: Vector3? = null): Double

Returns the squared distance between this ray and the line segment [v0, v1].

Link copied to clipboard

Returns the distance from this ray's origin to plane, or null if the ray does not intersect the plane.

Link copied to clipboard

Returns the distance of closest approach between this ray and point.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Structural equality: true when other is a Ray with equal origin and direction.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun intersectBox(box: Box3, target: Vector3): Vector3?

Intersects this ray with the bounding box box, writing the intersection point into target.

Link copied to clipboard
fun intersectPlane(plane: Plane, target: Vector3): Vector3?

Intersects this ray with plane, writing the intersection point into target.

Link copied to clipboard

Returns true if this ray intersects box.

Link copied to clipboard
fun intersectSphere(sphere: Sphere, target: Vector3): Vector3?

Intersects this ray with sphere, writing the intersection point into target.

Link copied to clipboard

Returns true if this ray intersects plane.

Link copied to clipboard

Returns true if this ray intersects sphere.

Link copied to clipboard
fun intersectTriangle(a: Vector3, b: Vector3, c: Vector3, backfaceCulling: Boolean, target: Vector3): Vector3?

Intersects this ray with the triangle (a, b, c), writing the intersection point into target.

Link copied to clipboard
fun lookAt(v: Vector3): Ray

Points this ray's direction at v in world space.

Link copied to clipboard
fun recast(t: Double): Ray

Shifts the origin of this ray along its direction by distance t.

Link copied to clipboard
fun set(origin: Vector3, direction: Vector3): Ray

Copies the given origin and direction into this ray.

Link copied to clipboard
open override fun toString(): String