forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineRenderer.cpp
More file actions
85 lines (72 loc) · 1.71 KB
/
Copy pathLineRenderer.cpp
File metadata and controls
85 lines (72 loc) · 1.71 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
82
83
84
85
#include "PCH.h"
#include "Component/LineRenderer.h"
#include "Component/Camera.h"
#include "GameObject.h"
#include "Core/Logger.h"
#include <assert.h>
namespace sh::game
{
SH_GAME_API LineRenderer::LineRenderer(GameObject& owner) :
MeshRenderer(owner),
start({ 0, 0, 0 }), end({ 0, 1, 0 }), mesh(),
color({ 1.f, 0.f, 0.f, 1.f })
{
mesh.SetVertex({ start, end });
mesh.SetIndices({ 0, 1 });
mesh.SetTopology(render::Mesh::Topology::Line);
mesh.lineWidth = 1.f;
mesh.Build(world.renderer);
Super::SetMesh(&mesh);
mat = world.materials.GetResource("LineMaterial");
assert(mat);
Super::SetMaterial(mat);
}
SH_GAME_API void LineRenderer::Awake()
{
Super::Awake();
}
SH_GAME_API void LineRenderer::Update()
{
for (auto& [cam, drawable] : drawables)
{
if (!cam->active)
continue;
struct Points
{
alignas(16) glm::vec3 start;
alignas(16) glm::vec3 end;
} points{ start, end };
struct Color
{
alignas(16) glm::vec4 color;
} color{ this->color };
drawable->SetUniformData(1, &points, render::IDrawable::Stage::Vertex);
drawable->SetUniformData(2, &color, render::IDrawable::Stage::Fragment);
}//drawables
Super::Update();
}
SH_GAME_API void LineRenderer::SetStart(const Vec3& start)
{
this->start = start;
}
SH_GAME_API void LineRenderer::SetEnd(const Vec3& start)
{
this->end = start;
}
SH_GAME_API void LineRenderer::SetColor(const Vec4& color)
{
this->color = color;
}
SH_GAME_API auto LineRenderer::GetStart() const -> const Vec3&
{
return start;
}
SH_GAME_API auto LineRenderer::GetEnd() const -> const Vec3&
{
return end;
}
SH_GAME_API auto LineRenderer::GetColor() const -> const Vec4&
{
return color;
}
}//namespace