GCubeSDK
©2026 FenixFox®Studios

Ray

Class representing a ray that emits from an origin in a certain direction. A ray is used for raycasting, which is used for mouse picking (working out what objects in the 3D space the mouse is over) amongst other things.

Methods

Ray(const Vector3& origin, const Vector3& direction)

Constructor to create new ray

origin origin of the ray Vector3(0,0,0)
direction (normalized) direction of the ray Vector3(0,0,-1)

Ray& set(const Vector3& origin, const Vector3& direction)

Sets the ray's components by copying the given values

origin origin
direction direction

Ray clone() const

Returns a new ray with copied values from this instance

Ray& copy(const Ray& ray)

Copies the values of the given ray to this instance

ray ray to copy from

Vector3& at(f32 t, Vector3& target) const

Returns a vector that is located at a given distance along this ray

t distance along the ray to retrieve a position for
target target vector that is used to store the method's result

Vector3& lookAt(const Vector3& v)

Adjusts the direction of the ray to point at the given vector in world space

v target position

Ray& recast(f32 t)

Shift the origin of this ray along its direction by the given distance

t distance along the ray to interpolate

f32 distanceToPoint(const Vector3& point) const

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

point point in 3D space to compute the distance to

f32 distanceSqToPoint(const Vector3& point) const

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

point point in 3D space to compute the distance to

f32 distanceSqToSegment(const Vector3& v0, const Vector3& v1, Vector3* optionalPointOnRay, Vector3* optionalPointOnSegment) const

Returns the squared distance between this ray and the given line segment

v0 start point of the line segment
v1 end point of the line segment
optionalPointOnRay when provided, receives the point on this ray that is closest to the segment
optionalPointOnSegment when provided, receives the point on the line segment that is closest to this ray

f32 distanceToPlane(const Plane& plane) const

Computes the distance from the ray's origin to the given plane

plane plane to compute the distance to

Vector3& closestPointToPoint(const Vector3& point, Vector3& target) const

Returns the point along this ray that is closest to the given point

point point in 3D space to get the closest location on the ray for
target target vector that is used to store the method's result

bool intersectsBox(const Box3& box) const

Returns true if this ray intersects with the given box

box box to intersect

bool intersectsPlane(const Plane& plane) const

Returns true if this ray intersects with the given plane

plane plane to intersect

bool intersectsSphere(const Sphere& sphere) const

Returns true if this ray intersects with the given sphere

sphere sphere to intersect

Vector3* intersectBox(const Box3& box, Vector3& target) const

Intersects this ray with the given bounding box, returning the intersection point or null if there is no intersection

box box to intersect
target target vector that is used to store the method's result

Vector3* intersectPlane(const Plane& plane, Vector3& target) const

Intersects this ray with the given plane, returning the intersection point or null if there is no intersection

plane plane to intersect
target target vector that is used to store the method's result

Vector3* intersectSphere(const Sphere& sphere, Vector3& target) const

Intersects this ray with the given sphere, returning the intersection point or null if there is no intersection

sphere sphere to intersect
target target vector that is used to store the method's result

Vector3* intersectTriangle(const Vector3& a, const Vector3& b, const Vector3& c, bool backfaceCulling, Vector3& target) const

Intersects this ray with the given triangle, returning the intersection point or null if there is no intersection

a first vertex of the triangle
b second vertex of the triangle
c third vertex of the triangle
backfaceCulling whether to use backface culling or not
target target vector that is used to store the method's result

Ray& applyMatrix4(const Matrix4& matrix4)

Transforms this ray with the given 4x4 transformation matrix

matrix4 transformation matrix

bool equals(const Ray& ray) const

Returns true if this ray is equal with the given one

ray ray to compare with this one

bool operator==(const Ray& ray) const

Checks if this ray equals another

ray ray to compare with

bool operator!=(const Ray& ray) const

Checks if this ray does not equal another

ray ray to compare with

Properties

direction Vector3 (normalized) direction of the ray
enabled bool Active/inactive
id u32 Unique identifier
isRay bool Read-only tag
name string Optional display name
origin Vector3 origin of the ray
uuid string UUID string
version u32 Bumps on change