Setting up ray-caster
I add QRayCaster to my root entity and connect its signal to a slot:
void MySceneClass::createRootEntity()
{
// ...
// Add ray caster to root entity
m_rayCaster = new Qt3DRender::QRayCaster(m_rootEntity);
m_rayCaster->setRunMode(Qt3DRender::QAbstractRayCaster::SingleShot);
m_rootEntity->addComponent(m_rayCaster);
// Set up signal to slot connection
QObject::connect(m_rayCaster, &Qt3DRender::QRayCaster::hitsChanged,
this, &MySceneClass::handleRayCasterHits);
// ...
}
I log ray-caster hits by the slot:
void MySceneClass::handleRayCasterHits(const Qt3DRender::QAbstractRayCaster::Hits hits)
{
qDebug() << "Ray casting resulted in hits";
}
Triggering ray-caster
I trigger ray-caster iteratively inside a loop:
void MyOtherClass::triggerRayCaster()
{
for (int i = 0; i < 100; ++i) {
m_mySceneClass->castRay(QVector3D(i, i, 50.0f), // origin
QVector3D(0.0f, 0.0f, -1.0f), // direction
-1 // length (-1 means infinite)
);
}
}
Problem
The problem is, on all the tests, only the last iteration of the trigger-loop inside triggerRayCaster()
is captured and logged by the slot inside handleRayCasterHits()
.
I don't get why. Am I missing something?