本页内容

Qt3DRender::QRayCasterHit Class

class Qt3DRender::QRayCasterHit

将光线投射到模型上时的命中详情。更多...

标题: #include <qraycasterhit.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS 3drender)
target_link_libraries(mytarget PRIVATE Qt6::3drender)
qmake: QT += 3drender
状态: 已弃用

该类已弃用。我们强烈建议不要在新代码中使用它。

公共类型

enum HitType { TriangleHit, LineHit, PointHit, EntityHit }

属性

公共函数

float distance() const
Qt3DCore::QEntity *entity() const
Qt3DCore::QNodeId entityId() const
QVector3D localIntersection() const
uint primitiveIndex() const
Qt3DRender::QRayCasterHit::HitType type() const
uint vertex1Index() const
uint vertex2Index() const
uint vertex3Index() const
QVector3D worldIntersection() const

详细说明

Qt3DRender::QRayCasterHit 包含使用Qt3DRender::QRayCaster 或Qt3DRender::QScreenRayCaster 组件通过模型投射光线时,成功命中事件的详细信息。

另请参阅 Qt3DRender::QRayCaster 、Qt3DRender::QScreenRayCaster 和Qt3DRender::QPickingSettings 。

成员类型文档

enum QRayCasterHit::HitType

指定返回的匹配结果类型。该设置通过 QPickingSettings 进行控制。

常量值描述
Qt3DRender::QRayCasterHit::TriangleHit0选中的基元是一个三角形,且顶点索引指向构成该三角形的三点
Qt3DRender::QRayCasterHit::LineHit1选中的基元为线段,前两个顶点索引分别指向构成该线的两个点
Qt3DRender::QRayCasterHit::PointHit2所选基元为单个点;所有 3 个顶点索引均未定义
Qt3DRender::QRayCasterHit::EntityHit3仅考虑了包围体积;基元和顶点索引将为未定义

属性文档

[read-only] distance : const float

该属性存储光线起点与交点之间的距离。

存储光线起点到光线与实体相交点的距离。

访问函数:

float distance() const

[read-only] entity : Qt3DCore::QEntity* const

该属性保存被击中的实体的指针。

保存被光线击中的 QEntity 的指针。

访问函数:

Qt3DCore::QEntity *entity() const

[read-only] entityId : const Qt3DCore::QNodeId

该属性存储被击中的实体的 ID。

保存被光线击中的实体的节点 ID。

访问函数:

Qt3DCore::QNodeId entityId() const

[read-only] localIntersection : const QVector3D

该属性存储了实体坐标系中交点的坐标。

保存该实体本机坐标系中交点的坐标。

访问函数:

QVector3D localIntersection() const

[read-only] primitiveIndex : const uint

该属性存储所选基元(三角形、直线或点)的索引。

保存被选中的基元(三角形、线段或点)的索引。

访问函数:

uint primitiveIndex() const

[read-only] type : const QRayCasterHit::HitType

该属性存储命中项的类型。

存储命中类型,该类型可以是TriangleHit 、LineHit 、PointHit 或EntityHit 。

访问函数:

Qt3DRender::QRayCasterHit::HitType type() const

[read-only] vertex1Index : const uint

该属性存储被选中基元第一个顶点的索引。

保存所选基元第一个顶点的索引。对于三角形命中,这是三个顶点之一;对于直线命中,这是两个顶点之一。

访问函数:

uint vertex1Index() const

[read-only] vertex2Index : const uint

该属性存储被选中基元第二个顶点的索引。

保存被选中基元第二个顶点的索引。对于三角形命中,这是三个顶点之一;对于直线命中,这是两个顶点之一。

访问函数:

uint vertex2Index() const

[read-only] vertex3Index : const uint

该属性存储所选基元第三个顶点的索引。

保存所选基元第三个顶点的索引。此属性仅在三角形命中时有效。

访问函数:

uint vertex3Index() const

[read-only] worldIntersection : const QVector3D

该属性存储了在模型坐标系中交点的坐标。

存储世界坐标系中交点的坐标。

访问函数:

QVector3D worldIntersection() const

成员函数文档

float QRayCasterHit::distance() const

返回光线原点与交点之间的距离

注: 这是 distance 属性的获取 函数。

Qt3DCore::QEntity *QRayCasterHit::entity() const

返回被击中的实体的指针

注意: 这是属性 entity 的获取 函数。

Qt3DCore::QNodeId QRayCasterHit::entityId() const

返回被命中的实体的 ID

注意: 这是属性 entityId 的获取器 函数。

QVector3D QRayCasterHit::localIntersection() const

返回该实体坐标系中交点的坐标

注: 这是属性 localIntersection 的获取 函数。

uint QRayCasterHit::primitiveIndex() const

返回所选基元对应的索引

注意: 这是属性 primitiveIndex的获取 函数。

Qt3DRender::QRayCasterHit::HitType QRayCasterHit::type() const

返回命中类型

注意: 这是用于获取 属性 type 的获取 函数。

uint QRayCasterHit::vertex1Index() const

返回所选基元第一个顶点的索引

注意: 这是 property vertex1Index的获取 函数。

uint QRayCasterHit::vertex2Index() const

返回所选基元中第二个顶点的索引

注意: 这是属性 vertex2Index 的获取 函数。

uint QRayCasterHit::vertex3Index() const

返回所选基元中第三个顶点的索引

注: 这是属性 vertex3Index 的获取 函数。

QVector3D QRayCasterHit::worldIntersection() const

返回模型坐标系中交点的坐标

注: 这是属性 worldIntersection 的获取 函数。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.