summaryrefslogtreecommitdiffstats
path: root/src/render/frontend
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2017-03-15 10:17:05 +0100
committerPaul Lemire <paul.lemire@kdab.com>2018-02-02 13:58:34 +0000
commit437a33de9336a5c50711e63dd6dfcd86ad28d5a5 (patch)
tree6f6cbf6fa5285a79cda6a849a0b96e744ec840c6 /src/render/frontend
parent46319648436814afb5a77755dde6681e304befaf (diff)
Render: Use SIMD Vectors and Matrices in the backend
Change-Id: I19b3b2f8fcb06eb2bc600ebe370465dd15a8eabc Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/frontend')
-rw-r--r--src/render/frontend/sphere.cpp48
-rw-r--r--src/render/frontend/sphere_p.h38
2 files changed, 43 insertions, 43 deletions
diff --git a/src/render/frontend/sphere.cpp b/src/render/frontend/sphere.cpp
index 2c22e0da4..740626163 100644
--- a/src/render/frontend/sphere.cpp
+++ b/src/render/frontend/sphere.cpp
@@ -53,18 +53,18 @@ 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::RayCasting::QRay3D &ray, const Qt3DRender::Render::Sphere &s, QVector3D *q = nullptr)
+bool intersectRaySphere(const Qt3DRender::RayCasting::QRay3D &ray, const Qt3DRender::Render::Sphere &s, Vector3D *q = nullptr)
{
- const QVector3D p = ray.origin();
- const QVector3D d = ray.direction();
- const QVector3D m = p - s.center();
- const float c = QVector3D::dotProduct(m, m) - s.radius() * s.radius();
+ const Vector3D p = ray.origin();
+ const Vector3D d = ray.direction();
+ const Vector3D m = p - s.center();
+ const float c = Vector3D::dotProduct(m, m) - s.radius() * s.radius();
// If there is definitely at least one real root, there must be an intersection
if (q == nullptr && c <= 0.0f)
return true;
- const float b = QVector3D::dotProduct(m, d);
+ const float b = Vector3D::dotProduct(m, d);
// Exit if r’s origin outside s (c > 0) and r pointing away from s (b > 0)
if (c > 0.0f && b > 0.0f)
return false;
@@ -89,12 +89,12 @@ bool intersectRaySphere(const Qt3DRender::RayCasting::QRay3D &ray, const Qt3DRen
return true;
}
-inline QPair<int, int> findExtremePoints(const QVector<QVector3D> &points)
+inline QPair<int, int> findExtremePoints(const QVector<Vector3D> &points)
{
// Find indices of extreme points along x, y, and z axes
int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
for (int i = 1; i < points.size(); ++i) {
- const QVector3D &p = points.at(i);
+ const Vector3D &p = points.at(i);
if (p.x() < points[xMin].x())
xMin = i;
if (p.x() > points[xMax].x())
@@ -124,20 +124,20 @@ inline QPair<int, int> findExtremePoints(const QVector<QVector3D> &points)
return extremeIndices;
}
-inline void sphereFromExtremePoints(Qt3DRender::Render::Sphere &s, const QVector<QVector3D> &points)
+inline void sphereFromExtremePoints(Qt3DRender::Render::Sphere &s, const QVector<Vector3D> &points)
{
// Find two most separated points on any of the basis vectors
QPair<int, int> extremeIndices = findExtremePoints(points);
// Construct sphere to contain these two points
- const QVector3D &p = points.at(extremeIndices.first);
- const QVector3D &q = points.at(extremeIndices.second);
- const QVector3D c = 0.5f * (p + q);
+ const Vector3D &p = points.at(extremeIndices.first);
+ const Vector3D &q = points.at(extremeIndices.second);
+ const Vector3D c = 0.5f * (p + q);
s.setCenter(c);
s.setRadius((q - c).length());
}
-inline void constructRitterSphere(Qt3DRender::Render::Sphere &s, const QVector<QVector3D> &points)
+inline void constructRitterSphere(Qt3DRender::Render::Sphere &s, const QVector<Vector3D> &points)
{
// Calculate the sphere encompassing two axially extreme points
sphereFromExtremePoints(s, points);
@@ -154,22 +154,22 @@ namespace Render {
const float Sphere::ms_epsilon = 1.0e-7f;
-Sphere Sphere::fromPoints(const QVector<QVector3D> &points)
+Sphere Sphere::fromPoints(const QVector<Vector3D> &points)
{
Sphere s;
s.initializeFromPoints(points);
return s;
}
-void Sphere::initializeFromPoints(const QVector<QVector3D> &points)
+void Sphere::initializeFromPoints(const QVector<Vector3D> &points)
{
if (!points.isEmpty())
constructRitterSphere(*this, points);
}
-void Sphere::expandToContain(const QVector3D &p)
+void Sphere::expandToContain(const Vector3D &p)
{
- const QVector3D d = p - m_center;
+ const Vector3D d = p - m_center;
const float dist2 = d.lengthSquared();
if (dist2 > m_radius * m_radius) {
@@ -184,7 +184,7 @@ void Sphere::expandToContain(const QVector3D &p)
void Sphere::expandToContain(const Sphere &sphere)
{
- const QVector3D d(sphere.m_center - m_center);
+ const Vector3D d(sphere.m_center - m_center);
const float dist2 = d.lengthSquared();
const float dr = sphere.m_radius - m_radius;
@@ -204,16 +204,16 @@ void Sphere::expandToContain(const Sphere &sphere)
}
}
-Sphere Sphere::transformed(const QMatrix4x4 &mat) const
+Sphere Sphere::transformed(const Matrix4x4 &mat) const
{
// Transform extremities in x, y, and z directions to find extremities
// of the resulting ellipsoid
- QVector3D x = mat.map(m_center + QVector3D(m_radius, 0.0f, 0.0f));
- QVector3D y = mat.map(m_center + QVector3D(0.0f, m_radius, 0.0f));
- QVector3D z = mat.map(m_center + QVector3D(0.0f, 0.0f, m_radius));
+ Vector3D x = mat.map(m_center + Vector3D(m_radius, 0.0f, 0.0f));
+ Vector3D y = mat.map(m_center + Vector3D(0.0f, m_radius, 0.0f));
+ Vector3D z = mat.map(m_center + Vector3D(0.0f, 0.0f, m_radius));
// Transform center and find maximum radius of ellipsoid
- QVector3D c = mat.map(m_center);
+ Vector3D c = mat.map(m_center);
float rSquared = qMax(qMax((x - c).lengthSquared(), (y - c).lengthSquared()), (z - c).lengthSquared());
return Sphere(c, sqrt(rSquared), id());
}
@@ -223,7 +223,7 @@ Qt3DCore::QNodeId Sphere::id() const
return m_id;
}
-bool Sphere::intersects(const RayCasting::QRay3D &ray, QVector3D *q, QVector3D *uvw) const
+bool Sphere::intersects(const RayCasting::QRay3D &ray, Vector3D *q, Vector3D *uvw) const
{
Q_UNUSED(uvw);
return intersectRaySphere(ray, *this, q);
diff --git a/src/render/frontend/sphere_p.h b/src/render/frontend/sphere_p.h
index 1587aecab..ff6b2286b 100644
--- a/src/render/frontend/sphere_p.h
+++ b/src/render/frontend/sphere_p.h
@@ -53,10 +53,10 @@
#include <Qt3DRender/private/qt3drender_global_p.h>
#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/private/matrix4x4_p.h>
#include <Qt3DRender/private/boundingsphere_p.h>
#include <QMatrix4x4>
-#include <QVector3D>
QT_BEGIN_NAMESPACE
@@ -73,58 +73,58 @@ public:
, m_id(i)
{}
- inline Sphere(const QVector3D &c, float r, Qt3DCore::QNodeId i = Qt3DCore::QNodeId())
+ inline Sphere(const Vector3D &c, float r, Qt3DCore::QNodeId i = Qt3DCore::QNodeId())
: m_center(c)
, m_radius(r)
, m_id(i)
{}
- void setCenter(const QVector3D &c);
- QVector3D center() const Q_DECL_OVERRIDE;
+ void setCenter(const Vector3D &c);
+ Vector3D center() const Q_DECL_OVERRIDE;
- inline bool isNull() { return m_center == QVector3D() && m_radius == 0.0f; }
+ inline bool isNull() { return m_center == Vector3D() && m_radius == 0.0f; }
void setRadius(float r);
float radius() const Q_DECL_OVERRIDE;
void clear();
- void initializeFromPoints(const QVector<QVector3D> &points);
- void expandToContain(const QVector3D &point);
- inline void expandToContain(const QVector<QVector3D> &points)
+ void initializeFromPoints(const QVector<Vector3D> &points);
+ void expandToContain(const Vector3D &point);
+ inline void expandToContain(const QVector<Vector3D> &points)
{
- for (const QVector3D &p : points)
+ for (const Vector3D &p : points)
expandToContain(p);
}
void expandToContain(const Sphere &sphere);
- Sphere transformed(const QMatrix4x4 &mat) const;
- inline Sphere &transform(const QMatrix4x4 &mat)
+ Sphere transformed(const Matrix4x4 &mat) const;
+ inline Sphere &transform(const Matrix4x4 &mat)
{
*this = transformed(mat);
return *this;
}
Qt3DCore::QNodeId id() const Q_DECL_FINAL;
- bool intersects(const RayCasting::QRay3D &ray, QVector3D *q, QVector3D *uvw = nullptr) const Q_DECL_FINAL;
+ bool intersects(const RayCasting::QRay3D &ray, Vector3D *q, Vector3D *uvw = nullptr) const Q_DECL_FINAL;
Type type() const Q_DECL_FINAL;
- static Sphere fromPoints(const QVector<QVector3D> &points);
+ static Sphere fromPoints(const QVector<Vector3D> &points);
private:
- QVector3D m_center;
+ Vector3D m_center;
float m_radius;
Qt3DCore::QNodeId m_id;
static const float ms_epsilon;
};
-inline void Sphere::setCenter(const QVector3D &c)
+inline void Sphere::setCenter(const Vector3D &c)
{
m_center = c;
}
-inline QVector3D Sphere::center() const
+inline Vector3D Sphere::center() const
{
return m_center;
}
@@ -141,15 +141,15 @@ inline float Sphere::radius() const
inline void Sphere::clear()
{
- m_center = QVector3D();
+ m_center = Vector3D();
m_radius = 0.0f;
}
inline bool intersects(const Sphere &a, const Sphere &b)
{
// Calculate squared distance between sphere centers
- const QVector3D d = a.center() - b.center();
- const float distSq = QVector3D::dotProduct(d, d);
+ const Vector3D d = a.center() - b.center();
+ const float distSq = Vector3D::dotProduct(d, d);
// Spheres intersect if squared distance is less than squared
// sum of radii