summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3d/qt3dquickvaluetypes.cpp
blob: 2c19c67ccacf0a3c7f3bbd0dc84c985ee3895639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qt3dquickvaluetypes_p.h"

QT_BEGIN_NAMESPACE

namespace Qt3DCore {
namespace Quick {

namespace Quick3DValueTypes {
    void registerValueTypes()
    {
        QQmlValueTypeFactory::registerValueTypes("Qt3D", 2, 0);
    }
}

QString Quick3DColorValueType::toString() const
{
    // to maintain behaviour with QtQuick 1.0, we just output normal toString() value.
    return QVariant(v).toString();
}

qreal Quick3DColorValueType::r() const
{
    return v.redF();
}

qreal Quick3DColorValueType::g() const
{
    return v.greenF();
}

qreal Quick3DColorValueType::b() const
{
    return v.blueF();
}

qreal Quick3DColorValueType::a() const
{
    return v.alphaF();
}

void Quick3DColorValueType::setR(qreal r)
{
    v.setRedF(r);
}

void Quick3DColorValueType::setG(qreal g)
{
    v.setGreenF(g);
}

void Quick3DColorValueType::setB(qreal b)
{
    v.setBlueF(b);
}

void Quick3DColorValueType::setA(qreal a)
{
    v.setAlphaF(a);
}


QString Quick3DVector2DValueType::toString() const
{
    return QString(QLatin1String("QVector2D(%1, %2)")).arg(v.x()).arg(v.y());
}

qreal Quick3DVector2DValueType::x() const
{
    return v.x();
}

qreal Quick3DVector2DValueType::y() const
{
    return v.y();
}

void Quick3DVector2DValueType::setX(qreal x)
{
    v.setX(x);
}

void Quick3DVector2DValueType::setY(qreal y)
{
    v.setY(y);
}

qreal Quick3DVector2DValueType::dotProduct(const QVector2D &vec) const
{
    return QVector2D::dotProduct(v, vec);
}

QVector2D Quick3DVector2DValueType::times(const QVector2D &vec) const
{
    return v * vec;
}

QVector2D Quick3DVector2DValueType::times(qreal scalar) const
{
    return v * scalar;
}

QVector2D Quick3DVector2DValueType::plus(const QVector2D &vec) const
{
    return v + vec;
}

QVector2D Quick3DVector2DValueType::minus(const QVector2D &vec) const
{
    return v - vec;
}

QVector2D Quick3DVector2DValueType::normalized() const
{
    return v.normalized();
}

qreal Quick3DVector2DValueType::length() const
{
    return v.length();
}

QVector3D Quick3DVector2DValueType::toVector3d() const
{
    return v.toVector3D();
}

QVector4D Quick3DVector2DValueType::toVector4d() const
{
    return v.toVector4D();
}

bool Quick3DVector2DValueType::fuzzyEquals(const QVector2D &vec, qreal epsilon) const
{
    qreal absEps = qAbs(epsilon);
    if (qAbs(v.x() - vec.x()) > absEps)
        return false;
    if (qAbs(v.y() - vec.y()) > absEps)
        return false;
    return true;
}

bool Quick3DVector2DValueType::fuzzyEquals(const QVector2D &vec) const
{
    return qFuzzyCompare(v, vec);
}


QString Quick3DVector3DValueType::toString() const
{
    return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(v.x()).arg(v.y()).arg(v.z());
}

qreal Quick3DVector3DValueType::x() const
{
    return v.x();
}

qreal Quick3DVector3DValueType::y() const
{
    return v.y();
}

qreal Quick3DVector3DValueType::z() const
{
    return v.z();
}

void Quick3DVector3DValueType::setX(qreal x)
{
    v.setX(x);
}

void Quick3DVector3DValueType::setY(qreal y)
{
    v.setY(y);
}

void Quick3DVector3DValueType::setZ(qreal z)
{
    v.setZ(z);
}

QVector3D Quick3DVector3DValueType::crossProduct(const QVector3D &vec) const
{
    return QVector3D::crossProduct(v, vec);
}

qreal Quick3DVector3DValueType::dotProduct(const QVector3D &vec) const
{
    return QVector3D::dotProduct(v, vec);
}

QVector3D Quick3DVector3DValueType::times(const QMatrix4x4 &m) const
{
    return v * m;
}

QVector3D Quick3DVector3DValueType::times(const QVector3D &vec) const
{
    return v * vec;
}

QVector3D Quick3DVector3DValueType::times(qreal scalar) const
{
    return v * scalar;
}

QVector3D Quick3DVector3DValueType::plus(const QVector3D &vec) const
{
    return v + vec;
}

QVector3D Quick3DVector3DValueType::minus(const QVector3D &vec) const
{
    return v - vec;
}

QVector3D Quick3DVector3DValueType::normalized() const
{
    return v.normalized();
}

qreal Quick3DVector3DValueType::length() const
{
    return v.length();
}

QVector2D Quick3DVector3DValueType::toVector2d() const
{
    return v.toVector2D();
}

QVector4D Quick3DVector3DValueType::toVector4d() const
{
    return v.toVector4D();
}

bool Quick3DVector3DValueType::fuzzyEquals(const QVector3D &vec, qreal epsilon) const
{
    qreal absEps = qAbs(epsilon);
    if (qAbs(v.x() - vec.x()) > absEps)
        return false;
    if (qAbs(v.y() - vec.y()) > absEps)
        return false;
    if (qAbs(v.z() - vec.z()) > absEps)
        return false;
    return true;
}

bool Quick3DVector3DValueType::fuzzyEquals(const QVector3D &vec) const
{
    return qFuzzyCompare(v, vec);
}


QString Quick3DVector4DValueType::toString() const
{
    return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(v.x()).arg(v.y()).arg(v.z()).arg(v.w());
}

qreal Quick3DVector4DValueType::x() const
{
    return v.x();
}

qreal Quick3DVector4DValueType::y() const
{
    return v.y();
}

qreal Quick3DVector4DValueType::z() const
{
    return v.z();
}

qreal Quick3DVector4DValueType::w() const
{
    return v.w();
}

void Quick3DVector4DValueType::setX(qreal x)
{
    v.setX(x);
}

void Quick3DVector4DValueType::setY(qreal y)
{
    v.setY(y);
}

void Quick3DVector4DValueType::setZ(qreal z)
{
    v.setZ(z);
}

void Quick3DVector4DValueType::setW(qreal w)
{
    v.setW(w);
}

qreal Quick3DVector4DValueType::dotProduct(const QVector4D &vec) const
{
    return QVector4D::dotProduct(v, vec);
}

QVector4D Quick3DVector4DValueType::times(const QVector4D &vec) const
{
    return v * vec;
}

QVector4D Quick3DVector4DValueType::times(const QMatrix4x4 &m) const
{
    return v * m;
}

QVector4D Quick3DVector4DValueType::times(qreal scalar) const
{
    return v * scalar;
}

QVector4D Quick3DVector4DValueType::plus(const QVector4D &vec) const
{
    return v + vec;
}

QVector4D Quick3DVector4DValueType::minus(const QVector4D &vec) const
{
    return v - vec;
}

QVector4D Quick3DVector4DValueType::normalized() const
{
    return v.normalized();
}

qreal Quick3DVector4DValueType::length() const
{
    return v.length();
}

QVector2D Quick3DVector4DValueType::toVector2d() const
{
    return v.toVector2D();
}

QVector3D Quick3DVector4DValueType::toVector3d() const
{
    return v.toVector3D();
}

bool Quick3DVector4DValueType::fuzzyEquals(const QVector4D &vec, qreal epsilon) const
{
    qreal absEps = qAbs(epsilon);
    if (qAbs(v.x() - vec.x()) > absEps)
        return false;
    if (qAbs(v.y() - vec.y()) > absEps)
        return false;
    if (qAbs(v.z() - vec.z()) > absEps)
        return false;
    if (qAbs(v.w() - vec.w()) > absEps)
        return false;
    return true;
}

bool Quick3DVector4DValueType::fuzzyEquals(const QVector4D &vec) const
{
    return qFuzzyCompare(v, vec);
}


QString Quick3DQuaternionValueType::toString() const
{
    return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(v.scalar()).arg(v.x()).arg(v.y()).arg(v.z());
}

qreal Quick3DQuaternionValueType::scalar() const
{
    return v.scalar();
}

qreal Quick3DQuaternionValueType::x() const
{
    return v.x();
}

qreal Quick3DQuaternionValueType::y() const
{
    return v.y();
}

qreal Quick3DQuaternionValueType::z() const
{
    return v.z();
}

void Quick3DQuaternionValueType::setScalar(qreal scalar)
{
    v.setScalar(scalar);
}

void Quick3DQuaternionValueType::setX(qreal x)
{
    v.setX(x);
}

void Quick3DQuaternionValueType::setY(qreal y)
{
    v.setY(y);
}

void Quick3DQuaternionValueType::setZ(qreal z)
{
    v.setZ(z);
}


QMatrix4x4 Quick3DMatrix4x4ValueType::times(const QMatrix4x4 &m) const
{
    return v * m;
}

QVector4D Quick3DMatrix4x4ValueType::times(const QVector4D &vec) const
{
    return v * vec;
}

QVector3D Quick3DMatrix4x4ValueType::times(const QVector3D &vec) const
{
    return v * vec;
}

QMatrix4x4 Quick3DMatrix4x4ValueType::times(qreal factor) const
{
    return v * factor;
}

QMatrix4x4 Quick3DMatrix4x4ValueType::plus(const QMatrix4x4 &m) const
{
    return v + m;
}

QMatrix4x4 Quick3DMatrix4x4ValueType::minus(const QMatrix4x4 &m) const
{
    return v - m;
}

QVector4D Quick3DMatrix4x4ValueType::row(int n) const
{
    return v.row(n);
}

QVector4D Quick3DMatrix4x4ValueType::column(int m) const
{
    return v.column(m);
}

qreal Quick3DMatrix4x4ValueType::determinant() const
{
    return v.determinant();
}

QMatrix4x4 Quick3DMatrix4x4ValueType::inverted() const
{
    return v.inverted();
}

QMatrix4x4 Quick3DMatrix4x4ValueType::transposed() const
{
    return v.transposed();
}

bool Quick3DMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m, qreal epsilon) const
{
    qreal absEps = qAbs(epsilon);
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            if (qAbs(v(i,j) - m(i,j)) > absEps) {
                return false;
            }
        }
    }
    return true;
}

bool Quick3DMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m) const
{
    return qFuzzyCompare(v, m);
}

QString Quick3DMatrix4x4ValueType::toString() const
{
    return QString(QLatin1String("QMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)"))
            .arg(v(0, 0)).arg(v(0, 1)).arg(v(0, 2)).arg(v(0, 3))
            .arg(v(1, 0)).arg(v(1, 1)).arg(v(1, 2)).arg(v(1, 3))
            .arg(v(2, 0)).arg(v(2, 1)).arg(v(2, 2)).arg(v(2, 3))
            .arg(v(3, 0)).arg(v(3, 1)).arg(v(3, 2)).arg(v(3, 3));
}

} // namespace Quick
} // namespace Qt3DCore

QT_END_NAMESPACE