-
Notifications
You must be signed in to change notification settings - Fork 47
/
Renderables.h
108 lines (88 loc) · 3.03 KB
/
Renderables.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
#include "math/Vector3.h"
#include "math/Vector4.h"
#include "math/Line.h"
#include "math/Frustum.h"
#include "entitylib.h"
#include "igl.h"
#include "render/RenderableGeometry.h"
#include "../OriginKey.h"
void light_draw_box_lines(const Vector3& origin, const Vector3 points[8]);
namespace entity {
class RenderLightRadiiBox : public OpenGLRenderable {
const Vector3& m_origin;
public:
mutable Vector3 m_points[8];
static ShaderPtr m_state;
RenderLightRadiiBox(const Vector3& origin) : m_origin(origin) {}
void render(const RenderInfo& info) const;
}; // class RenderLightRadiiBox
class RenderLightProjection : public OpenGLRenderable {
const Vector3& _origin;
const Vector3& _start;
const Frustum& _frustum;
public:
RenderLightProjection(const Vector3& origin, const Vector3& start, const Frustum& frustum);
// greebo: Renders the light cone of a projected light (may also be a frustum, when light_start / light_end are set)
void render(const RenderInfo& info) const;
}; // class RenderLightProjection
// The small diamond representing at the light's origin
class RenderableLightOctagon :
public render::RenderableGeometry
{
private:
const scene::INode& _owner;
bool _needsUpdate;
public:
RenderableLightOctagon(const scene::INode& owner) :
_owner(owner),
_needsUpdate(true)
{}
void queueUpdate()
{
_needsUpdate = true;
}
protected:
void updateGeometry() override
{
if (!_needsUpdate) return;
_needsUpdate = false;
// Generate the indexed vertex data
static Vector3 Origin(0, 0, 0);
static Vector3 Extents(8, 8, 8);
// Calculate the light vertices of this bounding box and store them into <points>
Vector3 max(Origin + Extents);
Vector3 min(Origin - Extents);
Vector3 mid(Origin);
// top, bottom, tleft, tright, bright, bleft
std::vector<ArbitraryMeshVertex> vertices
{
ArbitraryMeshVertex({ mid[0], mid[1], max[2] }, {1,0,0}, {0,0}),
ArbitraryMeshVertex({ mid[0], mid[1], min[2] }, {1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], max[1], mid[2] }, {1,0,0}, {0,0}),
ArbitraryMeshVertex({ max[0], max[1], mid[2] }, {1,0,0}, {0,0}),
ArbitraryMeshVertex({ max[0], min[1], mid[2] }, {1,0,0}, {0,0}),
ArbitraryMeshVertex({ min[0], min[1], mid[2] }, {1,0,0}, {0,0}),
};
// Orient the points using the transform
const auto& orientation = _owner.localToWorld();
for (auto& vertex : vertices)
{
vertex.vertex = orientation * vertex.vertex;
}
// Indices are always the same, therefore constant
static const std::vector<unsigned int> Indices
{
0, 2, 3,
0, 3, 4,
0, 4, 5,
0, 5, 2,
1, 2, 5,
1, 5, 4,
1, 4, 3,
1, 3, 2
};
RenderableGeometry::updateGeometry(render::GeometryType::Triangles, vertices, Indices);
}
};
} // namespace entity