-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlight.cpp
More file actions
25 lines (22 loc) · 906 Bytes
/
Copy pathlight.cpp
File metadata and controls
25 lines (22 loc) · 906 Bytes
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
#include "light.hpp"
#include <deserialize-utils.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <json/json.hpp>
namespace our {
void Light::deserialize(const nlohmann::json& data) {
if (!data.is_object()) return;
std::string typeStr = data.value("lightType", "point");
if (typeStr == "directional") {
type = LightType::DIRECTIONAL;
} else if (typeStr == "point") {
type = LightType::POINT;
} else if (typeStr == "spot") {
type = LightType::SPOT;
}
color = data.value("color", glm::vec3(1.0f, 1.0f, 1.0f));
attenuation = data.value("attenuation", glm::vec3(1.0f, 0.0f, 0.0f));
glm::vec2 spotAnglesDegrees = data.value("spotAngles", glm::vec2(15.0f, 30.0f));
spotAngles = {glm::radians(spotAnglesDegrees.x), glm::radians(spotAnglesDegrees.y)};
}
} // namespace our