mirror of https://github.com/qt/qt3d.git
Namespace ray casting classes
Main usage to namespace QBoundingVolume, QBoundingSphere for future use. Renamed QBoundingSphere to BoundingSphere to avoid clashes in file names. Change-Id: I0adcb3c3a5f1b8134653773a8e21490ecf61bae4 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
parent
2499faac08
commit
f5df989ff9
|
|
@ -79,6 +79,13 @@ QT_BEGIN_NAMESPACE
|
|||
QT3D_DECLARE_TYPEINFO(NS, Class, Q_MOVABLE_TYPE) \
|
||||
/*end*/
|
||||
|
||||
#define QT3D_DECLARE_SHARED_2(OuterNS, InnerNS, Class) \
|
||||
inline void swap(Class &lhs, Class &rhs) \
|
||||
Q_DECL_NOEXCEPT_EXPR(noexcept(lhs.swap(rhs))) \
|
||||
{ lhs.swap(rhs); } \
|
||||
QT3D_DECLARE_TYPEINFO_2(OuterNS, InnerNS, Class, Q_MOVABLE_TYPE) \
|
||||
/*end*/
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT3DCORE_GLOBAL_H
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace Render {
|
|||
|
||||
// Note: a, b, c in clockwise order
|
||||
// RealTime Collision Detection page 192
|
||||
bool intersectsSegmentTriangle(const QRay3D &ray,
|
||||
bool intersectsSegmentTriangle(const RayCasting::QRay3D &ray,
|
||||
const QVector3D &a,
|
||||
const QVector3D &b,
|
||||
const QVector3D &c,
|
||||
|
|
@ -112,7 +112,7 @@ Qt3DCore::QNodeId TriangleBoundingVolume::id() const
|
|||
return m_id;
|
||||
}
|
||||
|
||||
bool TriangleBoundingVolume::intersects(const QRay3D &ray, QVector3D *q) const
|
||||
bool TriangleBoundingVolume::intersects(const RayCasting::QRay3D &ray, QVector3D *q) const
|
||||
{
|
||||
float t = 0.0f;
|
||||
QVector3D uvw;
|
||||
|
|
@ -124,9 +124,9 @@ bool TriangleBoundingVolume::intersects(const QRay3D &ray, QVector3D *q) const
|
|||
return intersected;
|
||||
}
|
||||
|
||||
QBoundingVolume::Type TriangleBoundingVolume::type() const
|
||||
TriangleBoundingVolume::Type TriangleBoundingVolume::type() const
|
||||
{
|
||||
return QBoundingVolume::Triangle;
|
||||
return RayCasting::QBoundingVolume::Triangle;
|
||||
}
|
||||
|
||||
QVector3D TriangleBoundingVolume::a() const
|
||||
|
|
|
|||
|
|
@ -61,14 +61,14 @@ namespace Qt3DRender {
|
|||
|
||||
namespace Render {
|
||||
|
||||
Q_AUTOTEST_EXPORT bool intersectsSegmentTriangle(const QRay3D &ray,
|
||||
Q_AUTOTEST_EXPORT bool intersectsSegmentTriangle(const RayCasting::QRay3D &ray,
|
||||
const QVector3D &a,
|
||||
const QVector3D &b,
|
||||
const QVector3D &c,
|
||||
QVector3D &uvw,
|
||||
float &t);
|
||||
|
||||
class Q_AUTOTEST_EXPORT TriangleBoundingVolume : public QBoundingVolume
|
||||
class Q_AUTOTEST_EXPORT TriangleBoundingVolume : public RayCasting::QBoundingVolume
|
||||
{
|
||||
public:
|
||||
TriangleBoundingVolume();
|
||||
|
|
@ -78,7 +78,7 @@ public:
|
|||
const QVector3D &c);
|
||||
|
||||
Qt3DCore::QNodeId id() const Q_DECL_FINAL;
|
||||
bool intersects(const QRay3D &ray, QVector3D *q) const Q_DECL_FINAL;
|
||||
bool intersects(const RayCasting::QRay3D &ray, QVector3D *q) const Q_DECL_FINAL;
|
||||
Type type() const Q_DECL_FINAL;
|
||||
|
||||
QVector3D a() const;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ TrianglesExtractor::TrianglesExtractor(GeometryRenderer *renderer, NodeManagers
|
|||
{
|
||||
}
|
||||
|
||||
QVector<QBoundingVolume *> TrianglesExtractor::extract(const Qt3DCore::QNodeId id)
|
||||
QVector<RayCasting::QBoundingVolume *> TrianglesExtractor::extract(const Qt3DCore::QNodeId id)
|
||||
{
|
||||
qDeleteAll(m_volumes);
|
||||
apply(m_renderer, id);
|
||||
|
|
|
|||
|
|
@ -56,8 +56,9 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
|
||||
namespace RayCasting {
|
||||
class QBoundingVolume;
|
||||
}
|
||||
|
||||
namespace Render {
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ public:
|
|||
explicit TrianglesExtractor(GeometryRenderer *renderer,
|
||||
NodeManagers *manager);
|
||||
|
||||
QVector<QBoundingVolume *> extract(const Qt3DCore::QNodeId id);
|
||||
QVector<RayCasting::QBoundingVolume *> extract(const Qt3DCore::QNodeId id);
|
||||
|
||||
private:
|
||||
void visit(uint andx, const QVector3D &a,
|
||||
|
|
@ -75,7 +76,7 @@ private:
|
|||
uint cndx, const QVector3D &c) Q_DECL_OVERRIDE;
|
||||
|
||||
GeometryRenderer *m_renderer;
|
||||
QVector<QBoundingVolume *> m_volumes;
|
||||
QVector<RayCasting::QBoundingVolume *> m_volumes;
|
||||
};
|
||||
|
||||
} // namespace Render
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace {
|
|||
|
||||
// Intersects ray r = p + td, |d| = 1, with sphere s and, if intersecting,
|
||||
// returns true and intersection point q; false otherwise
|
||||
bool intersectRaySphere(const Qt3DRender::QRay3D &ray, const Qt3DRender::Render::Sphere &s, QVector3D *q = nullptr)
|
||||
bool intersectRaySphere(const Qt3DRender::RayCasting::QRay3D &ray, const Qt3DRender::Render::Sphere &s, QVector3D *q = nullptr)
|
||||
{
|
||||
const QVector3D p = ray.origin();
|
||||
const QVector3D d = ray.direction();
|
||||
|
|
@ -223,14 +223,14 @@ Qt3DCore::QNodeId Sphere::id() const
|
|||
return m_id;
|
||||
}
|
||||
|
||||
bool Sphere::intersects(const QRay3D &ray, QVector3D *q) const
|
||||
bool Sphere::intersects(const RayCasting::QRay3D &ray, QVector3D *q) const
|
||||
{
|
||||
return intersectRaySphere(ray, *this, q);
|
||||
}
|
||||
|
||||
QBoundingVolume::Type Sphere::type() const
|
||||
Sphere::Type Sphere::type() const
|
||||
{
|
||||
return QBoundingVolume::Sphere;
|
||||
return RayCasting::QBoundingVolume::Sphere;
|
||||
}
|
||||
|
||||
} // Render
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
#include <Qt3DRender/private/qt3drender_global_p.h>
|
||||
#include <Qt3DCore/qnodeid.h>
|
||||
#include <Qt3DRender/private/qboundingsphere_p.h>
|
||||
#include <Qt3DRender/private/boundingsphere_p.h>
|
||||
|
||||
#include <QMatrix4x4>
|
||||
#include <QVector3D>
|
||||
|
|
@ -64,7 +64,7 @@ namespace Qt3DRender {
|
|||
|
||||
namespace Render {
|
||||
|
||||
class QT3DRENDERSHARED_PRIVATE_EXPORT Sphere : public QBoundingSphere
|
||||
class QT3DRENDERSHARED_PRIVATE_EXPORT Sphere : public RayCasting::BoundingSphere
|
||||
{
|
||||
public:
|
||||
inline Sphere(Qt3DCore::QNodeId i = Qt3DCore::QNodeId())
|
||||
|
|
@ -80,12 +80,12 @@ public:
|
|||
{}
|
||||
|
||||
void setCenter(const QVector3D &c);
|
||||
QVector3D center() const;
|
||||
QVector3D center() const Q_DECL_OVERRIDE;
|
||||
|
||||
inline bool isNull() { return m_center == QVector3D() && m_radius == 0.0f; }
|
||||
|
||||
void setRadius(float r);
|
||||
float radius() const;
|
||||
float radius() const Q_DECL_OVERRIDE;
|
||||
|
||||
void clear();
|
||||
void initializeFromPoints(const QVector<QVector3D> &points);
|
||||
|
|
@ -106,7 +106,7 @@ public:
|
|||
}
|
||||
|
||||
Qt3DCore::QNodeId id() const Q_DECL_FINAL;
|
||||
bool intersects(const QRay3D &ray, QVector3D *q) const Q_DECL_FINAL;
|
||||
bool intersects(const RayCasting::QRay3D &ray, QVector3D *q) const Q_DECL_FINAL;
|
||||
Type type() const Q_DECL_FINAL;
|
||||
|
||||
static Sphere fromPoints(const QVector<QVector3D> &points);
|
||||
|
|
|
|||
|
|
@ -209,13 +209,13 @@ void GeometryRenderer::unsetDirty()
|
|||
}
|
||||
|
||||
|
||||
void GeometryRenderer::setTriangleVolumes(const QVector<QBoundingVolume *> &volumes)
|
||||
void GeometryRenderer::setTriangleVolumes(const QVector<RayCasting::QBoundingVolume *> &volumes)
|
||||
{
|
||||
qDeleteAll(m_triangleVolumes);
|
||||
m_triangleVolumes = volumes;
|
||||
}
|
||||
|
||||
QVector<QBoundingVolume *> GeometryRenderer::triangleData() const
|
||||
QVector<RayCasting::QBoundingVolume *> GeometryRenderer::triangleData() const
|
||||
{
|
||||
return m_triangleVolumes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,8 +58,9 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
|
||||
namespace RayCasting {
|
||||
class QBoundingVolume;
|
||||
}
|
||||
|
||||
namespace Render {
|
||||
|
||||
|
|
@ -91,9 +92,9 @@ public:
|
|||
void unsetDirty();
|
||||
|
||||
// Build triangle data Job thread
|
||||
void setTriangleVolumes(const QVector<QBoundingVolume *> &volumes);
|
||||
void setTriangleVolumes(const QVector<RayCasting::QBoundingVolume *> &volumes);
|
||||
// Pick volumes job
|
||||
QVector<QBoundingVolume *> triangleData() const;
|
||||
QVector<RayCasting::QBoundingVolume *> triangleData() const;
|
||||
|
||||
private:
|
||||
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
|
||||
|
|
@ -111,7 +112,7 @@ private:
|
|||
bool m_dirty;
|
||||
QGeometryFactoryPtr m_geometryFactory;
|
||||
GeometryRendererManager *m_manager;
|
||||
QVector<QBoundingVolume *> m_triangleVolumes;
|
||||
QVector<RayCasting::QBoundingVolume *> m_triangleVolumes;
|
||||
};
|
||||
|
||||
class GeometryRendererFunctor : public Qt3DCore::QBackendNodeMapper
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
using namespace Qt3DRender::RayCasting;
|
||||
|
||||
namespace Render {
|
||||
|
||||
|
|
@ -128,16 +129,17 @@ void PickBoundingVolumeJob::setRenderSettings(RenderSettings *settings)
|
|||
m_renderSettings = settings;
|
||||
}
|
||||
|
||||
QRay3D PickBoundingVolumeJob::intersectionRay(const QPoint &pos, const QMatrix4x4 &viewMatrix, const QMatrix4x4 &projectionMatrix, const QRect &viewport)
|
||||
RayCasting::QRay3D PickBoundingVolumeJob::intersectionRay(const QPoint &pos, const QMatrix4x4 &viewMatrix,
|
||||
const QMatrix4x4 &projectionMatrix, const QRect &viewport)
|
||||
{
|
||||
QVector3D nearPos = QVector3D(pos.x(), pos.y(), 0.0f);
|
||||
nearPos = nearPos.unproject(viewMatrix, projectionMatrix, viewport);
|
||||
QVector3D farPos = QVector3D(pos.x(), pos.y(), 1.0f);
|
||||
farPos = farPos.unproject(viewMatrix, projectionMatrix, viewport);
|
||||
|
||||
return QRay3D(nearPos,
|
||||
(farPos - nearPos).normalized(),
|
||||
(farPos - nearPos).length());
|
||||
return RayCasting::QRay3D(nearPos,
|
||||
(farPos - nearPos).normalized(),
|
||||
(farPos - nearPos).length());
|
||||
}
|
||||
|
||||
bool PickBoundingVolumeJob::runHelper()
|
||||
|
|
@ -390,10 +392,10 @@ QRect PickBoundingVolumeJob::windowViewport(const QSize &area, const QRectF &rel
|
|||
return relativeViewport.toRect();
|
||||
}
|
||||
|
||||
QRay3D PickBoundingVolumeJob::rayForViewportAndCamera(const QSize &area,
|
||||
const QPoint &pos,
|
||||
const QRectF &relativeViewport,
|
||||
Qt3DCore::QNodeId cameraId) const
|
||||
RayCasting::QRay3D PickBoundingVolumeJob::rayForViewportAndCamera(const QSize &area,
|
||||
const QPoint &pos,
|
||||
const QRectF &relativeViewport,
|
||||
const Qt3DCore::QNodeId cameraId) const
|
||||
{
|
||||
QMatrix4x4 viewMatrix;
|
||||
QMatrix4x4 projectionMatrix;
|
||||
|
|
@ -402,7 +404,7 @@ QRay3D PickBoundingVolumeJob::rayForViewportAndCamera(const QSize &area,
|
|||
|
||||
// In GL the y is inverted compared to Qt
|
||||
const QPoint glCorrectPos = QPoint(pos.x(), area.isValid() ? area.height() - pos.y() : pos.y());
|
||||
const QRay3D ray = intersectionRay(glCorrectPos, viewMatrix, projectionMatrix, viewport);
|
||||
const auto ray = intersectionRay(glCorrectPos, viewMatrix, projectionMatrix, viewport);
|
||||
return ray;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,9 +68,6 @@ class QNodeId;
|
|||
}
|
||||
|
||||
namespace Qt3DRender {
|
||||
|
||||
class QAbstractCollisionQueryService;
|
||||
|
||||
namespace Render {
|
||||
|
||||
class Entity;
|
||||
|
|
@ -89,10 +86,10 @@ public:
|
|||
void setRenderSettings(RenderSettings *settings);
|
||||
void setManagers(NodeManagers *manager);
|
||||
|
||||
static QRay3D intersectionRay(const QPoint &pos,
|
||||
const QMatrix4x4 &viewMatrix,
|
||||
const QMatrix4x4 &projectionMatrix,
|
||||
const QRect &viewport);
|
||||
static RayCasting::QRay3D intersectionRay(const QPoint &pos,
|
||||
const QMatrix4x4 &viewMatrix,
|
||||
const QMatrix4x4 &projectionMatrix,
|
||||
const QRect &viewport);
|
||||
|
||||
// For unit tests
|
||||
inline HObjectPicker currentPicker() const { return m_currentPicker; }
|
||||
|
|
@ -117,10 +114,10 @@ private:
|
|||
QMatrix4x4 &viewMatrix,
|
||||
QMatrix4x4 &projectionMatrix) const;
|
||||
QRect windowViewport(const QSize &area, const QRectF &relativeViewport) const;
|
||||
QRay3D rayForViewportAndCamera(const QSize &area,
|
||||
const QPoint &pos,
|
||||
const QRectF &relativeViewport,
|
||||
Qt3DCore::QNodeId cameraId) const;
|
||||
RayCasting::QRay3D rayForViewportAndCamera(const QSize &area,
|
||||
const QPoint &pos,
|
||||
const QRectF &relativeViewport,
|
||||
const Qt3DCore::QNodeId cameraId) const;
|
||||
void clearPreviouslyHoveredPickers();
|
||||
HObjectPicker m_currentPicker;
|
||||
QVector<HObjectPicker> m_hoveredPickers;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
using namespace Qt3DRender::RayCasting;
|
||||
|
||||
namespace Render {
|
||||
|
||||
|
|
@ -204,12 +205,12 @@ AbstractCollisionGathererFunctor::result_type AbstractCollisionGathererFunctor::
|
|||
return result_type(); // don't bother picking entities that don't
|
||||
// have an object picker, or if it's disabled
|
||||
|
||||
Qt3DRender::QRayCastingService rayCasting;
|
||||
RayCasting::QRayCastingService rayCasting;
|
||||
|
||||
return pick(&rayCasting, entity);
|
||||
}
|
||||
|
||||
AbstractCollisionGathererFunctor::result_type EntityCollisionGathererFunctor::pick(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const
|
||||
AbstractCollisionGathererFunctor::result_type EntityCollisionGathererFunctor::pick(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const
|
||||
{
|
||||
result_type result;
|
||||
|
||||
|
|
@ -220,7 +221,7 @@ AbstractCollisionGathererFunctor::result_type EntityCollisionGathererFunctor::pi
|
|||
return result;
|
||||
}
|
||||
|
||||
AbstractCollisionGathererFunctor::result_type TriangleCollisionGathererFunctor::pick(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const
|
||||
AbstractCollisionGathererFunctor::result_type TriangleCollisionGathererFunctor::pick(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const
|
||||
{
|
||||
result_type result;
|
||||
|
||||
|
|
@ -246,7 +247,7 @@ AbstractCollisionGathererFunctor::result_type TriangleCollisionGathererFunctor::
|
|||
return result;
|
||||
}
|
||||
|
||||
bool TriangleCollisionGathererFunctor::rayHitsEntity(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const
|
||||
bool TriangleCollisionGathererFunctor::rayHitsEntity(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const
|
||||
{
|
||||
const QCollisionQueryResult::Hit queryResult = rayCasting->query(m_ray, entity->worldBoundingVolume());
|
||||
return queryResult.m_distance >= 0.f;
|
||||
|
|
|
|||
|
|
@ -59,8 +59,9 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
|
||||
namespace RayCasting {
|
||||
class QAbstractCollisionQueryService;
|
||||
}
|
||||
|
||||
namespace Render {
|
||||
|
||||
|
|
@ -107,10 +108,11 @@ private:
|
|||
class Q_AUTOTEST_EXPORT CollisionVisitor : public TrianglesVisitor
|
||||
{
|
||||
public:
|
||||
typedef QVector<QCollisionQueryResult::Hit> HitList;
|
||||
typedef QVector<RayCasting::QCollisionQueryResult::Hit> HitList;
|
||||
HitList hits;
|
||||
|
||||
CollisionVisitor(NodeManagers* manager, const Entity *root, const QRay3D& ray, bool frontFaceRequested, bool backFaceRequested)
|
||||
CollisionVisitor(NodeManagers* manager, const Entity *root, const RayCasting::QRay3D& ray,
|
||||
bool frontFaceRequested, bool backFaceRequested)
|
||||
: TrianglesVisitor(manager), m_root(root), m_ray(ray), m_triangleIndex(0)
|
||||
, m_frontFaceRequested(frontFaceRequested), m_backFaceRequested(backFaceRequested)
|
||||
{
|
||||
|
|
@ -118,7 +120,7 @@ public:
|
|||
|
||||
private:
|
||||
const Entity *m_root;
|
||||
QRay3D m_ray;
|
||||
RayCasting::QRay3D m_ray;
|
||||
uint m_triangleIndex;
|
||||
bool m_frontFaceRequested;
|
||||
bool m_backFaceRequested;
|
||||
|
|
@ -137,17 +139,17 @@ struct Q_AUTOTEST_EXPORT AbstractCollisionGathererFunctor
|
|||
virtual ~AbstractCollisionGathererFunctor();
|
||||
|
||||
NodeManagers *m_manager;
|
||||
QRay3D m_ray;
|
||||
RayCasting::QRay3D m_ray;
|
||||
|
||||
// This define is required to work with QtConcurrent
|
||||
typedef CollisionVisitor::HitList result_type;
|
||||
result_type operator ()(const Entity *entity) const;
|
||||
virtual result_type pick(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const = 0;
|
||||
virtual result_type pick(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const = 0;
|
||||
};
|
||||
|
||||
struct Q_AUTOTEST_EXPORT EntityCollisionGathererFunctor : public AbstractCollisionGathererFunctor
|
||||
{
|
||||
result_type pick(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const Q_DECL_OVERRIDE;
|
||||
result_type pick(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
struct Q_AUTOTEST_EXPORT TriangleCollisionGathererFunctor : public AbstractCollisionGathererFunctor
|
||||
|
|
@ -155,9 +157,9 @@ struct Q_AUTOTEST_EXPORT TriangleCollisionGathererFunctor : public AbstractColli
|
|||
bool m_frontFaceRequested;
|
||||
bool m_backFaceRequested;
|
||||
|
||||
result_type pick(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const Q_DECL_OVERRIDE;
|
||||
result_type pick(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const Q_DECL_OVERRIDE;
|
||||
|
||||
bool rayHitsEntity(QAbstractCollisionQueryService *rayCasting, const Entity *entity) const;
|
||||
bool rayHitsEntity(RayCasting::QAbstractCollisionQueryService *rayCasting, const Entity *entity) const;
|
||||
};
|
||||
|
||||
Q_AUTOTEST_EXPORT QVector<Entity *> gatherEntities(Entity *entity, QVector<Entity *> entities);
|
||||
|
|
|
|||
|
|
@ -37,20 +37,22 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qboundingsphere_p.h"
|
||||
#include "boundingsphere_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
QBoundingSphere::QBoundingSphere()
|
||||
BoundingSphere::BoundingSphere()
|
||||
{
|
||||
}
|
||||
|
||||
QBoundingSphere::~QBoundingSphere()
|
||||
BoundingSphere::~BoundingSphere()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -37,8 +37,8 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QT3DRENDER_QBOUNDINGSPHERE_P_H
|
||||
#define QT3DRENDER_QBOUNDINGSPHERE_P_H
|
||||
#ifndef QT3DRENDER_BOUNDINGSPHERE_P_H
|
||||
#define QT3DRENDER_BOUNDINGSPHERE_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
|
|
@ -57,19 +57,21 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
class QT3DRENDERSHARED_EXPORT QBoundingSphere : public QBoundingVolume
|
||||
class QT3DRENDERSHARED_EXPORT BoundingSphere : public QBoundingVolume
|
||||
{
|
||||
public:
|
||||
QBoundingSphere();
|
||||
~QBoundingSphere();
|
||||
BoundingSphere();
|
||||
~BoundingSphere();
|
||||
|
||||
virtual QVector3D center() const = 0;
|
||||
virtual float radius() const = 0;
|
||||
};
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT3DRENDER_QBOUNDINGSPHERE_P_H
|
||||
#endif // QT3DRENDER_BOUNDINGSPHERE_P_H
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
QAbstractCollisionQueryService::QAbstractCollisionQueryService(const QString &description)
|
||||
: QAbstractServiceProvider(*new QAbstractCollisionQueryServicePrivate(description))
|
||||
|
|
@ -65,6 +66,7 @@ void QAbstractCollisionQueryService::addEntityHit(QCollisionQueryResult &result,
|
|||
result.d_func()->addEntityHit(entity, intersection, distance);
|
||||
}
|
||||
|
||||
} // RayCasting
|
||||
} // Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
class QAbstractCollisionQueryServicePrivate;
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
class QRay3D;
|
||||
class QBoundingVolume;
|
||||
|
|
@ -101,10 +102,11 @@ private:
|
|||
Q_DECLARE_PRIVATE(QAbstractCollisionQueryService)
|
||||
};
|
||||
|
||||
} // RayCasting
|
||||
} // Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(Qt3DRender::QAbstractCollisionQueryService::QueryMode) // LCOV_EXCL_LINE
|
||||
Q_DECLARE_METATYPE(Qt3DRender::RayCasting::QAbstractCollisionQueryService::QueryMode) // LCOV_EXCL_LINE
|
||||
|
||||
#endif // QT3DRENDER_QABSTRACTCOLLISIONQUERYSERVICE_P_H
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
QBoundingVolume::QBoundingVolume()
|
||||
{
|
||||
|
|
@ -51,6 +52,7 @@ QBoundingVolume::~QBoundingVolume()
|
|||
{
|
||||
}
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
class QRay3D;
|
||||
|
||||
class QT3DRENDERSHARED_EXPORT QBoundingVolume
|
||||
|
|
@ -75,10 +77,11 @@ public:
|
|||
virtual Type type() const = 0;
|
||||
};
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(Qt3DRender::QBoundingVolume*) // LCOV_EXCL_LINE
|
||||
Q_DECLARE_METATYPE(Qt3DRender::RayCasting::QBoundingVolume*) // LCOV_EXCL_LINE
|
||||
|
||||
#endif // QT3DRENDER_QBOUNDINGVOLUME_P_H
|
||||
|
|
|
|||
|
|
@ -43,13 +43,14 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
QBoundingVolumeProvider::~QBoundingVolumeProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // RayCasting
|
||||
} // Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
class QBoundingVolume;
|
||||
|
||||
|
|
@ -66,6 +67,7 @@ public:
|
|||
virtual QVector<QBoundingVolume *> boundingVolumes() const = 0;
|
||||
};
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
QCollisionQueryResultPrivate::QCollisionQueryResultPrivate()
|
||||
: QSharedData()
|
||||
|
|
@ -122,6 +123,7 @@ QQueryHandle QCollisionQueryResult::handle() const
|
|||
return d->m_handle;
|
||||
}
|
||||
|
||||
} // RayCasting
|
||||
} // Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
typedef int QQueryHandle;
|
||||
class QCollisionQueryResultPrivate;
|
||||
|
|
@ -69,7 +70,7 @@ class QT3DRENDERSHARED_EXPORT QCollisionQueryResult
|
|||
public:
|
||||
struct Hit {
|
||||
Hit() : m_distance(-1.f), m_triangleIndex(0) { m_vertexIndex[0] = m_vertexIndex[1] = m_vertexIndex[2] = 0; }
|
||||
Hit(Qt3DCore::QNodeId entity, const QVector3D &intersection, float distance) : m_entityId(entity), m_intersection(intersection), m_distance(distance) { }
|
||||
Hit(const Qt3DCore::QNodeId &entity, const QVector3D &intersection, float distance) : m_entityId(entity), m_intersection(intersection), m_distance(distance) { }
|
||||
Qt3DCore::QNodeId m_entityId;
|
||||
QVector3D m_intersection;
|
||||
float m_distance;
|
||||
|
|
@ -112,8 +113,8 @@ private:
|
|||
return d_ptr.constData();
|
||||
}
|
||||
};
|
||||
QT3D_DECLARE_TYPEINFO(Qt3DRender, QCollisionQueryResult::Hit, Q_PRIMITIVE_TYPE)
|
||||
QT3D_DECLARE_SHARED(Qt3DRender, QCollisionQueryResult)
|
||||
QT3D_DECLARE_TYPEINFO_2(Qt3DRender, RayCasting, QCollisionQueryResult::Hit, Q_PRIMITIVE_TYPE)
|
||||
QT3D_DECLARE_SHARED_2(Qt3DRender, RayCasting, QCollisionQueryResult)
|
||||
|
||||
class QCollisionQueryResultPrivate : public QSharedData
|
||||
{
|
||||
|
|
@ -133,6 +134,7 @@ inline bool operator==(const QCollisionQueryResult::Hit& left, const QCollisionQ
|
|||
return left.m_entityId == right.m_entityId;
|
||||
}
|
||||
|
||||
} // RayCasting
|
||||
} // Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
/*!
|
||||
\class Qt3DRender::QRay3D
|
||||
|
|
@ -371,6 +372,7 @@ QDataStream &operator>>(QDataStream &stream, QRay3D &ray)
|
|||
|
||||
#endif // QT_NO_DATASTREAM
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
class QT3DRENDERSHARED_EXPORT QRay3D
|
||||
{
|
||||
|
|
@ -97,7 +98,7 @@ private:
|
|||
QVector3D m_direction;
|
||||
float m_distance;
|
||||
};
|
||||
QT3D_DECLARE_TYPEINFO(Qt3DRender, QRay3D, Q_MOVABLE_TYPE)
|
||||
QT3D_DECLARE_TYPEINFO_2(Qt3DRender, RayCasting, QRay3D, Q_MOVABLE_TYPE)
|
||||
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
|
@ -109,15 +110,16 @@ QT3DRENDERSHARED_EXPORT QDataStream &operator<<(QDataStream &stream, const QRay3
|
|||
QT3DRENDERSHARED_EXPORT QDataStream &operator>>(QDataStream &stream, QRay3D &ray);
|
||||
#endif
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
QT_END_NAMESPACE
|
||||
|
||||
inline bool qFuzzyCompare(const Qt3DRender::QRay3D &ray1, const Qt3DRender::QRay3D &ray2)
|
||||
inline bool qFuzzyCompare(const Qt3DRender::RayCasting::QRay3D &ray1, const Qt3DRender::RayCasting::QRay3D &ray2)
|
||||
{
|
||||
return qFuzzyCompare(ray1.origin(), ray2.origin()) &&
|
||||
qFuzzyCompare(ray1.direction(), ray2.direction());
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Qt3DRender::QRay3D) // LCOV_EXCL_LINE
|
||||
Q_DECLARE_METATYPE(Qt3DRender::RayCasting::QRay3D) // LCOV_EXCL_LINE
|
||||
|
||||
#endif // QT3DRENDER_QRAY3D_H
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE
|
|||
using namespace Qt3DCore;
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
@ -144,7 +145,7 @@ QCollisionQueryResult QRayCastingServicePrivate::collides(const QRay3D &ray, QBo
|
|||
return result;
|
||||
}
|
||||
|
||||
QCollisionQueryResult::Hit QRayCastingServicePrivate::collides(const QRay3D &ray, const Qt3DRender::QBoundingVolume *volume)
|
||||
QCollisionQueryResult::Hit QRayCastingServicePrivate::collides(const QRay3D &ray, const QBoundingVolume *volume)
|
||||
{
|
||||
QCollisionQueryResult::Hit result;
|
||||
Hit hit = volumeRayIntersection(volume, ray);
|
||||
|
|
@ -213,6 +214,7 @@ QVector<QCollisionQueryResult> QRayCastingService::fetchAllResults() const
|
|||
return results;
|
||||
}
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DRender {
|
||||
namespace RayCasting {
|
||||
|
||||
class QBoundingVolumeProvider;
|
||||
class QRayCastingServicePrivate;
|
||||
|
|
@ -112,6 +113,7 @@ public:
|
|||
QAtomicInt m_handlesCount;
|
||||
};
|
||||
|
||||
} // namespace RayCasting
|
||||
} // namespace Qt3DRender
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ INCLUDEPATH += $$PWD
|
|||
|
||||
HEADERS += \
|
||||
$$PWD/qabstractcollisionqueryservice_p.h \
|
||||
$$PWD/qboundingsphere_p.h \
|
||||
$$PWD/boundingsphere_p.h \
|
||||
$$PWD/qboundingvolume_p.h \
|
||||
$$PWD/qboundingvolumeprovider_p.h \
|
||||
$$PWD/qcollisionqueryresult_p.h \
|
||||
|
|
@ -11,7 +11,7 @@ HEADERS += \
|
|||
|
||||
SOURCES += \
|
||||
$$PWD/qabstractcollisionqueryservice.cpp \
|
||||
$$PWD/qboundingsphere.cpp \
|
||||
$$PWD/boundingsphere.cpp \
|
||||
$$PWD/qboundingvolume.cpp \
|
||||
$$PWD/qboundingvolumeprovider.cpp \
|
||||
$$PWD/qcollisionqueryresult.cpp \
|
||||
|
|
|
|||
|
|
@ -131,11 +131,11 @@ void tst_QRay3D::create()
|
|||
{
|
||||
QFETCH(QVector3D, point);
|
||||
QFETCH(QVector3D, direction);
|
||||
Qt3DRender::QRay3D ray(point, direction);
|
||||
Qt3DRender::RayCasting::QRay3D ray(point, direction);
|
||||
QVERIFY(fuzzyCompare(ray.direction(), direction));
|
||||
QVERIFY(fuzzyCompare(ray.origin(), point));
|
||||
|
||||
Qt3DRender::QRay3D ray2;
|
||||
Qt3DRender::RayCasting::QRay3D ray2;
|
||||
QCOMPARE(ray2.origin(), QVector3D(0, 0, 0));
|
||||
QCOMPARE(ray2.direction(), QVector3D(0, 0, 1));
|
||||
ray2.setOrigin(point);
|
||||
|
|
@ -188,7 +188,7 @@ void tst_QRay3D::projection()
|
|||
QFETCH(QVector3D, direction);
|
||||
QFETCH(QVector3D, vector);
|
||||
QFETCH(QVector3D, expected);
|
||||
Qt3DRender::QRay3D line(point, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line(point, direction);
|
||||
QVector3D result = line.project(vector);
|
||||
QVERIFY(fuzzyCompare(result, expected));
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ void tst_QRay3D::point()
|
|||
QFETCH(QVector3D, direction);
|
||||
QFETCH(QVector3D, point_on_line_pos_0_6);
|
||||
QFETCH(QVector3D, point_on_line_neg_7_2);
|
||||
Qt3DRender::QRay3D line(point, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line(point, direction);
|
||||
QVERIFY(fuzzyCompare(line.point(0.6f), point_on_line_pos_0_6));
|
||||
QVERIFY(fuzzyCompare(line.point(-7.2f), point_on_line_neg_7_2));
|
||||
QVERIFY(fuzzyCompare(line.projectedDistance(point_on_line_pos_0_6), 0.6f));
|
||||
|
|
@ -327,7 +327,7 @@ void tst_QRay3D::contains_point()
|
|||
QFETCH(QVector3D, point);
|
||||
QFETCH(bool, contains);
|
||||
|
||||
Qt3DRender::QRay3D line(origin, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line(origin, direction);
|
||||
QCOMPARE(line.contains(point), contains);
|
||||
}
|
||||
|
||||
|
|
@ -343,23 +343,23 @@ void tst_QRay3D::contains_ray()
|
|||
QFETCH(QVector3D, point);
|
||||
QFETCH(bool, contains);
|
||||
|
||||
Qt3DRender::QRay3D line(origin, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line(origin, direction);
|
||||
if (contains) {
|
||||
Qt3DRender::QRay3D line2(point, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line2(point, direction);
|
||||
QVERIFY(line.contains(line2));
|
||||
QVERIFY(line2.contains(line));
|
||||
|
||||
// Reversed direction is also contained.
|
||||
Qt3DRender::QRay3D line3(point, -direction);
|
||||
Qt3DRender::RayCasting::QRay3D line3(point, -direction);
|
||||
QVERIFY(line.contains(line2));
|
||||
QVERIFY(line2.contains(line));
|
||||
|
||||
// Different direction.
|
||||
Qt3DRender::QRay3D line4(point, QVector3D(direction.y(), direction.x(), direction.z()));
|
||||
Qt3DRender::RayCasting::QRay3D line4(point, QVector3D(direction.y(), direction.x(), direction.z()));
|
||||
QVERIFY(!line.contains(line4));
|
||||
QVERIFY(!line4.contains(line));
|
||||
} else {
|
||||
Qt3DRender::QRay3D line2(point, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line2(point, direction);
|
||||
QVERIFY(!line.contains(line2));
|
||||
QVERIFY(!line2.contains(line));
|
||||
}
|
||||
|
|
@ -404,15 +404,15 @@ void tst_QRay3D::distance()
|
|||
QFETCH(QVector3D, point);
|
||||
QFETCH(float, distance);
|
||||
|
||||
Qt3DRender::QRay3D line(origin, direction);
|
||||
Qt3DRender::RayCasting::QRay3D line(origin, direction);
|
||||
QCOMPARE(line.distance(point), distance);
|
||||
}
|
||||
|
||||
void tst_QRay3D::compare()
|
||||
{
|
||||
Qt3DRender::QRay3D ray1(QVector3D(10, 20, 30), QVector3D(-3, -4, -5));
|
||||
Qt3DRender::QRay3D ray2(QVector3D(10, 20, 30), QVector3D(1.5f, 2.0f, 2.5f));
|
||||
Qt3DRender::QRay3D ray3(QVector3D(0, 20, 30), QVector3D(-3, -4, -5));
|
||||
Qt3DRender::RayCasting::QRay3D ray1(QVector3D(10, 20, 30), QVector3D(-3, -4, -5));
|
||||
Qt3DRender::RayCasting::QRay3D ray2(QVector3D(10, 20, 30), QVector3D(1.5f, 2.0f, 2.5f));
|
||||
Qt3DRender::RayCasting::QRay3D ray3(QVector3D(0, 20, 30), QVector3D(-3, -4, -5));
|
||||
QVERIFY(ray1 == ray1);
|
||||
QVERIFY(!(ray1 != ray1));
|
||||
QVERIFY(qFuzzyCompare(ray1, ray1));
|
||||
|
|
@ -427,7 +427,7 @@ void tst_QRay3D::compare()
|
|||
void tst_QRay3D::dataStream()
|
||||
{
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
Qt3DRender::QRay3D ray(QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f));
|
||||
Qt3DRender::RayCasting::QRay3D ray(QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f));
|
||||
|
||||
QByteArray data;
|
||||
{
|
||||
|
|
@ -435,7 +435,7 @@ void tst_QRay3D::dataStream()
|
|||
stream << ray;
|
||||
}
|
||||
|
||||
Qt3DRender::QRay3D ray2;
|
||||
Qt3DRender::RayCasting::QRay3D ray2;
|
||||
{
|
||||
QDataStream stream2(data);
|
||||
stream2 >> ray2;
|
||||
|
|
@ -460,9 +460,9 @@ void tst_QRay3D::transform()
|
|||
m.rotate(45.0f, 1.0f, 1.0f, 1.0f);
|
||||
m.scale(23.5f);
|
||||
|
||||
Qt3DRender::QRay3D ray1(point, direction);
|
||||
Qt3DRender::QRay3D ray2(ray1);
|
||||
Qt3DRender::QRay3D ray3;
|
||||
Qt3DRender::RayCasting::QRay3D ray1(point, direction);
|
||||
Qt3DRender::RayCasting::QRay3D ray2(ray1);
|
||||
Qt3DRender::RayCasting::QRay3D ray3;
|
||||
|
||||
ray1.transform(m);
|
||||
ray3 = ray2.transformed(m);
|
||||
|
|
@ -477,15 +477,15 @@ void tst_QRay3D::transform()
|
|||
class tst_QRay3DProperties : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Qt3DRender::QRay3D ray READ ray WRITE setRay)
|
||||
Q_PROPERTY(Qt3DRender::RayCasting::QRay3D ray READ ray WRITE setRay)
|
||||
public:
|
||||
tst_QRay3DProperties(QObject *parent = 0) : QObject(parent) {}
|
||||
|
||||
Qt3DRender::QRay3D ray() const { return r; }
|
||||
void setRay(const Qt3DRender::QRay3D& value) { r = value; }
|
||||
Qt3DRender::RayCasting::QRay3D ray() const { return r; }
|
||||
void setRay(const Qt3DRender::RayCasting::QRay3D& value) { r = value; }
|
||||
|
||||
private:
|
||||
Qt3DRender::QRay3D r;
|
||||
Qt3DRender::RayCasting::QRay3D r;
|
||||
};
|
||||
|
||||
// Test getting and setting properties via the metaobject system.
|
||||
|
|
@ -493,35 +493,35 @@ void tst_QRay3D::properties()
|
|||
{
|
||||
tst_QRay3DProperties obj;
|
||||
|
||||
qRegisterMetaType<Qt3DRender::QRay3D>();
|
||||
qRegisterMetaType<Qt3DRender::RayCasting::QRay3D>();
|
||||
|
||||
obj.setRay(Qt3DRender::QRay3D(QVector3D(1, 2, 3), QVector3D(4, 5, 6)));
|
||||
obj.setRay(Qt3DRender::RayCasting::QRay3D(QVector3D(1, 2, 3), QVector3D(4, 5, 6)));
|
||||
|
||||
Qt3DRender::QRay3D r = qvariant_cast<Qt3DRender::QRay3D>(obj.property("ray"));
|
||||
Qt3DRender::RayCasting::QRay3D r = qvariant_cast<Qt3DRender::RayCasting::QRay3D>(obj.property("ray"));
|
||||
QCOMPARE(r.origin(), QVector3D(1, 2, 3));
|
||||
QCOMPARE(r.direction(), QVector3D(4, 5, 6));
|
||||
|
||||
obj.setProperty("ray",
|
||||
qVariantFromValue
|
||||
(Qt3DRender::QRay3D(QVector3D(-1, -2, -3), QVector3D(-4, -5, -6))));
|
||||
(Qt3DRender::RayCasting::QRay3D(QVector3D(-1, -2, -3), QVector3D(-4, -5, -6))));
|
||||
|
||||
r = qvariant_cast<Qt3DRender::QRay3D>(obj.property("ray"));
|
||||
r = qvariant_cast<Qt3DRender::RayCasting::QRay3D>(obj.property("ray"));
|
||||
QCOMPARE(r.origin(), QVector3D(-1, -2, -3));
|
||||
QCOMPARE(r.direction(), QVector3D(-4, -5, -6));
|
||||
}
|
||||
|
||||
void tst_QRay3D::metaTypes()
|
||||
{
|
||||
int id = qMetaTypeId<Qt3DRender::QRay3D>();
|
||||
QVERIFY(QMetaType::type("Qt3DRender::QRay3D") == id);
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("Qt3DRender::QRay3D"));
|
||||
int id = qMetaTypeId<Qt3DRender::RayCasting::QRay3D>();
|
||||
QVERIFY(QMetaType::type("Qt3DRender::RayCasting::QRay3D") == id);
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("Qt3DRender::RayCasting::QRay3D"));
|
||||
QVERIFY(QMetaType::isRegistered(id));
|
||||
}
|
||||
|
||||
void tst_QRay3D::shouldNotAllowNullDirection()
|
||||
{
|
||||
// GIVEN
|
||||
Qt3DRender::QRay3D ray;
|
||||
Qt3DRender::RayCasting::QRay3D ray;
|
||||
|
||||
QCOMPARE(ray.origin(), QVector3D(0, 0, 0));
|
||||
QCOMPARE(ray.direction(), QVector3D(0, 0, 1));
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
using namespace Qt3DCore;
|
||||
using namespace Qt3DRender;
|
||||
using namespace Qt3DRender::Render;
|
||||
using namespace Qt3DRender::RayCasting;
|
||||
|
||||
class tst_RayCasting : public QObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ private Q_SLOTS:
|
|||
QCOMPARE(volume.a(), QVector3D());
|
||||
QCOMPARE(volume.b(), QVector3D());
|
||||
QCOMPARE(volume.c(), QVector3D());
|
||||
QCOMPARE(volume.type(), Qt3DRender::QBoundingVolume::Triangle);
|
||||
QCOMPARE(volume.type(), Qt3DRender::RayCasting::QBoundingVolume::Triangle);
|
||||
}
|
||||
|
||||
void transformed_data()
|
||||
|
|
@ -124,7 +124,7 @@ private Q_SLOTS:
|
|||
|
||||
void intersects_data()
|
||||
{
|
||||
QTest::addColumn<Qt3DRender::QRay3D>("ray");
|
||||
QTest::addColumn<Qt3DRender::RayCasting::QRay3D>("ray");
|
||||
QTest::addColumn<QVector3D>("a");
|
||||
QTest::addColumn<QVector3D>("b");
|
||||
QTest::addColumn<QVector3D>("c");
|
||||
|
|
@ -135,7 +135,7 @@ private Q_SLOTS:
|
|||
const float farPlaneDistance = 40.0;
|
||||
|
||||
QTest::newRow("halfway_center")
|
||||
<< Qt3DRender::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), farPlaneDistance)
|
||||
<< Qt3DRender::RayCasting::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), farPlaneDistance)
|
||||
<< QVector3D(3.0, 1.5, 20.0)
|
||||
<< QVector3D(0.0, -1.5, 20.0)
|
||||
<< QVector3D(-3, 1.5, 20.0)
|
||||
|
|
@ -143,7 +143,7 @@ private Q_SLOTS:
|
|||
<< 0.5f
|
||||
<< true;
|
||||
QTest::newRow("miss_halfway_center_too_short")
|
||||
<< Qt3DRender::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), farPlaneDistance * 0.25f)
|
||||
<< Qt3DRender::RayCasting::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), farPlaneDistance * 0.25f)
|
||||
<< QVector3D(3.0, 1.5, 20.0)
|
||||
<< QVector3D(0.0, -1.5, 20.0)
|
||||
<< QVector3D(-3, 1.5, 20.0)
|
||||
|
|
@ -151,7 +151,7 @@ private Q_SLOTS:
|
|||
<< 0.0f
|
||||
<< false;
|
||||
QTest::newRow("far_center")
|
||||
<< Qt3DRender::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), farPlaneDistance)
|
||||
<< Qt3DRender::RayCasting::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), farPlaneDistance)
|
||||
<< QVector3D(3.0, 1.5, 40.0)
|
||||
<< QVector3D(0.0, -1.5, 40.0)
|
||||
<< QVector3D(-3, 1.5, 40.0)
|
||||
|
|
@ -159,7 +159,7 @@ private Q_SLOTS:
|
|||
<< 1.0f
|
||||
<< true;
|
||||
QTest::newRow("near_center")
|
||||
<< Qt3DRender::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), 1.0f)
|
||||
<< Qt3DRender::RayCasting::QRay3D(QVector3D(), QVector3D(0.0, 0.0, 1.0), 1.0f)
|
||||
<< QVector3D(3.0, 1.5, 0.0)
|
||||
<< QVector3D(0.0, -1.5, 0.0)
|
||||
<< QVector3D(-3, 1.5, 0.0)
|
||||
|
|
@ -167,7 +167,7 @@ private Q_SLOTS:
|
|||
<< 0.0f
|
||||
<< true;
|
||||
QTest::newRow("above_miss_center")
|
||||
<< Qt3DRender::QRay3D(QVector3D(0.0, 2.0, 0.0), QVector3D(0.0, 2.0, 1.0), 1.0f)
|
||||
<< Qt3DRender::RayCasting::QRay3D(QVector3D(0.0, 2.0, 0.0), QVector3D(0.0, 2.0, 1.0), 1.0f)
|
||||
<< QVector3D(3.0, 1.5, 0.0)
|
||||
<< QVector3D(0.0, -1.5, 0.0)
|
||||
<< QVector3D(-3, 1.5, 0.0)
|
||||
|
|
@ -175,7 +175,7 @@ private Q_SLOTS:
|
|||
<< 0.0f
|
||||
<< false;
|
||||
QTest::newRow("below_miss_center")
|
||||
<< Qt3DRender::QRay3D(QVector3D(0.0, -2.0, 0.0), QVector3D(0.0, -2.0, 1.0), 1.0f)
|
||||
<< Qt3DRender::RayCasting::QRay3D(QVector3D(0.0, -2.0, 0.0), QVector3D(0.0, -2.0, 1.0), 1.0f)
|
||||
<< QVector3D(3.0, 1.5, 0.0)
|
||||
<< QVector3D(0.0, -1.5, 0.0)
|
||||
<< QVector3D(-3, 1.5, 0.0)
|
||||
|
|
@ -187,7 +187,7 @@ private Q_SLOTS:
|
|||
void intersects()
|
||||
{
|
||||
// GIVEN
|
||||
QFETCH(Qt3DRender::QRay3D, ray);
|
||||
QFETCH(Qt3DRender::RayCasting::QRay3D, ray);
|
||||
QFETCH(QVector3D, a);
|
||||
QFETCH(QVector3D, b);
|
||||
QFETCH(QVector3D, c);
|
||||
|
|
|
|||
|
|
@ -378,14 +378,14 @@ private Q_SLOTS:
|
|||
|
||||
// WHEN
|
||||
Qt3DRender::Render::TrianglesExtractor extractor(bGeomRenderer, manager);
|
||||
QVector<Qt3DRender::QBoundingVolume *> volumes = extractor.extract(Qt3DCore::QNodeId());
|
||||
QVector<Qt3DRender::RayCasting::QBoundingVolume *> volumes = extractor.extract(Qt3DCore::QNodeId());
|
||||
|
||||
// THEN
|
||||
QVERIFY(!volumes.empty());
|
||||
QCOMPARE(volumes.size(), expectedVolumes.size());
|
||||
for (int i = 0, m = volumes.size(); i < m; ++i) {
|
||||
const Qt3DRender::Render::TriangleBoundingVolume *expectedVolume = expectedVolumes.at(i);
|
||||
const Qt3DRender::Render::TriangleBoundingVolume *actualVolume = static_cast<Qt3DRender::Render::TriangleBoundingVolume *>(volumes.at(i));
|
||||
const auto *expectedVolume = expectedVolumes.at(i);
|
||||
const auto *actualVolume = static_cast<Qt3DRender::Render::TriangleBoundingVolume *>(volumes.at(i));
|
||||
|
||||
QCOMPARE(expectedVolume->id(), actualVolume->id());
|
||||
QCOMPARE(expectedVolume->a(), actualVolume->a());
|
||||
|
|
|
|||
Loading…
Reference in New Issue