// Copyright (c) 2021 Dominic Msters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "../libs.h" #include "../util/math.h" #include "matrix.h" /** The math for the camera is stored here. */ typedef struct { /** View Matrix (Where the camera looks) */ matrix_t view; /** Projection Matrix (How the camera looks) */ matrix_t projection; } camera_t; typedef struct { float x, y, z, lookX, lookY, lookZ; } cameralookat_t; /** * Make a camera look at a position in world space while itself being positioned * within world space. * * @param camera The camera to position. * @param x The X position in world space of the camera. * @param y The Y position in world space of the camera. * @param z The Z position in world space of the camera. * @param targetX The Target X position in world space of the camera. * @param targetY The Target Y position in world space of the camera. * @param targetZ The Target Z position in world space of the camera. */ void cameraLookAt(camera_t *camera, float x, float y, float z, float targetX, float targetY, float targetZ ); /** * Shorthand for look at that uses the look struct. * * @param camera Camera to position. * @param look Look vectors. */ void cameraLookAtStruct(camera_t *camera, cameralookat_t look); /** * Make a camera look in a direction based on a rotation direction. * * @param camera The camera to position. * @param x The X position in world space of the camera. * @param y The Y position in world space of the camera. * @param z The Z position in world space of the camera. * @param pitch The pitch of the camera. * @param yaw The yaw of the camera. * @param roll The roll of the camera. */ void cameraLook(camera_t *camera, float x, float y, float z, float pitch, float yaw, float roll ); /** * Make a camera's projection be a 3D Perspective view. * * @param camera The camera to project. * @param fov The field of view of the camera (in degrees). * @param aspect The aspect ratio of the camera (w / h) * @param camNear The near plane clip. * @param camFar the far plane clip. */ void cameraPerspective(camera_t *camera, float fov, float aspect, float camNear, float camFar ); /** * Defines an orthorgonal camera matrix. * * @param camera Camera to position. * @param left The left side of the viewport. * @param right The right side of the viewport. * @param bottom The bottom side of the viewport. * @param camNear The near plane clip. * @param camFar the far plane clip. */ void cameraOrtho(camera_t *camera, float left, float right, float bottom, float top, float camNear, float camFar ); /** * Update a camera to orbit around a point. * * @param camera Camera to update * @param distance Distance from the point * @param yaw Yaw (Y axis) rotation. * @param pitch Pitch (X/Z axis) rotation. * @param targetX X point to orbit around. * @param targetY Y point to orbit around. * @param targetZ Z point to orbit around. */ void cameraOrbit(camera_t *camera, float distance, float yaw, float pitch, float targetX, float targetY, float targetZ );