Ray

Ray class.

Constructor

new Ray(optionsopt)

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Options:

Properties
NameTypeAttributesDescription
startPositionVec3 | Array.<number><optional>

Ray start point position.

endPositionVec3 | Array.<number><optional>

Ray end point position.

startColorVec3 | Array.<number><optional>

Ray start point color.

endColorVec3 | Array.<number><optional>

Ray end point color.

visibilityboolean<optional>

Visibility.

Members

(static, constant) AWAY

(static, constant) INPLANE

(static, constant) INSIDE

(static, constant) OUTSIDE

Methods

getEndPosition() → {Vec3}

Returns ray end position.

Returns:
Type: 
Vec3

getPoint(distance) → {Vec3}

Computes the point along the ray on the distance.

Parameters:
NameTypeDescription
distancenumber

Point distance.

Returns:
Type: 
Vec3

getStartPosition() → {Vec3}

Returns ray start position.

Returns:
Type: 
Vec3

getVisibility() → {boolean}

Returns visibility.

Returns:
Type: 
boolean

hitPlane(v0, v1, v2, res) → {number}

Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.

Parameters:
NameTypeDescription
v0Vec3

First plane point.

v1Vec3

Second plane point.

v2Vec3

Third plane point.

resVec3

Hit point object pointer that stores hit result.

Returns:
Type: 
number

hitSphere(sphere) → {Vec3}

Returns a ray hit sphere coordiante. If there isn't hit returns null.

Parameters:
NameTypeDescription
sphereSphere

Sphere object.

Returns:
Type: 
Vec3

hitTriangle(v0, v1, v2, res) → {number}

Returns ray hit a triange result.

Parameters:
NameTypeDescription
v0Vec3

First triangle corner coordinate.

v1Vec3

Second triangle corner coordinate.

v2Vec3

Third triangle corner coordinate.

resVec3

Hit point object pointer that stores hit result.

Returns:
  • Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE, 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
Type: 
number

remove()

Remove from handler.

set(origin, direction) → {Ray}

Sets a ray parameters.

Parameters:
NameTypeDescription
originVec3

The origin of the ray.

directionVec3

The direction of the ray.

Returns:
Type: 
Ray

setEndPosition(x, y, z)

Sets ray end position.

Parameters:
NameTypeDescription
xnumber

X coordinate.

ynumber

Y coordinate.

znumber

Z coordinate.

setEndPosition3v(position)

Sets ray end position.

Parameters:
NameTypeDescription
positionVec3

Cartesian coordinates.

setPickingColor3v(color)

Set picking color.

Parameters:
NameTypeDescription
colorVec3

Picking color.

setStartPosition(x, y, z)

Sets ray start position.

Parameters:
NameTypeDescription
xnumber

X coordinate.

ynumber

Y coordinate.

znumber

Z coordinate.

setStartPosition3v(position)

Sets ray start position.

Parameters:
NameTypeDescription
positionVec3

Cartesian coordinates.

setVisibility(visibility)

Sets visibility.

Parameters:
NameTypeDescription
visibilityboolean

Visibility flag.

Ray

Represents a ray that extends infinitely from the provided origin in the provided direction.

Constructor

new Ray(origin, direction)

Parameters:
NameTypeDescription
originVec3

The origin of the ray.

directionVec3

The direction of the ray.

Members

(static, constant) AWAY

(static, constant) INPLANE

(static, constant) INSIDE

(static, constant) OUTSIDE

Methods

getEndPosition() → {Vec3}

Returns ray end position.

Returns:
Type: 
Vec3

getPoint(distance) → {Vec3}

Computes the point along the ray on the distance.

Parameters:
NameTypeDescription
distancenumber

Point distance.

Returns:
Type: 
Vec3

getStartPosition() → {Vec3}

Returns ray start position.

Returns:
Type: 
Vec3

getVisibility() → {boolean}

Returns visibility.

Returns:
Type: 
boolean

hitPlane(v0, v1, v2, res) → {number}

Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.

Parameters:
NameTypeDescription
v0Vec3

First plane point.

v1Vec3

Second plane point.

v2Vec3

Third plane point.

resVec3

Hit point object pointer that stores hit result.

Returns:
Type: 
number

hitSphere(sphere) → {Vec3}

Returns a ray hit sphere coordiante. If there isn't hit returns null.

Parameters:
NameTypeDescription
sphereSphere

Sphere object.

Returns:
Type: 
Vec3

hitTriangle(v0, v1, v2, res) → {number}

Returns ray hit a triange result.

Parameters:
NameTypeDescription
v0Vec3

First triangle corner coordinate.

v1Vec3

Second triangle corner coordinate.

v2Vec3

Third triangle corner coordinate.

resVec3

Hit point object pointer that stores hit result.

Returns:
  • Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE, 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
Type: 
number

remove()

Remove from handler.

set(origin, direction) → {Ray}

Sets a ray parameters.

Parameters:
NameTypeDescription
originVec3

The origin of the ray.

directionVec3

The direction of the ray.

Returns:
Type: 
Ray

setEndPosition(x, y, z)

Sets ray end position.

Parameters:
NameTypeDescription
xnumber

X coordinate.

ynumber

Y coordinate.

znumber

Z coordinate.

setEndPosition3v(position)

Sets ray end position.

Parameters:
NameTypeDescription
positionVec3

Cartesian coordinates.

setPickingColor3v(color)

Set picking color.

Parameters:
NameTypeDescription
colorVec3

Picking color.

setStartPosition(x, y, z)

Sets ray start position.

Parameters:
NameTypeDescription
xnumber

X coordinate.

ynumber

Y coordinate.

znumber

Z coordinate.

setStartPosition3v(position)

Sets ray start position.

Parameters:
NameTypeDescription
positionVec3

Cartesian coordinates.

setVisibility(visibility)

Sets visibility.

Parameters:
NameTypeDescription
visibilityboolean

Visibility flag.