-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxObject.cpp
More file actions
81 lines (59 loc) · 2.22 KB
/
BoxObject.cpp
File metadata and controls
81 lines (59 loc) · 2.22 KB
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
#include "BoxObject.h"
#include <QVector3D>
#include <QOpenGLShaderProgram>
#include "recon.h"
BoxObject::BoxObject() :
mVBO(QOpenGLBuffer::VertexBuffer),
mEBO(QOpenGLBuffer::IndexBuffer)
{
Transform3D trans;
auto pointCloud = PointCloud("MultiView/views.txt", 4876.8, 2032, 1520);
const size_t pointCount = pointCloud.size();
for(unsigned int i = 0; i < pointCount; ++i) {
BoxMesh b(0.005, 0.005, 0.005);
trans.setTranslation(pointCloud[i][0], pointCloud[i][1], pointCloud[i][2]);
b.transform(trans.toMatrix());
mBoxes.push_back(b);
}
unsigned int NBoxes = mBoxes.size();
mVertexBufferData.resize(NBoxes*BoxMesh::VertexCount);
mElementBufferData.resize(NBoxes*BoxMesh::IndexCount);
Vertex * vertexBuffer = mVertexBufferData.data();
unsigned int vertexCount = 0;
GLuint * elementBuffer = mElementBufferData.data();
for (const BoxMesh & b : mBoxes)
b.copy2Buffer(vertexBuffer, elementBuffer, vertexCount);
}
void BoxObject::create(QOpenGLShaderProgram * shaderProgramm) {
mVAO.create();
mVAO.bind();
mVBO.create();
mVBO.bind();
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
int vertexMemSize = mVertexBufferData.size()*sizeof(Vertex);
qDebug() << "BoxObject - VertexBuffer size =" << vertexMemSize/1024.0 << "kByte";
mVBO.allocate(mVertexBufferData.data(), vertexMemSize);
mEBO.create();
mEBO.bind();
mEBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
int elementMemSize = mElementBufferData.size()*sizeof(GLuint);
qDebug() << "BoxObject - ElementBuffer size =" << elementMemSize/1024.0 << "kByte";
mEBO.allocate(mElementBufferData.data(), elementMemSize);
shaderProgramm->enableAttributeArray(0);
shaderProgramm->setAttributeBuffer(0, GL_FLOAT, 0, 3, sizeof(Vertex));
shaderProgramm->enableAttributeArray(1);
shaderProgramm->setAttributeBuffer(1, GL_FLOAT, offsetof(Vertex, r), 3, sizeof(Vertex));
mVAO.release();
mVBO.release();
mEBO.release();
}
void BoxObject::destroy() {
mVAO.destroy();
mVBO.destroy();
mEBO.destroy();
}
void BoxObject::render() {
mVAO.bind();
glDrawElements(GL_TRIANGLES, mElementBufferData.size(), GL_UNSIGNED_INT, nullptr);
mVAO.release();
}