TerraForge3D  2.3.1
3D Terrain And Landscape Generator
LightManager.cpp
1#include "Lighting/LightManager.h"
2#include "imgui/imgui.h"
3
4#include "glm/gtc/type_ptr.hpp"
5
6#include <string>
7
8static int ID = 0;
9
10LightManager::LightManager()
11{
12 lightManagerID = ID++;
13 position.y = -0.3f;
14 position.x = position.z = 0.0f;
15 color[0] = color[1] = color[2] = color[3] = 0.8;
16 ambientColor[0] = ambientColor[1] = ambientColor[2] = ambientColor[3] = 0.8;
17 strength = 50.0f;
18}
19
20LightManager::~LightManager()
21{
22}
23
24void LightManager::ShowSettings(bool renderWindow, bool *pOpen)
25{
26 if (*pOpen)
27 {
28 if (renderWindow)
29 {
30 ImGui::Begin(("Light Setting##" + std::to_string(lightManagerID)).c_str(), pOpen);
31 }
32
33 ImGui::Text("Strength");
34 ImGui::DragFloat("##lightStrength", &strength, 0.1f);
35 ImGui::Text("Position");
36 ImGui::DragFloat3("##lightPosition", &position[0], 0.01f);
37 ImGui::Separator();
38 ImGui::Separator();
39 ImGui::Text("Light Color");
40 ImGui::ColorEdit3("##lightColor", color);
41
42 if (renderWindow)
43 {
44 ImGui::End();
45 }
46 }
47}
48
49nlohmann::json LightManager::Save()
50{
51 nlohmann::json data, tmp;
52 tmp["x"] = position.x;
53 tmp["y"] = position.y;
54 tmp["z"] = position.z;
55 data["position"] = tmp;
56 tmp = nlohmann::json();
57 tmp["r"] = color[0];
58 tmp["g"] = color[1];
59 tmp["b"] = color[2];
60 tmp["a"] = color[3];
61 data["color"] = tmp;
62 data["strength"] = strength;
63 return data;
64}
65
66void LightManager::Load(nlohmann::json data)
67{
68 position[0] = data["position"]["x"];
69 position[1] = data["position"]["y"];
70 position[2] = data["position"]["z"];
71 color[0] = data["color"]["r"];
72 color[1] = data["color"]["g"];
73 color[2] = data["color"]["b"];
74 color[3] = data["color"]["a"];
75 strength = data["strength"];
76}
a class to store JSON values
Definition: json.hpp:17860
basic_json<> json
default JSON class
Definition: json.hpp:3411