t3d. Ray

A ray that emits from an origin in a certain direction. This is used by the Raycaster to assist with raycasting. Raycasting is used for mouse picking (working out what objects in the 3D space the mouse is over) amongst other things.

Constructor

new Ray(origin=opt, direction=opt)

Parameters:
NameTypeAttributesDescription
origin=t3d.Vector3<optional>
the origin of the Ray.
direction=t3d.Vector3<optional>
the direction of the Ray. This must be normalized (with Vector3.normalize) for the methods to operate properly.

Methods

applyMatrix4(matrix4) → {t3d.Ray}

Transform this Ray by the Matrix4.
Parameters:
NameTypeDescription
matrix4t3d.Matrix4the Matrix4 to apply to this Ray.
Returns:
Type: 
t3d.Ray

at(t, optionalTarget=opt) → {t3d.Vector3}

Get a Vector3 that is a given distance along this Ray.
Parameters:
NameTypeAttributesDescription
tNumberthe distance along the Ray to retrieve a position for.
optionalTarget=t3d.Vector3<optional>
the result will be copied into this Vector3.
Returns:
Type: 
t3d.Vector3

copy(ray) → {t3d.Ray}

Copies the origin and direction properties of ray into this ray.
Parameters:
NameTypeDescription
rayt3d.Ray
Returns:
Type: 
t3d.Ray

distanceSqToPoint(point) → {Number}

Get the squared distance of the closest approach between the Ray and the Vector3.
Parameters:
NameTypeDescription
pointt3d.Vector3the Vector3 to compute a distance to.
Returns:
Type: 
Number

distanceToPlane(plane) → {Number}

Get the distance of the closest approach between the Ray and the Plane.
Parameters:
NameTypeDescription
planet3d.Planethe Plane to compute a distance to.
Returns:
Type: 
Number

intersectBox(box, optionalTarget=opt) → {t3d.Vector3}

Intersect this Ray with a Box3, returning the intersection point or null if there is no intersection.
Parameters:
NameTypeAttributesDescription
boxt3d.Box3the Box3 to intersect with.
optionalTarget=t3d.Vector3<optional>
the result will be copied into this Vector3.
Returns:
Type: 
t3d.Vector3

intersectPlane(plane, optionalTarget=opt) → {t3d.Vector3}

Intersect this Ray with a Plane, returning the intersection point or null if there is no intersection.
Parameters:
NameTypeAttributesDescription
planet3d.Planethe Plane to intersect with.
optionalTarget=t3d.Vector3<optional>
the result will be copied into this Vector3.
Returns:
Type: 
t3d.Vector3

intersectSphere(sphere, optionalTarget=opt) → {t3d.Vector3}

Intersect this Ray with a Sphere, returning the intersection point or null if there is no intersection.
Parameters:
NameTypeAttributesDescription
spheret3d.Spherethe Sphere to intersect with.
optionalTarget=t3d.Vector3<optional>
the result will be copied into this Vector3.
Returns:
Type: 
t3d.Vector3

intersectTriangle(a, b, c, backfaceCulling, optionalTarget=opt) → {t3d.Vector3}

Intersect this Ray with a triangle, returning the intersection point or null if there is no intersection.
Parameters:
NameTypeAttributesDescription
at3d.Vector3The Vector3 point making up the triangle.
bt3d.Vector3The Vector3 point making up the triangle.
ct3d.Vector3The Vector3 point making up the triangle.
backfaceCullingBooleanwhether to use backface culling.
optionalTarget=t3d.Vector3<optional>
the result will be copied into this Vector3.
Returns:
Type: 
t3d.Vector3

intersectsBox(box) → {Boolean}

Return true if this Ray intersects with the Box3.
Parameters:
NameTypeDescription
boxt3d.Box3the Box3 to intersect with.
Returns:
Type: 
Boolean

intersectsPlane(plane) → {Boolean}

Return true if this Ray intersects with the Plane.
Parameters:
NameTypeDescription
planet3d.Planethe plane to intersect with.
Returns:
Type: 
Boolean

intersectsSphere(sphere) → {Boolean}

Return true if this Ray intersects with the Sphere.
Parameters:
NameTypeDescription
spheret3d.Spherethe Sphere to intersect with.
Returns:
Type: 
Boolean

set(origin, direction) → {t3d.Ray}

Sets this ray's origin and direction properties by copying the values from the given objects.
Parameters:
NameTypeDescription
origint3d.Vector3the origin of the Ray.
directiont3d.Vector3the direction of the Ray. This must be normalized (with Vector3.normalize) for the methods to operate properly.
Returns:
Type: 
t3d.Ray