- Qt 6.11
- Qt 3D
- C++ Classes
- Qt3DRender (Deprecated)
- QRayCaster
- Qt 6.11.0 Reference Documentation

# Qt3DRender::QRayCaster Class

class Qt3DRender::QRayCaster

Qt3DRender::QRayCaster is used to perform ray casting tests in 3d world coordinates. More...

Header: | `#include <QRayCaster>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS 3drender)` `target_link_libraries(mytarget PRIVATE Qt6::3drender)`
qmake: | `QT += 3drender`
In QML: | RayCaster
Inherits: | Qt3DRender::QAbstractRayCaster
Status: | Deprecated

- List of all members, including inherited members

## Properties

- direction : QVector3D
- length : float
- origin : QVector3D

## Public Functions

QVector3D | direction() const
float | length() const
QVector3D | origin() const

## Public Slots

void | setDirection(const QVector3D &direction)
void | setLength(float length)
void | setOrigin(const QVector3D &origin)
void | trigger()
void | trigger(const QVector3D &origin, const QVector3D &direction, float length)

## Signals

void | directionChanged(const QVector3D &direction)
void | lengthChanged(float length)
void | originChanged(const QVector3D &origin)

## Detailed Description

The 3d ray is defined by its origin, direction and length. It will be affected by the transformations applied to the entity it belongs to.

Ray casting tests will be performed every frame as long as the component is enabled. The hits property will be updated with the list of intersections.

See also QAbstractRayCaster, QScreenRayCaster, and QNoPicking.

## Property Documentation

### direction : QVector3D

Holds the direction of the 3D ray. This should be a unit vector.

Access functions:

QVector3D | direction() const
void | setDirection(const QVector3D &direction)

Notifier signal:

void | directionChanged(const QVector3D &direction)

### length : float

Holds the length of the 3D ray.

Access functions:

float | length() const
void | setLength(float length)

Notifier signal:

void | lengthChanged(float length)

### origin : QVector3D

Holds the origin of the 3D ray in local coordinates.

Access functions:

QVector3D | origin() const
void | setOrigin(const QVector3D &origin)

Notifier signal:

void | originChanged(const QVector3D &origin)

## Member Function Documentation

### `[slot]` void QRayCaster::setLength(float length)

Sets the length of the ray to length.

If the value is less than or equal to zero, the ray is concidered to be infinite.

Note: Setter function for property length.

See also length().

### `[slot]` void QRayCaster::trigger()

Convenience method to enable the component and trigger tests using the current ray.

Note: This slot is overloaded. To connect to this slot:

     // Connect using qOverload:
     connect(rayCaster, qOverload<>(&QRayCaster::trigger),
             receiver, &ReceiverClass::slot);

     // Or using a lambda:
     connect(rayCaster, qOverload<>(&QRayCaster::trigger),
             this, []() { /* handle trigger */ });

For more examples and approaches, see connecting to overloaded slots.

### `[slot]` void QRayCaster::trigger(const QVector3D &origin, const QVector3D &direction, float length)

Convenience method to set the ray details origin, direction, and length, and enable the component to trigger tests.

Note: This slot is overloaded. To connect to this slot:

     // Connect using qOverload:
     connect(rayCaster, qOverload(&QRayCaster::trigger),
             receiver, &ReceiverClass::slot);

     // Or using a lambda:
     connect(rayCaster, qOverload(&QRayCaster::trigger),
             this, [](const QVector3D &origin, const QVector3D &direction, float length) { /* handle trigger */ });

For more examples and approaches, see connecting to overloaded slots.