src/camera.c

changeset 101
febf3dc10011
parent 99
ac143db979dc
--- a/src/camera.c	Mon Apr 28 21:13:01 2025 +0200
+++ b/src/camera.c	Tue Apr 29 21:51:29 2025 +0200
@@ -25,8 +25,28 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "ascension/context.h"
 #include "ascension/camera.h"
 
+void asc_camera_init(AscCamera *camera, AscCameraParams params) {
+    if (params.type == ASC_CAMERA_ORTHO) {
+        asc_recti rect = params.ortho.rect;
+        if (rect.size.width <= 0 || rect.size.height <= 0) {
+            rect.size.width = 1;
+            rect.size.height = 1;
+        }
+        asc_camera_ortho(camera, rect);
+    } else if (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(camera, 0, sizeof(AscCamera));
+    }
+    camera->viewport_update_func = params.viewport_update_func;
+    camera->projection_update_func = params.projection_update_func;
+}
+
 void asc_camera_ortho(AscCamera *camera, asc_recti rect) {
     asc_mat4f_unit(camera->view);
     float left = (float) rect.pos.x;

mercurial