From 6c2037ad2c6303545cc051120c00663def468a2a Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Sun, 24 Sep 2023 00:00:00 -0600 Subject: Made camera system handle more cameras easier --- src/cameras.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/cameras.c (limited to 'src/cameras.c') diff --git a/src/cameras.c b/src/cameras.c new file mode 100644 index 0000000..6a960f5 --- /dev/null +++ b/src/cameras.c @@ -0,0 +1,40 @@ +#include "cameras.h" +#include "game.h" +#include "world.h" + +// First person camera indeed. +void initFirstPersonCamera(Game * game, Camera3D * camera) { + *camera = (Camera3D){ + .fovy = 90.0, + .projection = CAMERA_PERSPECTIVE + }; +} + +void updateFirstPersonCamera(Game * game, Camera3D * camera) { + Entity * player = getEntityFromWorld(game->world, 0); + Vector3 direction = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation); + + camera->position = Vector3Add(player->position, Vector3Scale(direction, CAMERA_DIS)); + camera->target = Vector3Add(camera->position, direction); + camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation); +} + +// Callbacks indeed. +const CameraInitCb cameraInitCallbacks[CAMERA_COUNT] = { + initFirstPersonCamera +}; + +const CameraCb cameraCallbacks[CAMERA_COUNT] = { + updateFirstPersonCamera +}; + +void initCameras(Game * game, Cameras cameras) { + int i; + + for (i = 0; i < CAMERA_COUNT; ++i) + cameraInitCallbacks[i](game, &cameras[i]); +} + +void runCameraUpdate(Game * game, Cameras cameras, CameraId id) { + cameraCallbacks[id](game, &cameras[id]); +} -- cgit v1.2.3