math3d/qquaternion.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4float QQuaternion::length() const -
5{ -
6 return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
executed: return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
Execution Count:28
28
7} -
8 -
9 -
10 -
11 -
12 -
13 -
14float QQuaternion::lengthSquared() const -
15{ -
16 return xp * xp + yp * yp + zp * zp + wp * wp;
executed: return xp * xp + yp * yp + zp * zp + wp * wp;
Execution Count:10
10
17} -
18QQuaternion QQuaternion::normalized() const -
19{ -
20 -
21 double len = double(xp) * double(xp) + -
22 double(yp) * double(yp) + -
23 double(zp) * double(zp) + -
24 double(wp) * double(wp); -
25 if (qFuzzyIsNull(len - 1.0f))
evaluated: qFuzzyIsNull(len - 1.0f)
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:61
18-61
26 return *this;
executed: return *this;
Execution Count:18
18
27 else if (!qFuzzyIsNull(len))
evaluated: !qFuzzyIsNull(len)
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:1
1-60
28 return *this / qSqrt(len);
executed: return *this / qSqrt(len);
Execution Count:60
60
29 else -
30 return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
executed: return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
Execution Count:1
1
31} -
32 -
33 -
34 -
35 -
36 -
37 -
38 -
39void QQuaternion::normalize() -
40{ -
41 -
42 double len = double(xp) * double(xp) + -
43 double(yp) * double(yp) + -
44 double(zp) * double(zp) + -
45 double(wp) * double(wp); -
46 if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
evaluated: qFuzzyIsNull(len - 1.0f)
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:2
evaluated: qFuzzyIsNull(len)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1-8
47 return;
executed: return;
Execution Count:9
9
48 -
49 len = qSqrt(len); -
50 -
51 xp /= len; -
52 yp /= len; -
53 zp /= len; -
54 wp /= len; -
55}
executed: }
Execution Count:1
1
56QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const -
57{ -
58 return (*this * QQuaternion(0, vector) * conjugate()).vector();
executed: return (*this * QQuaternion(0, vector) * conjugate()).vector();
Execution Count:8
8
59} -
60QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, float angle) -
61{ -
62 -
63 -
64 -
65 -
66 float a = (angle / 2.0f) * 3.14159265358979323846 / 180.0f; -
67 float s = sinf(a); -
68 float c = cosf(a); -
69 QVector3D ax = axis.normalized(); -
70 return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
executed: return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
Execution Count:21
21
71} -
72 -
73 -
74 -
75 -
76 -
77 -
78 -
79QQuaternion QQuaternion::fromAxisAndAngle -
80 (float x, float y, float z, float angle) -
81{ -
82 float length = qSqrt(x * x + y * y + z * z); -
83 if (!qFuzzyIsNull(length - 1.0f) && !qFuzzyIsNull(length)) {
evaluated: !qFuzzyIsNull(length - 1.0f)
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:3
evaluated: !qFuzzyIsNull(length)
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:1
1-32
84 x /= length; -
85 y /= length; -
86 z /= length; -
87 }
executed: }
Execution Count:31
31
88 float a = (angle / 2.0f) * 3.14159265358979323846 / 180.0f; -
89 float s = sinf(a); -
90 float c = cosf(a); -
91 return QQuaternion(c, x * s, y * s, z * s).normalized();
executed: return QQuaternion(c, x * s, y * s, z * s).normalized();
Execution Count:35
35
92} -
93QQuaternion QQuaternion::slerp -
94 (const QQuaternion& q1, const QQuaternion& q2, float t) -
95{ -
96 -
97 if (t <= 0.0f)
evaluated: t <= 0.0f
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:4
2-4
98 return q1;
executed: return q1;
Execution Count:2
2
99 else if (t >= 1.0f)
evaluated: t >= 1.0f
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
100 return q2;
executed: return q2;
Execution Count:2
2
101 -
102 -
103 QQuaternion q2b; -
104 float dot; -
105 dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp; -
106 if (dot >= 0.0f) {
evaluated: dot >= 0.0f
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
107 q2b = q2; -
108 } else {
executed: }
Execution Count:1
1
109 q2b = -q2; -
110 dot = -dot; -
111 }
executed: }
Execution Count:1
1
112 -
113 -
114 -
115 float factor1 = 1.0f - t; -
116 float factor2 = t; -
117 if ((1.0f - dot) > 0.0000001) {
partially evaluated: (1.0f - dot) > 0.0000001
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
118 float angle = acosf(dot); -
119 float sinOfAngle = sinf(angle); -
120 if (sinOfAngle > 0.0000001) {
partially evaluated: sinOfAngle > 0.0000001
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
121 factor1 = sinf((1.0f - t) * angle) / sinOfAngle; -
122 factor2 = sinf(t * angle) / sinOfAngle; -
123 }
executed: }
Execution Count:2
2
124 }
executed: }
Execution Count:2
2
125 -
126 -
127 return q1 * factor1 + q2b * factor2;
executed: return q1 * factor1 + q2b * factor2;
Execution Count:2
2
128} -
129QQuaternion QQuaternion::nlerp -
130 (const QQuaternion& q1, const QQuaternion& q2, float t) -
131{ -
132 -
133 if (t <= 0.0f)
evaluated: t <= 0.0f
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:4
2-4
134 return q1;
executed: return q1;
Execution Count:2
2
135 else if (t >= 1.0f)
evaluated: t >= 1.0f
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
136 return q2;
executed: return q2;
Execution Count:2
2
137 -
138 -
139 QQuaternion q2b; -
140 float dot; -
141 dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp; -
142 if (dot >= 0.0f)
evaluated: dot >= 0.0f
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
143 q2b = q2;
executed: q2b = q2;
Execution Count:1
1
144 else -
145 q2b = -q2;
executed: q2b = -q2;
Execution Count:1
1
146 -
147 -
148 return (q1 * (1.0f - t) + q2b * t).normalized();
executed: return (q1 * (1.0f - t) + q2b * t).normalized();
Execution Count:2
2
149} -
150 -
151 -
152 -
153 -
154QQuaternion::operator QVariant() const -
155{ -
156 return QVariant(QVariant::Quaternion, this);
executed: return QVariant(QVariant::Quaternion, this);
Execution Count:1
1
157} -
158 -
159 -
160 -
161QDebug operator<<(QDebug dbg, const QQuaternion &q) -
162{ -
163 dbg.nospace() << "QQuaternion(scalar:" << q.scalar() -
164 << ", vector:(" << q.x() << ", " -
165 << q.y() << ", " << q.z() << "))"; -
166 return dbg.space();
executed: return dbg.space();
Execution Count:1
1
167} -
168QDataStream &operator<<(QDataStream &stream, const QQuaternion &quaternion) -
169{ -
170 stream << quaternion.scalar() << quaternion.x() -
171 << quaternion.y() << quaternion.z(); -
172 return stream;
never executed: return stream;
0
173} -
174QDataStream &operator>>(QDataStream &stream, QQuaternion &quaternion) -
175{ -
176 float scalar, x, y, z; -
177 stream >> scalar; -
178 stream >> x; -
179 stream >> y; -
180 stream >> z; -
181 quaternion.setScalar(scalar); -
182 quaternion.setX(x); -
183 quaternion.setY(y); -
184 quaternion.setZ(z); -
185 return stream;
never executed: return stream;
0
186} -
187 -
188 -
189 -
190 -
191 -
192 -
193 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial