learn-opengl/19-blending-facecull/src/components.hpp
2026-08-30 13:51:01 -04:00

114 lines
2.6 KiB
C++

#pragma once
#include <glm/glm.hpp>
#include <vector>
#include <unordered_map>
#include "json.hpp"
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
#define MAX_LIGHTS 4
namespace components {
template <typename T> struct NameOf;
struct Material {
glm::vec3 ambient{0.1f,0.1f,0.1f};
float shininess{32.0f};
unsigned int diffuseMap = 0;
unsigned int specularMap = 0;
};
ENROLL_COMPONENT(Material, ambient, shininess, diffuseMap, specularMap);
struct Light {
glm::vec3 position{0.0f, 0.0f, 0.0f};
glm::vec3 direction{0.0f, 0.0f, 0.0f};
glm::vec3 ambient{0.0f, 0.0f, 0.0f};
glm::vec3 diffuse{0.0f, 0.0f, 0.0f};
glm::vec3 specular{0.0f, 0.0f, 0.0f};
float constant=0.0f;
float linear=0.0f;
float quadratic=0.0f;
float cut_off=0.0f;
float outer_cut_off=0.0f;
bool on=true;
void adjust(float amount) {
ambient += amount;
diffuse += amount;
specular += amount;
}
};
ENROLL_COMPONENT(Light,
position, direction,
ambient, diffuse, specular,
constant, linear, quadratic,
cut_off, outer_cut_off, on);
struct Lighting {
std::vector<Light> directional;
std::vector<Light> positioned;
std::vector<Light> spot;
Light camera;
};
ENROLL_COMPONENT(Lighting, directional, positioned, spot, camera);
struct Camera {
glm::vec3 position{0.0f, 0.0f, 3.0f};
glm::vec3 front{0.0f, 0.0f, -1.0f};
glm::vec3 up{0.0f, 1.0f, 0.0f};
glm::vec3 direction{0.0f, 0.0f, 0.0f};
float movement_speed = 20.0f;
};
ENROLL_COMPONENT(Camera, position, front, up, direction, movement_speed);
struct Model {
std::string directory;
std::string model_path;
};
ENROLL_COMPONENT(Model, directory, model_path);
using Position = glm::vec3;
struct Rotation {
float angle = 0;
glm::vec3 axes{1.0f, 0.0f, 0.0f};
};
ENROLL_COMPONENT(Rotation, angle, axes);
struct Thing {
std::string model;
std::string material;
Position position;
Rotation rotation;
float scale;
};
ENROLL_COMPONENT(Thing, model, material, position, rotation, scale);
struct Shader {
std::string vertex_path;
std::string frag_path;
};
ENROLL_COMPONENT(Shader, vertex_path, frag_path);
struct Scene {
components::Shader shader;
components::Shader light_shader;
std::unordered_map<std::string, Material> materials;
std::unordered_map<std::string, Model> models;
std::vector<Thing> things;
Camera camera;
Lighting light;
};
ENROLL_COMPONENT(Scene, shader, light_shader, materials, models, things, camera, light);
}