diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-17 15:39:40 +1100 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-17 15:39:40 +1100 |
commit | cbcd40391c445afb836217a64e0bd96bc54cb805 (patch) | |
tree | e8c3656283af96394432b61f07fb1284fec486e2 /examples/transforms | |
parent | 31359e468c4f1d844f19862f63ed911b66b98068 (diff) |
rendering using transforms
Diffstat (limited to 'examples/transforms')
-rw-r--r-- | examples/transforms/ex_transforms.c | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/examples/transforms/ex_transforms.c b/examples/transforms/ex_transforms.c index edb1c21..b11fbc7 100644 --- a/examples/transforms/ex_transforms.c +++ b/examples/transforms/ex_transforms.c @@ -7,6 +7,14 @@ #include "maths.h" #include "transform_hierarchy.h" +const vec3 pointlight_positions[4] = { + { 0.7, 0.2, 2.0 }, + { 2.3, -3.3, -4.0 }, + { -4.0, 2.0, -12.0 }, + { 0.0, 0.0, -3.0 }, +}; +point_light point_lights[4]; + int main() { core* core = core_bringup(); @@ -18,20 +26,43 @@ int main() { model_handle cube_handle = model_load_obj(core, "assets/models/obj/cube/cube.obj", true); model* cube = &core->models->data[cube_handle.raw]; - // 2. upload vertex data to gpu model_upload_meshes(&core->renderer, cube); + directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 }, + .ambient = (vec3){ 0.2, 0.2, 0.2 }, + .diffuse = (vec3){ 0.5, 0.5, 0.5 }, + .specular = (vec3){ 1.0, 1.0, 1.0 } }; + // point lights setup + for (int i = 0; i < 4; i++) { + point_lights[i].position = pointlight_positions[i]; + point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 }; + point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 }; + point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 }; + point_lights[i].constant = 1.0; + point_lights[i].linear = 0.09; + point_lights[i].quadratic = 0.032; + } + + scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 }; + memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4])); + // Create transform hierarchy transform_hierarchy* transform_tree = transform_hierarchy_create(); transform_node* root_node = transform_hierarchy_root_node(transform_tree); - // Add nodes // -- 4 cubes - transform cube1 = transform_create(vec3(-2.0, -2.0, -2.0), quat_ident(), 2.0); - transform cube2 = transform_create(vec3(2.0, 2.0, 2.0), quat_ident(), 2.0); - transform_hierarchy_add_node(root_node, cube_handle, cube1); - transform_hierarchy_add_node(root_node, cube_handle, cube2); + transform cube1 = transform_create(vec3(1.0, 1.0, 0.0), quat_ident(), 2.0); + transform cube2 = transform_create(vec3(1.0, -1.0, 0.0), quat_ident(), 2.0); + transform cube3 = transform_create(vec3(0.0, 1.0, 0.0), quat_ident(), 2.0); + transform cube4 = transform_create(vec3(0.0, -1.0, 0.0), quat_ident(), 2.0); + transform_node* node1 = transform_hierarchy_add_node(root_node, cube_handle, cube1); + transform_node* node2 = transform_hierarchy_add_node(root_node, cube_handle, cube2); + + transform_node* node3 = transform_hierarchy_add_node(node1, cube_handle, cube3); + transform_node* node4 = transform_hierarchy_add_node(node2, cube_handle, cube4); + transform_hierarchy_debug_print(root_node, core); + // Main loop while (!glfwWindowShouldClose(core->renderer.window)) { @@ -39,8 +70,12 @@ int main() { threadpool_process_results(&core->threadpool, 1); render_frame_begin(&core->renderer); + transform_hierarchy_propagate_transforms(transform_tree); - // insert work here + draw_model(&core->renderer, &cam, cube, &node1->world_matrix_tf, &our_scene); + draw_model(&core->renderer, &cam, cube, &node2->world_matrix_tf, &our_scene); + draw_model(&core->renderer, &cam, cube, &node3->world_matrix_tf, &our_scene); + draw_model(&core->renderer, &cam, cube, &node4->world_matrix_tf, &our_scene); render_frame_end(&core->renderer); } |