diff options
Diffstat (limited to 'src/core/transforms/vector3d_sse.cpp')
-rw-r--r-- | src/core/transforms/vector3d_sse.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/core/transforms/vector3d_sse.cpp b/src/core/transforms/vector3d_sse.cpp index 7e20a2f77..151cbb959 100644 --- a/src/core/transforms/vector3d_sse.cpp +++ b/src/core/transforms/vector3d_sse.cpp @@ -38,6 +38,13 @@ ****************************************************************************/ #include <private/qsimd_p.h> + +#ifdef __AVX2__ +#include "matrix4x4_avx2_p.h" +#else +#include "matrix4x4_sse_p.h" +#endif + #include "vector3d_sse_p.h" #include "vector4d_sse_p.h" #include <QDebug> @@ -59,6 +66,74 @@ Vector3D_SSE::Vector3D_SSE(const Vector4D_SSE &v) m_xyzw = _mm_mul_ps(v.m_xyzw, _mm_set_ps(0.0f, 1.0f, 1.0f, 1.0f)); } +#ifdef __AVX2__ + +Vector3D_SSE Vector3D_SSE::unproject(const Matrix4x4_AVX2 &modelView, const Matrix4x4_AVX2 &projection, const QRect &viewport) const +{ + const Matrix4x4_AVX2 inverse = (projection * modelView).inverted(); + + Vector4D_SSE tmp(*this, 1.0f); + tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width())); + tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height())); + tmp = tmp * 2.0f - Vector4D_SSE(1.0f, 1.0f, 1.0f, 1.0f); + + Vector4D_SSE obj = inverse * tmp; + if (qFuzzyIsNull(obj.w())) + obj.setW(1.0f); + obj /= obj.w(); + return Vector3D_SSE(obj); +} + +Vector3D_SSE Vector3D_SSE::project(const Matrix4x4_AVX2 &modelView, const Matrix4x4_AVX2 &projection, const QRect &viewport) const +{ + Vector4D_SSE tmp(*this, 1.0f); + tmp = projection * modelView * tmp; + if (qFuzzyIsNull(tmp.w())) + tmp.setW(1.0f); + tmp /= tmp.w(); + + tmp = tmp * 0.5f + Vector4D_SSE(0.5f, 0.5f, 0.5f, 0.5f); + tmp.setX(tmp.x() * viewport.width() + viewport.x()); + tmp.setY(tmp.y() * viewport.height() + viewport.y()); + + return Vector3D_SSE(tmp); +} + +#else + +Vector3D_SSE Vector3D_SSE::unproject(const Matrix4x4_SSE &modelView, const Matrix4x4_SSE &projection, const QRect &viewport) const +{ + const Matrix4x4_SSE inverse = (projection * modelView).inverted(); + + Vector4D_SSE tmp(*this, 1.0f); + tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width())); + tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height())); + tmp = tmp * 2.0f - Vector4D_SSE(1.0f, 1.0f, 1.0f, 1.0f); + + Vector4D_SSE obj = inverse * tmp; + if (qFuzzyIsNull(obj.w())) + obj.setW(1.0f); + obj /= obj.w(); + return Vector3D_SSE(obj); +} + +Vector3D_SSE Vector3D_SSE::project(const Matrix4x4_SSE &modelView, const Matrix4x4_SSE &projection, const QRect &viewport) const +{ + Vector4D_SSE tmp(*this, 1.0f); + tmp = projection * modelView * tmp; + if (qFuzzyIsNull(tmp.w())) + tmp.setW(1.0f); + tmp /= tmp.w(); + + tmp = tmp * 0.5f + Vector4D_SSE(0.5f, 0.5f, 0.5f, 0.5f); + tmp.setX(tmp.x() * viewport.width() + viewport.x()); + tmp.setY(tmp.y() * viewport.height() + viewport.y()); + + return Vector3D_SSE(tmp); +} + +#endif + } // Qt3DCore QT_END_NAMESPACE |