1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qcollisiondebugmeshbuilder_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | QCollisionDebugMeshBuilder::QCollisionDebugMeshBuilder() { } |
9 | |
10 | void QCollisionDebugMeshBuilder::reset() |
11 | { |
12 | m_vertices.clear(); |
13 | m_normals.clear(); |
14 | } |
15 | |
16 | void QCollisionDebugMeshBuilder::addLine(const QVector3D &start, const QVector3D &end, |
17 | const QVector3D &normal) |
18 | { |
19 | m_vertices.append(t: start); |
20 | m_vertices.append(t: end); |
21 | m_normals.append(t: normal); |
22 | } |
23 | |
24 | QByteArray QCollisionDebugMeshBuilder::generateVertexArray() |
25 | { |
26 | QByteArray output; |
27 | const int size = m_normals.count(); |
28 | output.resize(size: 4 * 4 * sizeof(float) * size); |
29 | |
30 | float *data = reinterpret_cast<float *>(output.data()); |
31 | |
32 | for (int i = 0; i < size; ++i) { |
33 | const QVector3D &start = m_vertices[i * 2]; |
34 | const QVector3D &end = m_vertices[i * 2 + 1]; |
35 | const QVector3D &normal = m_normals[i]; |
36 | |
37 | data[0] = start.x(); |
38 | data[1] = start.y(); |
39 | data[2] = start.z(); |
40 | data[4] = 1.0f; |
41 | |
42 | data[5] = normal.x(); |
43 | data[6] = normal.y(); |
44 | data[7] = normal.z(); |
45 | data[8] = 0.0f; |
46 | |
47 | data += 8; |
48 | data[0] = end.x(); |
49 | data[1] = end.y(); |
50 | data[2] = end.z(); |
51 | data[4] = 1.0f; |
52 | |
53 | data[5] = normal.x(); |
54 | data[6] = normal.y(); |
55 | data[7] = normal.z(); |
56 | data[8] = 0.0f; |
57 | |
58 | data += 8; |
59 | } |
60 | |
61 | return output; |
62 | } |
63 | |
64 | QT_END_NAMESPACE |
65 |