/
RenderableCurve.h
69 lines (52 loc) · 1.41 KB
/
RenderableCurve.h
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
#pragma once
#include <vector>
#include "irenderable.h"
#include "render.h"
#include "render/RenderableGeometry.h"
namespace entity
{
class RenderableCurve :
public render::RenderableGeometry
{
private:
const IEntityNode& _entity;
bool _needsUpdate;
public:
std::vector<VertexCb> m_vertices;
RenderableCurve(const IEntityNode& entity) :
_entity(entity),
_needsUpdate(true)
{}
void queueUpdate()
{
_needsUpdate = true;
}
protected:
void updateGeometry() override
{
if (!_needsUpdate) return;
_needsUpdate = false;
if (m_vertices.size() < 2)
{
clear();
return;
}
std::vector<ArbitraryMeshVertex> vertices;
std::vector<unsigned int> indices;
vertices.reserve(m_vertices.size());
indices.reserve(m_vertices.size() << 1);
unsigned int index = 0;
auto colour = _entity.getEntityColour();
for (const auto& v : m_vertices)
{
vertices.push_back(ArbitraryMeshVertex(v.vertex, { 0,0,1 }, { 0,0 }, colour));
indices.push_back(index);
indices.push_back(++index);
};
// Remove the last two superfluous indices
indices.pop_back();
indices.pop_back();
RenderableGeometry::updateGeometryWithData(render::GeometryType::Lines, vertices, indices);
}
};
} // namespace entity