1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
4** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the Qt3D module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qt3dquickvaluetypes_p.h"
42
43QT_BEGIN_NAMESPACE
44
45namespace Qt3DCore {
46namespace Quick {
47
48namespace Quick3DValueTypes {
49 void registerValueTypes()
50 {
51 QQmlValueTypeFactory::registerValueTypes(uri: "Qt3D.Core", versionMajor: 2, versionMinor: 0);
52 }
53}
54
55QString Quick3DColorValueType::toString() const
56{
57 return v.name(format: v.alpha() != 255 ? QColor::HexArgb : QColor::HexRgb);
58}
59
60qreal Quick3DColorValueType::r() const
61{
62 return v.redF();
63}
64
65qreal Quick3DColorValueType::g() const
66{
67 return v.greenF();
68}
69
70qreal Quick3DColorValueType::b() const
71{
72 return v.blueF();
73}
74
75qreal Quick3DColorValueType::a() const
76{
77 return v.alphaF();
78}
79
80qreal Quick3DColorValueType::hsvHue() const
81{
82 return v.hsvHueF();
83}
84
85qreal Quick3DColorValueType::hsvSaturation() const
86{
87 return v.hsvSaturationF();
88}
89
90qreal Quick3DColorValueType::hsvValue() const
91{
92 return v.valueF();
93}
94
95qreal Quick3DColorValueType::hslHue() const
96{
97 return v.hslHueF();
98}
99
100qreal Quick3DColorValueType::hslSaturation() const
101{
102 return v.hslSaturationF();
103}
104
105qreal Quick3DColorValueType::hslLightness() const
106{
107 return v.lightnessF();
108}
109
110void Quick3DColorValueType::setR(qreal r)
111{
112 v.setRedF(r);
113}
114
115void Quick3DColorValueType::setG(qreal g)
116{
117 v.setGreenF(g);
118}
119
120void Quick3DColorValueType::setB(qreal b)
121{
122 v.setBlueF(b);
123}
124
125void Quick3DColorValueType::setA(qreal a)
126{
127 v.setAlphaF(a);
128}
129
130void Quick3DColorValueType::setHsvHue(qreal hsvHue)
131{
132 qreal hue, saturation, value, alpha;
133 v.getHsvF(h: &hue, s: &saturation, v: &value, a: &alpha);
134 v.setHsvF(h: hsvHue, s: saturation, v: value, a: alpha);
135}
136
137void Quick3DColorValueType::setHsvSaturation(qreal hsvSaturation)
138{
139 qreal hue, saturation, value, alpha;
140 v.getHsvF(h: &hue, s: &saturation, v: &value, a: &alpha);
141 v.setHsvF(h: hue, s: hsvSaturation, v: value, a: alpha);
142}
143
144void Quick3DColorValueType::setHsvValue(qreal hsvValue)
145{
146 qreal hue, saturation, value, alpha;
147 v.getHsvF(h: &hue, s: &saturation, v: &value, a: &alpha);
148 v.setHsvF(h: hue, s: saturation, v: hsvValue, a: alpha);
149}
150
151void Quick3DColorValueType::setHslHue(qreal hslHue)
152{
153 qreal hue, saturation, lightness, alpha;
154 v.getHslF(h: &hue, s: &saturation, l: &lightness, a: &alpha);
155 v.setHslF(h: hslHue, s: saturation, l: lightness, a: alpha);
156}
157
158void Quick3DColorValueType::setHslSaturation(qreal hslSaturation)
159{
160 qreal hue, saturation, lightness, alpha;
161 v.getHslF(h: &hue, s: &saturation, l: &lightness, a: &alpha);
162 v.setHslF(h: hue, s: hslSaturation, l: lightness, a: alpha);
163}
164
165void Quick3DColorValueType::setHslLightness(qreal hslLightness)
166{
167 qreal hue, saturation, lightness, alpha;
168 v.getHslF(h: &hue, s: &saturation, l: &lightness, a: &alpha);
169 v.setHslF(h: hue, s: saturation, l: hslLightness, a: alpha);
170}
171
172QString Quick3DVector2DValueType::toString() const
173{
174 return QString(QLatin1String("QVector2D(%1, %2)")).arg(a: v.x()).arg(a: v.y());
175}
176
177qreal Quick3DVector2DValueType::x() const
178{
179 return v.x();
180}
181
182qreal Quick3DVector2DValueType::y() const
183{
184 return v.y();
185}
186
187void Quick3DVector2DValueType::setX(qreal x)
188{
189 v.setX(x);
190}
191
192void Quick3DVector2DValueType::setY(qreal y)
193{
194 v.setY(y);
195}
196
197qreal Quick3DVector2DValueType::dotProduct(const QVector2D &vec) const
198{
199 return QVector2D::dotProduct(v1: v, v2: vec);
200}
201
202QVector2D Quick3DVector2DValueType::times(const QVector2D &vec) const
203{
204 return v * vec;
205}
206
207QVector2D Quick3DVector2DValueType::times(qreal scalar) const
208{
209 return v * scalar;
210}
211
212QVector2D Quick3DVector2DValueType::plus(const QVector2D &vec) const
213{
214 return v + vec;
215}
216
217QVector2D Quick3DVector2DValueType::minus(const QVector2D &vec) const
218{
219 return v - vec;
220}
221
222QVector2D Quick3DVector2DValueType::normalized() const
223{
224 return v.normalized();
225}
226
227qreal Quick3DVector2DValueType::length() const
228{
229 return v.length();
230}
231
232QVector3D Quick3DVector2DValueType::toVector3d() const
233{
234 return v.toVector3D();
235}
236
237QVector4D Quick3DVector2DValueType::toVector4d() const
238{
239 return v.toVector4D();
240}
241
242bool Quick3DVector2DValueType::fuzzyEquals(const QVector2D &vec, qreal epsilon) const
243{
244 qreal absEps = qAbs(t: epsilon);
245 if (qAbs(t: v.x() - vec.x()) > absEps)
246 return false;
247 if (qAbs(t: v.y() - vec.y()) > absEps)
248 return false;
249 return true;
250}
251
252bool Quick3DVector2DValueType::fuzzyEquals(const QVector2D &vec) const
253{
254 return qFuzzyCompare(v1: v, v2: vec);
255}
256
257
258QString Quick3DVector3DValueType::toString() const
259{
260 return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(a: v.x()).arg(a: v.y()).arg(a: v.z());
261}
262
263qreal Quick3DVector3DValueType::x() const
264{
265 return v.x();
266}
267
268qreal Quick3DVector3DValueType::y() const
269{
270 return v.y();
271}
272
273qreal Quick3DVector3DValueType::z() const
274{
275 return v.z();
276}
277
278void Quick3DVector3DValueType::setX(qreal x)
279{
280 v.setX(x);
281}
282
283void Quick3DVector3DValueType::setY(qreal y)
284{
285 v.setY(y);
286}
287
288void Quick3DVector3DValueType::setZ(qreal z)
289{
290 v.setZ(z);
291}
292
293QVector3D Quick3DVector3DValueType::crossProduct(const QVector3D &vec) const
294{
295 return QVector3D::crossProduct(v1: v, v2: vec);
296}
297
298qreal Quick3DVector3DValueType::dotProduct(const QVector3D &vec) const
299{
300 return QVector3D::dotProduct(v1: v, v2: vec);
301}
302
303QVector3D Quick3DVector3DValueType::times(const QMatrix4x4 &m) const
304{
305 return v * m;
306}
307
308QVector3D Quick3DVector3DValueType::times(const QVector3D &vec) const
309{
310 return v * vec;
311}
312
313QVector3D Quick3DVector3DValueType::times(qreal scalar) const
314{
315 return v * scalar;
316}
317
318QVector3D Quick3DVector3DValueType::plus(const QVector3D &vec) const
319{
320 return v + vec;
321}
322
323QVector3D Quick3DVector3DValueType::minus(const QVector3D &vec) const
324{
325 return v - vec;
326}
327
328QVector3D Quick3DVector3DValueType::normalized() const
329{
330 return v.normalized();
331}
332
333qreal Quick3DVector3DValueType::length() const
334{
335 return v.length();
336}
337
338QVector2D Quick3DVector3DValueType::toVector2d() const
339{
340 return v.toVector2D();
341}
342
343QVector4D Quick3DVector3DValueType::toVector4d() const
344{
345 return v.toVector4D();
346}
347
348bool Quick3DVector3DValueType::fuzzyEquals(const QVector3D &vec, qreal epsilon) const
349{
350 qreal absEps = qAbs(t: epsilon);
351 if (qAbs(t: v.x() - vec.x()) > absEps)
352 return false;
353 if (qAbs(t: v.y() - vec.y()) > absEps)
354 return false;
355 if (qAbs(t: v.z() - vec.z()) > absEps)
356 return false;
357 return true;
358}
359
360bool Quick3DVector3DValueType::fuzzyEquals(const QVector3D &vec) const
361{
362 return qFuzzyCompare(v1: v, v2: vec);
363}
364
365
366QString Quick3DVector4DValueType::toString() const
367{
368 return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(a: v.x()).arg(a: v.y()).arg(a: v.z()).arg(a: v.w());
369}
370
371qreal Quick3DVector4DValueType::x() const
372{
373 return v.x();
374}
375
376qreal Quick3DVector4DValueType::y() const
377{
378 return v.y();
379}
380
381qreal Quick3DVector4DValueType::z() const
382{
383 return v.z();
384}
385
386qreal Quick3DVector4DValueType::w() const
387{
388 return v.w();
389}
390
391void Quick3DVector4DValueType::setX(qreal x)
392{
393 v.setX(x);
394}
395
396void Quick3DVector4DValueType::setY(qreal y)
397{
398 v.setY(y);
399}
400
401void Quick3DVector4DValueType::setZ(qreal z)
402{
403 v.setZ(z);
404}
405
406void Quick3DVector4DValueType::setW(qreal w)
407{
408 v.setW(w);
409}
410
411qreal Quick3DVector4DValueType::dotProduct(const QVector4D &vec) const
412{
413 return QVector4D::dotProduct(v1: v, v2: vec);
414}
415
416QVector4D Quick3DVector4DValueType::times(const QVector4D &vec) const
417{
418 return v * vec;
419}
420
421QVector4D Quick3DVector4DValueType::times(const QMatrix4x4 &m) const
422{
423 return v * m;
424}
425
426QVector4D Quick3DVector4DValueType::times(qreal scalar) const
427{
428 return v * scalar;
429}
430
431QVector4D Quick3DVector4DValueType::plus(const QVector4D &vec) const
432{
433 return v + vec;
434}
435
436QVector4D Quick3DVector4DValueType::minus(const QVector4D &vec) const
437{
438 return v - vec;
439}
440
441QVector4D Quick3DVector4DValueType::normalized() const
442{
443 return v.normalized();
444}
445
446qreal Quick3DVector4DValueType::length() const
447{
448 return v.length();
449}
450
451QVector2D Quick3DVector4DValueType::toVector2d() const
452{
453 return v.toVector2D();
454}
455
456QVector3D Quick3DVector4DValueType::toVector3d() const
457{
458 return v.toVector3D();
459}
460
461bool Quick3DVector4DValueType::fuzzyEquals(const QVector4D &vec, qreal epsilon) const
462{
463 qreal absEps = qAbs(t: epsilon);
464 if (qAbs(t: v.x() - vec.x()) > absEps)
465 return false;
466 if (qAbs(t: v.y() - vec.y()) > absEps)
467 return false;
468 if (qAbs(t: v.z() - vec.z()) > absEps)
469 return false;
470 if (qAbs(t: v.w() - vec.w()) > absEps)
471 return false;
472 return true;
473}
474
475bool Quick3DVector4DValueType::fuzzyEquals(const QVector4D &vec) const
476{
477 return qFuzzyCompare(v1: v, v2: vec);
478}
479
480
481QString Quick3DQuaternionValueType::toString() const
482{
483 return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(a: v.scalar()).arg(a: v.x()).arg(a: v.y()).arg(a: v.z());
484}
485
486qreal Quick3DQuaternionValueType::scalar() const
487{
488 return v.scalar();
489}
490
491qreal Quick3DQuaternionValueType::x() const
492{
493 return v.x();
494}
495
496qreal Quick3DQuaternionValueType::y() const
497{
498 return v.y();
499}
500
501qreal Quick3DQuaternionValueType::z() const
502{
503 return v.z();
504}
505
506void Quick3DQuaternionValueType::setScalar(qreal scalar)
507{
508 v.setScalar(scalar);
509}
510
511void Quick3DQuaternionValueType::setX(qreal x)
512{
513 v.setX(x);
514}
515
516void Quick3DQuaternionValueType::setY(qreal y)
517{
518 v.setY(y);
519}
520
521void Quick3DQuaternionValueType::setZ(qreal z)
522{
523 v.setZ(z);
524}
525
526
527QMatrix4x4 Quick3DMatrix4x4ValueType::times(const QMatrix4x4 &m) const
528{
529 return v * m;
530}
531
532QVector4D Quick3DMatrix4x4ValueType::times(const QVector4D &vec) const
533{
534 return v * vec;
535}
536
537QVector3D Quick3DMatrix4x4ValueType::times(const QVector3D &vec) const
538{
539 return v * vec;
540}
541
542QMatrix4x4 Quick3DMatrix4x4ValueType::times(qreal factor) const
543{
544 return v * factor;
545}
546
547QMatrix4x4 Quick3DMatrix4x4ValueType::plus(const QMatrix4x4 &m) const
548{
549 return v + m;
550}
551
552QMatrix4x4 Quick3DMatrix4x4ValueType::minus(const QMatrix4x4 &m) const
553{
554 return v - m;
555}
556
557QVector4D Quick3DMatrix4x4ValueType::row(int n) const
558{
559 return v.row(index: n);
560}
561
562QVector4D Quick3DMatrix4x4ValueType::column(int m) const
563{
564 return v.column(index: m);
565}
566
567qreal Quick3DMatrix4x4ValueType::determinant() const
568{
569 return v.determinant();
570}
571
572QMatrix4x4 Quick3DMatrix4x4ValueType::inverted() const
573{
574 return v.inverted();
575}
576
577QMatrix4x4 Quick3DMatrix4x4ValueType::transposed() const
578{
579 return v.transposed();
580}
581
582bool Quick3DMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m, qreal epsilon) const
583{
584 qreal absEps = qAbs(t: epsilon);
585 for (int i = 0; i < 4; ++i) {
586 for (int j = 0; j < 4; ++j) {
587 if (qAbs(t: v(i,j) - m(i,j)) > absEps) {
588 return false;
589 }
590 }
591 }
592 return true;
593}
594
595bool Quick3DMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m) const
596{
597 return qFuzzyCompare(m1: v, m2: m);
598}
599
600QString Quick3DMatrix4x4ValueType::toString() const
601{
602 return QString(QLatin1String("QMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)"))
603 .arg(a: v(0, 0)).arg(a: v(0, 1)).arg(a: v(0, 2)).arg(a: v(0, 3))
604 .arg(a: v(1, 0)).arg(a: v(1, 1)).arg(a: v(1, 2)).arg(a: v(1, 3))
605 .arg(a: v(2, 0)).arg(a: v(2, 1)).arg(a: v(2, 2)).arg(a: v(2, 3))
606 .arg(a: v(3, 0)).arg(a: v(3, 1)).arg(a: v(3, 2)).arg(a: v(3, 3));
607}
608
609} // namespace Quick
610} // namespace Qt3DCore
611
612QT_END_NAMESPACE
613

source code of qt3d/src/quick3d/quick3d/qt3dquickvaluetypes.cpp