src/scene.c

changeset 101
febf3dc10011
parent 100
5231da78831e
--- a/src/scene.c	Mon Apr 28 21:13:01 2025 +0200
+++ b/src/scene.c	Tue Apr 29 21:51:29 2025 +0200
@@ -45,16 +45,7 @@
         asc_wprintf("Scene %"PRIxPTR" is already initialized - initialization skipped.", (uintptr_t) scene);
         return;
     }
-    if (camera_params.type == ASC_CAMERA_ORTHO) {
-        asc_camera_ortho(&scene->camera, camera_params.ortho.rect);
-    } else if (camera_params.type == ASC_CAMERA_PERSPECTIVE) {
-        // TODO: implement
-        asc_wprintf("Camera type PERSPECTIVE is not yet implemented.");
-    } else {
-        // at least zero all the bytes (law of the least surprise)
-        memset(&scene->camera, 0, sizeof(AscCamera));
-    }
-    scene->camera.viewport_update_func = camera_params.viewport_update_func;
+    asc_camera_init(&scene->camera, camera_params);
     scene->root = asc_scene_node_empty();
 
     asc_dprintf("Initialized scene %"PRIxPTR, (uintptr_t) scene);
@@ -72,11 +63,15 @@
 
     // if the window resized, we must update the viewport
     if (asc_active_window->resized) {
+        asc_vec2i window_size = asc_active_window->dimensions;
         if (scene->camera.viewport_update_func == NULL) {
             // this assumes the viewport was initialized with zeros!
-            scene->camera.viewport.size = asc_active_window->dimensions;
+            scene->camera.viewport.size = window_size;
         } else {
-            scene->camera.viewport = scene->camera.viewport_update_func(asc_active_window->dimensions);
+            scene->camera.viewport = scene->camera.viewport_update_func(window_size);
+        }
+        if (scene->camera.projection_update_func != NULL) {
+            scene->camera.projection_update_func(&scene->camera, window_size);
         }
     }
 

mercurial