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 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | namespace Qt3DCore { |
46 | namespace Quick { |
47 | |
48 | namespace Quick3DValueTypes { |
49 | void registerValueTypes() |
50 | { |
51 | QQmlValueTypeFactory::registerValueTypes(uri: "Qt3D.Core" , versionMajor: 2, versionMinor: 0); |
52 | } |
53 | } |
54 | |
55 | QString Quick3DColorValueType::toString() const |
56 | { |
57 | return v.name(format: v.alpha() != 255 ? QColor::HexArgb : QColor::HexRgb); |
58 | } |
59 | |
60 | qreal Quick3DColorValueType::r() const |
61 | { |
62 | return v.redF(); |
63 | } |
64 | |
65 | qreal Quick3DColorValueType::g() const |
66 | { |
67 | return v.greenF(); |
68 | } |
69 | |
70 | qreal Quick3DColorValueType::b() const |
71 | { |
72 | return v.blueF(); |
73 | } |
74 | |
75 | qreal Quick3DColorValueType::a() const |
76 | { |
77 | return v.alphaF(); |
78 | } |
79 | |
80 | qreal Quick3DColorValueType::hsvHue() const |
81 | { |
82 | return v.hsvHueF(); |
83 | } |
84 | |
85 | qreal Quick3DColorValueType::hsvSaturation() const |
86 | { |
87 | return v.hsvSaturationF(); |
88 | } |
89 | |
90 | qreal Quick3DColorValueType::hsvValue() const |
91 | { |
92 | return v.valueF(); |
93 | } |
94 | |
95 | qreal Quick3DColorValueType::hslHue() const |
96 | { |
97 | return v.hslHueF(); |
98 | } |
99 | |
100 | qreal Quick3DColorValueType::hslSaturation() const |
101 | { |
102 | return v.hslSaturationF(); |
103 | } |
104 | |
105 | qreal Quick3DColorValueType::hslLightness() const |
106 | { |
107 | return v.lightnessF(); |
108 | } |
109 | |
110 | void Quick3DColorValueType::setR(qreal r) |
111 | { |
112 | v.setRedF(r); |
113 | } |
114 | |
115 | void Quick3DColorValueType::setG(qreal g) |
116 | { |
117 | v.setGreenF(g); |
118 | } |
119 | |
120 | void Quick3DColorValueType::setB(qreal b) |
121 | { |
122 | v.setBlueF(b); |
123 | } |
124 | |
125 | void Quick3DColorValueType::setA(qreal a) |
126 | { |
127 | v.setAlphaF(a); |
128 | } |
129 | |
130 | void 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 | |
137 | void 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 | |
144 | void 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 | |
151 | void 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 | |
158 | void 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 | |
165 | void 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 | |
172 | QString Quick3DVector2DValueType::toString() const |
173 | { |
174 | return QString(QLatin1String("QVector2D(%1, %2)" )).arg(a: v.x()).arg(a: v.y()); |
175 | } |
176 | |
177 | qreal Quick3DVector2DValueType::x() const |
178 | { |
179 | return v.x(); |
180 | } |
181 | |
182 | qreal Quick3DVector2DValueType::y() const |
183 | { |
184 | return v.y(); |
185 | } |
186 | |
187 | void Quick3DVector2DValueType::setX(qreal x) |
188 | { |
189 | v.setX(x); |
190 | } |
191 | |
192 | void Quick3DVector2DValueType::setY(qreal y) |
193 | { |
194 | v.setY(y); |
195 | } |
196 | |
197 | qreal Quick3DVector2DValueType::dotProduct(const QVector2D &vec) const |
198 | { |
199 | return QVector2D::dotProduct(v1: v, v2: vec); |
200 | } |
201 | |
202 | QVector2D Quick3DVector2DValueType::times(const QVector2D &vec) const |
203 | { |
204 | return v * vec; |
205 | } |
206 | |
207 | QVector2D Quick3DVector2DValueType::times(qreal scalar) const |
208 | { |
209 | return v * scalar; |
210 | } |
211 | |
212 | QVector2D Quick3DVector2DValueType::plus(const QVector2D &vec) const |
213 | { |
214 | return v + vec; |
215 | } |
216 | |
217 | QVector2D Quick3DVector2DValueType::minus(const QVector2D &vec) const |
218 | { |
219 | return v - vec; |
220 | } |
221 | |
222 | QVector2D Quick3DVector2DValueType::normalized() const |
223 | { |
224 | return v.normalized(); |
225 | } |
226 | |
227 | qreal Quick3DVector2DValueType::length() const |
228 | { |
229 | return v.length(); |
230 | } |
231 | |
232 | QVector3D Quick3DVector2DValueType::toVector3d() const |
233 | { |
234 | return v.toVector3D(); |
235 | } |
236 | |
237 | QVector4D Quick3DVector2DValueType::toVector4d() const |
238 | { |
239 | return v.toVector4D(); |
240 | } |
241 | |
242 | bool 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 | |
252 | bool Quick3DVector2DValueType::fuzzyEquals(const QVector2D &vec) const |
253 | { |
254 | return qFuzzyCompare(v1: v, v2: vec); |
255 | } |
256 | |
257 | |
258 | QString 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 | |
263 | qreal Quick3DVector3DValueType::x() const |
264 | { |
265 | return v.x(); |
266 | } |
267 | |
268 | qreal Quick3DVector3DValueType::y() const |
269 | { |
270 | return v.y(); |
271 | } |
272 | |
273 | qreal Quick3DVector3DValueType::z() const |
274 | { |
275 | return v.z(); |
276 | } |
277 | |
278 | void Quick3DVector3DValueType::setX(qreal x) |
279 | { |
280 | v.setX(x); |
281 | } |
282 | |
283 | void Quick3DVector3DValueType::setY(qreal y) |
284 | { |
285 | v.setY(y); |
286 | } |
287 | |
288 | void Quick3DVector3DValueType::setZ(qreal z) |
289 | { |
290 | v.setZ(z); |
291 | } |
292 | |
293 | QVector3D Quick3DVector3DValueType::crossProduct(const QVector3D &vec) const |
294 | { |
295 | return QVector3D::crossProduct(v1: v, v2: vec); |
296 | } |
297 | |
298 | qreal Quick3DVector3DValueType::dotProduct(const QVector3D &vec) const |
299 | { |
300 | return QVector3D::dotProduct(v1: v, v2: vec); |
301 | } |
302 | |
303 | QVector3D Quick3DVector3DValueType::times(const QMatrix4x4 &m) const |
304 | { |
305 | return v * m; |
306 | } |
307 | |
308 | QVector3D Quick3DVector3DValueType::times(const QVector3D &vec) const |
309 | { |
310 | return v * vec; |
311 | } |
312 | |
313 | QVector3D Quick3DVector3DValueType::times(qreal scalar) const |
314 | { |
315 | return v * scalar; |
316 | } |
317 | |
318 | QVector3D Quick3DVector3DValueType::plus(const QVector3D &vec) const |
319 | { |
320 | return v + vec; |
321 | } |
322 | |
323 | QVector3D Quick3DVector3DValueType::minus(const QVector3D &vec) const |
324 | { |
325 | return v - vec; |
326 | } |
327 | |
328 | QVector3D Quick3DVector3DValueType::normalized() const |
329 | { |
330 | return v.normalized(); |
331 | } |
332 | |
333 | qreal Quick3DVector3DValueType::length() const |
334 | { |
335 | return v.length(); |
336 | } |
337 | |
338 | QVector2D Quick3DVector3DValueType::toVector2d() const |
339 | { |
340 | return v.toVector2D(); |
341 | } |
342 | |
343 | QVector4D Quick3DVector3DValueType::toVector4d() const |
344 | { |
345 | return v.toVector4D(); |
346 | } |
347 | |
348 | bool 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 | |
360 | bool Quick3DVector3DValueType::fuzzyEquals(const QVector3D &vec) const |
361 | { |
362 | return qFuzzyCompare(v1: v, v2: vec); |
363 | } |
364 | |
365 | |
366 | QString 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 | |
371 | qreal Quick3DVector4DValueType::x() const |
372 | { |
373 | return v.x(); |
374 | } |
375 | |
376 | qreal Quick3DVector4DValueType::y() const |
377 | { |
378 | return v.y(); |
379 | } |
380 | |
381 | qreal Quick3DVector4DValueType::z() const |
382 | { |
383 | return v.z(); |
384 | } |
385 | |
386 | qreal Quick3DVector4DValueType::w() const |
387 | { |
388 | return v.w(); |
389 | } |
390 | |
391 | void Quick3DVector4DValueType::setX(qreal x) |
392 | { |
393 | v.setX(x); |
394 | } |
395 | |
396 | void Quick3DVector4DValueType::setY(qreal y) |
397 | { |
398 | v.setY(y); |
399 | } |
400 | |
401 | void Quick3DVector4DValueType::setZ(qreal z) |
402 | { |
403 | v.setZ(z); |
404 | } |
405 | |
406 | void Quick3DVector4DValueType::setW(qreal w) |
407 | { |
408 | v.setW(w); |
409 | } |
410 | |
411 | qreal Quick3DVector4DValueType::dotProduct(const QVector4D &vec) const |
412 | { |
413 | return QVector4D::dotProduct(v1: v, v2: vec); |
414 | } |
415 | |
416 | QVector4D Quick3DVector4DValueType::times(const QVector4D &vec) const |
417 | { |
418 | return v * vec; |
419 | } |
420 | |
421 | QVector4D Quick3DVector4DValueType::times(const QMatrix4x4 &m) const |
422 | { |
423 | return v * m; |
424 | } |
425 | |
426 | QVector4D Quick3DVector4DValueType::times(qreal scalar) const |
427 | { |
428 | return v * scalar; |
429 | } |
430 | |
431 | QVector4D Quick3DVector4DValueType::plus(const QVector4D &vec) const |
432 | { |
433 | return v + vec; |
434 | } |
435 | |
436 | QVector4D Quick3DVector4DValueType::minus(const QVector4D &vec) const |
437 | { |
438 | return v - vec; |
439 | } |
440 | |
441 | QVector4D Quick3DVector4DValueType::normalized() const |
442 | { |
443 | return v.normalized(); |
444 | } |
445 | |
446 | qreal Quick3DVector4DValueType::length() const |
447 | { |
448 | return v.length(); |
449 | } |
450 | |
451 | QVector2D Quick3DVector4DValueType::toVector2d() const |
452 | { |
453 | return v.toVector2D(); |
454 | } |
455 | |
456 | QVector3D Quick3DVector4DValueType::toVector3d() const |
457 | { |
458 | return v.toVector3D(); |
459 | } |
460 | |
461 | bool 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 | |
475 | bool Quick3DVector4DValueType::fuzzyEquals(const QVector4D &vec) const |
476 | { |
477 | return qFuzzyCompare(v1: v, v2: vec); |
478 | } |
479 | |
480 | |
481 | QString 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 | |
486 | qreal Quick3DQuaternionValueType::scalar() const |
487 | { |
488 | return v.scalar(); |
489 | } |
490 | |
491 | qreal Quick3DQuaternionValueType::x() const |
492 | { |
493 | return v.x(); |
494 | } |
495 | |
496 | qreal Quick3DQuaternionValueType::y() const |
497 | { |
498 | return v.y(); |
499 | } |
500 | |
501 | qreal Quick3DQuaternionValueType::z() const |
502 | { |
503 | return v.z(); |
504 | } |
505 | |
506 | void Quick3DQuaternionValueType::setScalar(qreal scalar) |
507 | { |
508 | v.setScalar(scalar); |
509 | } |
510 | |
511 | void Quick3DQuaternionValueType::setX(qreal x) |
512 | { |
513 | v.setX(x); |
514 | } |
515 | |
516 | void Quick3DQuaternionValueType::setY(qreal y) |
517 | { |
518 | v.setY(y); |
519 | } |
520 | |
521 | void Quick3DQuaternionValueType::setZ(qreal z) |
522 | { |
523 | v.setZ(z); |
524 | } |
525 | |
526 | |
527 | QMatrix4x4 Quick3DMatrix4x4ValueType::times(const QMatrix4x4 &m) const |
528 | { |
529 | return v * m; |
530 | } |
531 | |
532 | QVector4D Quick3DMatrix4x4ValueType::times(const QVector4D &vec) const |
533 | { |
534 | return v * vec; |
535 | } |
536 | |
537 | QVector3D Quick3DMatrix4x4ValueType::times(const QVector3D &vec) const |
538 | { |
539 | return v * vec; |
540 | } |
541 | |
542 | QMatrix4x4 Quick3DMatrix4x4ValueType::times(qreal factor) const |
543 | { |
544 | return v * factor; |
545 | } |
546 | |
547 | QMatrix4x4 Quick3DMatrix4x4ValueType::plus(const QMatrix4x4 &m) const |
548 | { |
549 | return v + m; |
550 | } |
551 | |
552 | QMatrix4x4 Quick3DMatrix4x4ValueType::minus(const QMatrix4x4 &m) const |
553 | { |
554 | return v - m; |
555 | } |
556 | |
557 | QVector4D Quick3DMatrix4x4ValueType::row(int n) const |
558 | { |
559 | return v.row(index: n); |
560 | } |
561 | |
562 | QVector4D Quick3DMatrix4x4ValueType::column(int m) const |
563 | { |
564 | return v.column(index: m); |
565 | } |
566 | |
567 | qreal Quick3DMatrix4x4ValueType::determinant() const |
568 | { |
569 | return v.determinant(); |
570 | } |
571 | |
572 | QMatrix4x4 Quick3DMatrix4x4ValueType::inverted() const |
573 | { |
574 | return v.inverted(); |
575 | } |
576 | |
577 | QMatrix4x4 Quick3DMatrix4x4ValueType::transposed() const |
578 | { |
579 | return v.transposed(); |
580 | } |
581 | |
582 | bool 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 | |
595 | bool Quick3DMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m) const |
596 | { |
597 | return qFuzzyCompare(m1: v, m2: m); |
598 | } |
599 | |
600 | QString 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 | |
612 | QT_END_NAMESPACE |
613 | |