/
RenderableArrow.cpp
63 lines (50 loc) · 1.62 KB
/
RenderableArrow.cpp
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
#include "RenderableArrow.h"
#include "EntityNode.h"
namespace entity
{
RenderableArrow::RenderableArrow(EntityNode& node) :
_node(node),
_needsUpdate(true)
{}
void RenderableArrow::queueUpdate()
{
_needsUpdate = true;
}
void RenderableArrow::updateGeometry()
{
if (!_needsUpdate) return;
_needsUpdate = false;
static Vector3 Up(0, 0, 1);
const auto& origin = _node.worldAABB().getOrigin();
const auto& direction = _node.getDirection();
Vector3 left(-direction.y(), direction.x(), 0);
Vector3 endpoint(origin + direction * 32.0);
Vector3 tip1(endpoint + direction * (-8.0) + Up * (-4.0));
Vector3 tip2(tip1 + Up * 8.0);
Vector3 tip3(endpoint + direction * (-8.0) + left * (-4.0));
Vector3 tip4(tip3 + left * 8.0);
std::vector<ArbitraryMeshVertex> vertices
{
ArbitraryMeshVertex(origin, {1,0,0}, {0,0}),
ArbitraryMeshVertex(endpoint, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip1, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip2, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip3, {1,0,0}, {0,0}),
ArbitraryMeshVertex(tip4, {1,0,0}, {0,0}),
};
// Indices are always the same, therefore constant
static const std::vector<unsigned int> Indices
{
0, 1, // origin to endpoint
1, 2, // endpoint to tip1
1, 3, // endpoint to tip2
1, 4, // endpoint to tip3
1, 5, // endpoint to tip4
2, 4, // tip1 to tip3
4, 3, // tip3 to tip2
3, 5, // tip2 to tip4
5, 2, // tip4 to tip1
};
RenderableGeometry::updateGeometry(render::GeometryType::Lines, vertices, Indices);
}
}