update djstdlib

This commit is contained in:
Daniel Ledda
2025-01-16 09:39:17 +01:00
parent c0deceec65
commit a0818f0950
8 changed files with 218 additions and 157 deletions

View File

@@ -25,7 +25,6 @@
#include "lib/loaders/tinyobj.h"
struct Entity;
struct Polycube;
struct SceneGraphNode;
uint32 new_entity();
Entity *get_entity(uint32 id);
@@ -104,6 +103,19 @@ struct SceneGraphNode {
uint32 entity;
};
struct Frame {
uint32 width;
uint32 height;
int32 x;
int32 y;
Camera* cam;
};
struct Polycube {
int graph_node;
glm::vec3 color;
};
struct GlobalAppState {
bool wireframe = false;
uint32 current_polycube;
@@ -111,6 +123,7 @@ struct GlobalAppState {
uint32 light;
Shader *active_shader;
std::vector<Polycube> polycubes;
Camera* camera;
};
GlobalAppState app_state = {};
@@ -133,11 +146,6 @@ void recalculate_sg_node(SceneGraphNode *n) {
);
}
struct Polycube {
int graph_node;
glm::vec3 color;
};
void show_polycube(Polycube *p) {
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
for (uint32 &child : node->children) {
@@ -167,14 +175,6 @@ glm::vec3 centreFromPolycube(Polycube *p) {
return centre;
}
struct Frame {
uint32 width;
uint32 height;
int32 x;
int32 y;
Camera* cam;
};
Frame createFrame(Arena *arena, uint32 width, uint32 height, uint32 x, uint32 y) {
Frame result = {0};
result.width = width;
@@ -311,7 +311,11 @@ void process_input(GLFWwindow *window, Input *input, Input *prevInput) {
}
real64 deltaY = (input->mouse.y - prevInput->mouse.y) * 0.006;
if (deltaY > 0.00000001 || deltaY < -0.00000001) {
polycube_graph_node->rotation = polycube_graph_node->rotation * glm::quat(glm::vec3(deltaY, 0, 0));
auto eyes = glm::normalize(app_state.camera->pos - polycube_graph_node->translation);
auto rotationAxis = glm::cross(eyes, glm::vec3(0, 1, 0));
auto localRotationAxis = glm::vec3(glm::inverse(polycube_graph_node->world) * glm::vec4(rotationAxis, 0));
auto rotation = glm::quat(deltaY, localRotationAxis);
polycube_graph_node->rotation = rotation * polycube_graph_node->rotation;
}
}
}
@@ -393,11 +397,14 @@ int main_gfx() {
return -1;
}
Frame main_frame = createFrame(arena, 800, 600, 0, 0);
app_state.current_polycube = 0;
app_state.last_polycube_visible = 6;
app_state.active_shader = 0;
app_state.polycubes = {};
app_state.light = new_entity();
app_state.camera = main_frame.cam;
SceneGraphNode *light_graph_node = get_scene_graph_node(get_entity(app_state.light)->scene_graph_node);
light_graph_node->translation = glm::vec3(4.0f, 24.0f, 6.0f);
@@ -410,8 +417,6 @@ int main_gfx() {
cube_mesh = createMesh("./assets/models/c000000.obj");
wall_tex = createTexture("./assets/textures/brick-wall.jpg");
Frame main_frame = createFrame(arena, 800, 600, 0, 0);
SceneGraphNode root_node = {};
init_sg_node(&root_node);
@@ -424,8 +429,8 @@ int main_gfx() {
root_node.children.push_back(app_state.polycubes.back().graph_node);
}
main_frame.cam->pos = glm::vec3(4.0f, 4.0f, 4.0f);
camera_look_at(main_frame.cam, 0.0f, 0.0f, 0.0f);
app_state.camera->pos = glm::vec3(4.0f, 4.0f, 4.0f);
camera_look_at(app_state.camera, 0.0f, 0.0f, 0.0f);
glUseProgram(app_state.active_shader->prog_id);