Vivid
Loading...
Searching...
No Matches
PointLightComponent.cpp
1#include "PointLightComponent.h"
2#include "imgui/imgui/imgui.h"
3#include "core/renderer/shapes/Quad3d.h"
4#include "core/ecs/components/TransformComponent.h"
5#include "core/ecs/components/model/ModelComponent.h"
6#include "core/ecs/ECS.h"
7#include "common/maths/Vec.h"
8
9namespace Vivid
10{
11 PointLightComponent::PointLightComponent(Maths::Vec3 color)
12 : m_Color(color)
13 {
14 }
15
16 void PointLightComponent::Draw(Camera* camera)
17 {
18 auto component = ECS::GetComponent(ComponentType::TransformComponent, m_OwnerEntityID);
19
20 float scale = dynamic_cast<TransformComponent*>(component.get())->GetScale().x;
21 Quad3d* quad = new Vivid::Quad3d(10.0f / scale, m_Color);
22 ModelComponent* modelComponent = new Vivid::ModelComponent();
23
24 if (m_Shader == nullptr)
25 {
26 m_Shader = Vivid::Shader::Create("./../assets/shaders/basic.vertexShader.glsl",
27 "./../assets/shaders/basic.pixelShader.glsl");
28 }
29
30 m_Mesh = new Vivid::Mesh(*quad);
31 m_Mesh->BindShader(m_Shader);
32
33 modelComponent->AddMesh(m_Mesh);
34 modelComponent->SetEntity(m_OwnerEntityID);
35 modelComponent->Draw(camera);
36 }
37
38 void PointLightComponent::ImGuiRender()
39 {
40 ImGui::ColorPicker3("Color", &m_Color.x);
41 ImGui::SliderFloat("Intensity", &m_Intensity, 0.0f, 10.0f);
42 }
43}
A class that represents the camera.
Definition: Camera.h:25
Contains a Mesh.
Definition: Mesh.h:32
Contains a ModelComponent.