File: lineboxgeometry.cpp

package info (click to toggle)
qt6-quick3d 6.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 143,588 kB
  • sloc: cpp: 395,989; ansic: 41,469; xml: 288; sh: 242; makefile: 32
file content (84 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download | duplicates (3)
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
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "lineboxgeometry.h"
#include <QRandomGenerator>
#include <QVector3D>
#include <array>

LineBoxGeometry::LineBoxGeometry()
{
    constexpr int kStride = sizeof(QVector3D);

    QByteArray vertexData(24 * kStride, Qt::Initialization::Uninitialized);
    QVector3D *p = reinterpret_cast<QVector3D *>(vertexData.data());

    std::array<QVector3D, 8> pts;
    pts[0] = QVector3D(-50, -50, -50);
    pts[1] = QVector3D(-50, -50, +50);
    pts[2] = QVector3D(-50, +50, +50);
    pts[3] = QVector3D(-50, +50, -50);
    pts[4] = QVector3D(+50, -50, -50);
    pts[5] = QVector3D(+50, -50, +50);
    pts[6] = QVector3D(+50, +50, +50);
    pts[7] = QVector3D(+50, +50, -50);
    // left side
    *p = pts[0];
    p++;
    *p = pts[1];
    p++;
    *p = pts[1];
    p++;
    *p = pts[2];
    p++;
    *p = pts[2];
    p++;
    *p = pts[3];
    p++;
    *p = pts[3];
    p++;
    *p = pts[0];
    p++;
    // right side
    *p = pts[4];
    p++;
    *p = pts[5];
    p++;
    *p = pts[5];
    p++;
    *p = pts[6];
    p++;
    *p = pts[6];
    p++;
    *p = pts[7];
    p++;
    *p = pts[7];
    p++;
    *p = pts[4];
    p++;
    // across
    *p = pts[0];
    p++;
    *p = pts[4];
    p++;
    *p = pts[1];
    p++;
    *p = pts[5];
    p++;
    *p = pts[2];
    p++;
    *p = pts[6];
    p++;
    *p = pts[3];
    p++;
    *p = pts[7];
    p++;

    setVertexData(vertexData);
    setStride(kStride);
    setBounds(QVector3D(-50.0f, -50.0f, -50.0f), QVector3D(+50.0f, +50.0f, +50.0f));

    setPrimitiveType(QQuick3DGeometry::PrimitiveType::Lines);

    addAttribute(QQuick3DGeometry::Attribute::PositionSemantic, 0, QQuick3DGeometry::Attribute::F32Type);
}