1// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "vector3d_sse_p.h"
5
6#include <private/qsimd_p.h>
7
8#include "matrix4x4_sse_p.h"
9#include "vector4d_sse_p.h"
10#include <QDebug>
11
12#ifdef __SSE2__
13
14QT_BEGIN_NAMESPACE
15
16namespace Qt3DCore {
17
18QDebug operator<<(QDebug dbg, const Vector3D_SSE &v)
19{
20 dbg.nospace() << "Vector3D_SSE(" << v.x() << ", " << v.y() << ", " << v.z() << ") ";
21 return dbg;
22}
23
24Vector3D_SSE::Vector3D_SSE(const Vector4D_SSE &v)
25{
26 m_xyzw = _mm_mul_ps(a: v.m_xyzw, b: _mm_set_ps(z: 0.0f, y: 1.0f, x: 1.0f, w: 1.0f));
27}
28
29Vector3D_SSE Vector3D_SSE::unproject(const Matrix4x4_SSE &modelView, const Matrix4x4_SSE &projection, const QRect &viewport) const
30{
31 const Matrix4x4_SSE inverse = (projection * modelView).inverted();
32
33 Vector4D_SSE tmp(*this, 1.0f);
34 tmp.setX((tmp.x() - float(viewport.x())) / float(viewport.width()));
35 tmp.setY((tmp.y() - float(viewport.y())) / float(viewport.height()));
36 tmp = tmp * 2.0f - Vector4D_SSE(1.0f, 1.0f, 1.0f, 1.0f);
37
38 Vector4D_SSE obj = inverse * tmp;
39 if (qFuzzyIsNull(f: obj.w()))
40 obj.setW(1.0f);
41 obj /= obj.w();
42 return Vector3D_SSE(obj);
43}
44
45Vector3D_SSE Vector3D_SSE::project(const Matrix4x4_SSE &modelView, const Matrix4x4_SSE &projection, const QRect &viewport) const
46{
47 Vector4D_SSE tmp(*this, 1.0f);
48 tmp = projection * modelView * tmp;
49 if (qFuzzyIsNull(f: tmp.w()))
50 tmp.setW(1.0f);
51 tmp /= tmp.w();
52
53 tmp = tmp * 0.5f + Vector4D_SSE(0.5f, 0.5f, 0.5f, 0.5f);
54 tmp.setX(tmp.x() * viewport.width() + viewport.x());
55 tmp.setY(tmp.y() * viewport.height() + viewport.y());
56
57 return Vector3D_SSE(tmp);
58}
59
60} // Qt3DCore
61
62QT_END_NAMESPACE
63
64#endif // __SSE2__
65

source code of qt3d/src/core/transforms/vector3d_sse.cpp