diff options
Diffstat (limited to 'src/render/frontend')
-rw-r--r-- | src/render/frontend/qcomputecommand.cpp | 2 | ||||
-rw-r--r-- | src/render/frontend/qrenderaspect.cpp | 1 | ||||
-rw-r--r-- | src/render/frontend/qrenderaspect_p.h | 2 | ||||
-rw-r--r-- | src/render/frontend/sphere.cpp | 50 | ||||
-rw-r--r-- | src/render/frontend/sphere_p.h | 13 |
5 files changed, 58 insertions, 10 deletions
diff --git a/src/render/frontend/qcomputecommand.cpp b/src/render/frontend/qcomputecommand.cpp index d040150d5..d0c9f5805 100644 --- a/src/render/frontend/qcomputecommand.cpp +++ b/src/render/frontend/qcomputecommand.cpp @@ -66,7 +66,7 @@ namespace Qt3DRender { /*! \qmltype ComputeCommand \since 5.7 - \inmodule Qt3DRender + \inqmlmodule Qt3D.Render \inherits Component3D \instantiates Qt3DRender::QComputeCommand \brief Component to issue work for the compute shader on GPU. diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp index 159c11981..271eb9c11 100644 --- a/src/render/frontend/qrenderaspect.cpp +++ b/src/render/frontend/qrenderaspect.cpp @@ -562,6 +562,7 @@ void QRenderAspect::onRegistered() // TO DO: Load proper Renderer class based on Qt configuration preferences d->m_renderer = new Render::Renderer(d->m_renderType); + d->m_renderer->setScreen(d->m_screen); d->m_renderer->setNodeManagers(d->m_nodeManagers); // Create a helper for deferring creation of an offscreen surface used during cleanup diff --git a/src/render/frontend/qrenderaspect_p.h b/src/render/frontend/qrenderaspect_p.h index 8ef4ecd12..62e373b11 100644 --- a/src/render/frontend/qrenderaspect_p.h +++ b/src/render/frontend/qrenderaspect_p.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QSurface; +class QScreen; namespace Qt3DRender { @@ -106,6 +107,7 @@ public: QVector<Render::QRenderPlugin *> m_renderPlugins; QRenderAspect::RenderType m_renderType; Render::OffscreenSurfaceHelper *m_offscreenHelper; + QScreen *m_screen = nullptr; static QMutex m_pluginLock; static QVector<QString> m_pluginConfig; diff --git a/src/render/frontend/sphere.cpp b/src/render/frontend/sphere.cpp index 4909acaef..470dbfe59 100644 --- a/src/render/frontend/sphere.cpp +++ b/src/render/frontend/sphere.cpp @@ -44,6 +44,7 @@ #include <QPair> #include <math.h> +#include <algorithm> QT_BEGIN_NAMESPACE @@ -55,6 +56,9 @@ namespace { // returns true and intersection point q; false otherwise bool intersectRaySphere(const Qt3DRender::RayCasting::QRay3D &ray, const Qt3DRender::Render::Sphere &s, Vector3D *q = nullptr) { + if (s.isNull()) + return false; + const Vector3D p = ray.origin(); const Vector3D d = ray.direction(); const Vector3D m = p - s.center(); @@ -139,11 +143,31 @@ inline void sphereFromExtremePoints(Qt3DRender::Render::Sphere &s, const QVector inline void constructRitterSphere(Qt3DRender::Render::Sphere &s, const QVector<Vector3D> &points) { - // Calculate the sphere encompassing two axially extreme points - sphereFromExtremePoints(s, points); - - // Now make sure the sphere bounds all points by growing if needed - s.expandToContain(points); + //def bounding_sphere(points): + // dist = lambda a,b: ((a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2)**0.5 + // x = points[0] + // y = max(points,key= lambda p: dist(p,x) ) + // z = max(points,key= lambda p: dist(p,y) ) + // bounding_sphere = (((y[0]+z[0])/2,(y[1]+z[1])/2,(y[2]+z[2])/2), dist(y,z)/2) + // + // exterior_points = [p for p in points if dist(p,bounding_sphere[0]) > bounding_sphere[1] ] + // while ( len(exterior_points) > 0 ): + // pt = exterior_points.pop() + // if (dist(pt, bounding_sphere[0]) > bounding_sphere[1]): + // bounding_sphere = (bounding_sphere[0],dist(pt,bounding_sphere[0])) + // + // return bounding_sphere + + const Vector3D x = points[0]; + const Vector3D y = *std::max_element(points.begin(), points.end(), [&x](const Vector3D& lhs, const Vector3D& rhs){ return (lhs - x).lengthSquared() < (rhs - x).lengthSquared(); }); + const Vector3D z = *std::max_element(points.begin(), points.end(), [&y](const Vector3D& lhs, const Vector3D& rhs){ return (lhs - y).lengthSquared() < (rhs - y).lengthSquared(); }); + + const Vector3D center = (y + z) * 0.5f; + const Vector3D maxDistPt = *std::max_element(points.begin(), points.end(), [¢er](const Vector3D& lhs, const Vector3D& rhs){ return (lhs - center).lengthSquared() < (rhs - center).lengthSquared(); }); + const float radius = (maxDistPt - center).length(); + + s.setCenter(center); + s.setRadius(radius); } } // anonymous namespace @@ -169,6 +193,12 @@ void Sphere::initializeFromPoints(const QVector<Vector3D> &points) void Sphere::expandToContain(const Vector3D &p) { + if (isNull()) { + m_center = p; + m_radius = 0.0f; + return; + } + const Vector3D d = p - m_center; const float dist2 = d.lengthSquared(); @@ -184,6 +214,13 @@ void Sphere::expandToContain(const Vector3D &p) void Sphere::expandToContain(const Sphere &sphere) { + if (isNull()) { + *this = sphere; + return; + } else if (sphere.isNull()) { + return; + } + const Vector3D d(sphere.m_center - m_center); const float dist2 = d.lengthSquared(); @@ -206,6 +243,9 @@ void Sphere::expandToContain(const Sphere &sphere) Sphere Sphere::transformed(const Matrix4x4 &mat) const { + if (isNull()) + return *this; + // Transform extremities in x, y, and z directions to find extremities // of the resulting ellipsoid Vector3D x = mat.map(m_center + Vector3D(m_radius, 0.0f, 0.0f)); diff --git a/src/render/frontend/sphere_p.h b/src/render/frontend/sphere_p.h index 10cf92091..b7585f85a 100644 --- a/src/render/frontend/sphere_p.h +++ b/src/render/frontend/sphere_p.h @@ -69,7 +69,7 @@ class Q_3DRENDERSHARED_PRIVATE_EXPORT Sphere : public RayCasting::BoundingSphere public: inline Sphere(Qt3DCore::QNodeId i = Qt3DCore::QNodeId()) : m_center() - , m_radius(0.0f) + , m_radius(-1.0f) , m_id(i) {} @@ -82,7 +82,7 @@ public: void setCenter(const Vector3D &c); Vector3D center() const override; - inline bool isNull() { return m_center == Vector3D() && m_radius == 0.0f; } + bool isNull() const { return m_center == Vector3D() && m_radius == -1.0f; } void setRadius(float r); float radius() const override; @@ -131,7 +131,9 @@ inline Vector3D Sphere::center() const inline void Sphere::setRadius(float r) { - m_radius = r; + Q_ASSERT(r >= 0.0f); + if (r >= 0.0f) + m_radius = r; } inline float Sphere::radius() const @@ -142,11 +144,14 @@ inline float Sphere::radius() const inline void Sphere::clear() { m_center = Vector3D(); - m_radius = 0.0f; + m_radius = -1.0f; } inline bool intersects(const Sphere &a, const Sphere &b) { + if (a.isNull() || b.isNull()) + return false; + // Calculate squared distance between sphere centers const Vector3D d = a.center() - b.center(); const float distSq = Vector3D::dotProduct(d, d); |