src/camera.c

Thu, 28 Mar 2024 23:30:21 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 28 Mar 2024 23:30:21 +0100
changeset 45
18de2af03531
parent 41
df81d493716e
child 47
44457f6cb0a2
permissions
-rw-r--r--

simplify how transforms work

universe@37 1 /*
universe@37 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@37 3 * Copyright 2023 Mike Becker. All rights reserved.
universe@37 4 *
universe@37 5 * Redistribution and use in source and binary forms, with or without
universe@37 6 * modification, are permitted provided that the following conditions are met:
universe@37 7 *
universe@37 8 * 1. Redistributions of source code must retain the above copyright
universe@37 9 * notice, this list of conditions and the following disclaimer.
universe@37 10 *
universe@37 11 * 2. Redistributions in binary form must reproduce the above copyright
universe@37 12 * notice, this list of conditions and the following disclaimer in the
universe@37 13 * documentation and/or other materials provided with the distribution.
universe@37 14 *
universe@37 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@37 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@37 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@37 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@37 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@37 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@37 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@37 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@37 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@37 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@37 25 * POSSIBILITY OF SUCH DAMAGE.
universe@37 26 */
universe@37 27
universe@37 28 #include "ascension/camera.h"
universe@37 29
universe@37 30 static void asc_camera_update_ortho(AscCamera *camera) {
universe@37 31 float left = (float) camera->rect.pos.x;
universe@37 32 float right = left + (float) camera->rect.size.width;
universe@37 33 float top = (float) camera->rect.pos.y;
universe@37 34 float bottom = top + (float) camera->rect.size.height;
universe@41 35 asc_mat4f_ortho(camera->projection, left, right, bottom, top, -1, 1);
universe@37 36 }
universe@37 37
universe@37 38 void asc_camera_ortho(AscCamera *camera, asc_recti rect) {
universe@37 39 asc_mat4f_unit(camera->view);
universe@37 40 camera->update = asc_camera_update_ortho;
universe@37 41 camera->rect = rect;
universe@37 42 }
universe@37 43
universe@37 44 void asc_camera_disable(AscCamera *camera) {
universe@37 45 camera->update = NULL;
universe@37 46 }

mercurial