Ray(origin, direction)

Class representing a ray in 3D space.

new Ray(origin, direction)

Constructs a new ray with the given values.

Parameters:
Name Type Description
origin Vector3

The origin of the ray.

direction Vector3

The direction of the ray.

Author:

Members

direction :Vector3

The direction of the ray.

origin :Vector3

The origin of the ray.

Methods

applyMatrix4(m) → {Ray}

Transforms this ray by the given 4x4 matrix.

Parameters:
Name Type Description
m Matrix4

The 4x4 matrix.

Returns:
Ray -

A reference to this ray.

at(t, result) → {Vector3}

Computes a position on the ray according to the given t value and stores the result in the given 3D vector. The t value has a range of [0, Infinity] where 0 means the position is equal with the origin of the ray.

Parameters:
Name Type Description
t Number

A scalar value representing a position on the ray.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

clone() → {Ray}

Creates a new ray and copies all values from this ray.

Returns:
Ray -

A new ray.

copy(ray) → {Ray}

Copies all values from the given ray to this ray.

Parameters:
Name Type Description
ray Ray

The ray to copy.

Returns:
Ray -

A reference to this ray.

equals(ray) → {Boolean}

Returns true if the given ray is deep equal with this ray.

Parameters:
Name Type Description
ray Ray

The ray to test.

Returns:
Boolean -

The result of the equality test.

intersectAABB(aabb, result) → {Vector3}

Performs a ray/AABB intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Parameters:
Name Type Description
aabb AABB

An AABB.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectBoundingSphere(sphere, result) → {Vector3}

Performs a ray/sphere intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Parameters:
Name Type Description
sphere BoundingSphere

A bounding sphere.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectBVH(bvh, result) → {Vector3}

Performs a ray/BVH intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Parameters:
Name Type Description
bvh BVH

A BVH.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectConvexHull(convexHull, result) → {Vector3}

Performs a ray/convex hull intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned. The implementation is based on "Fast Ray-Convex Polyhedron Intersection" by Eric Haines, GRAPHICS GEMS II

Parameters:
Name Type Description
convexHull ConvexHull

A convex hull.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectOBB(obb, result) → {Vector3}

Performs a ray/OBB intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Parameters:
Name Type Description
obb OBB

An orientend bounding box.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectPlane(plane, result) → {Vector3}

Performs a ray/plane intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Parameters:
Name Type Description
plane Plane

A plane.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectsAABB(aabb) → {boolean}

Performs a ray/AABB intersection test. Returns either true or false if there is a intersection or not.

Parameters:
Name Type Description
aabb AABB

An axis-aligned bounding box.

Returns:
boolean -

Whether there is an intersection or not.

intersectsBoundingSphere(sphere) → {boolean}

Performs a ray/sphere intersection test. Returns either true or false if there is a intersection or not.

Parameters:
Name Type Description
sphere BoundingSphere

A bounding sphere.

Returns:
boolean -

Whether there is an intersection or not.

intersectsBVH(bvh) → {boolean}

Performs a ray/BVH intersection test. Returns either true or false if there is a intersection or not.

Parameters:
Name Type Description
bvh BVH

A BVH.

Returns:
boolean -

Whether there is an intersection or not.

intersectsConvexHull(convexHull) → {boolean}

Performs a ray/convex hull intersection test. Returns either true or false if there is a intersection or not.

Parameters:
Name Type Description
convexHull ConvexHull

A convex hull.

Returns:
boolean -

Whether there is an intersection or not.

intersectsOBB(obb) → {boolean}

Performs a ray/OBB intersection test. Returns either true or false if there is a intersection or not.

Parameters:
Name Type Description
obb OBB

An orientend bounding box.

Returns:
boolean -

Whether there is an intersection or not.

intersectsPlane(plane) → {boolean}

Performs a ray/plane intersection test. Returns either true or false if there is a intersection or not.

Parameters:
Name Type Description
plane Plane

A plane.

Returns:
boolean -

Whether there is an intersection or not.

intersectTriangle(triangle, backfaceCulling, result) → {Vector3}

Performs a ray/triangle intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Parameters:
Name Type Description
triangle Triangle

A triangle.

backfaceCulling Boolean

Whether back face culling is active or not.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

set(origin, direction) → {Ray}

Sets the given values to this ray.

Parameters:
Name Type Description
origin Vector3

The origin of the ray.

direction Vector3

The direction of the ray.

Returns:
Ray -

A reference to this ray.