Updated camera API

This commit is contained in:
Crydsch 2022-07-24 13:56:21 +02:00
parent ec4e138113
commit 5d4eb778c4
2 changed files with 35 additions and 41 deletions

View File

@ -304,7 +304,7 @@ typedef struct Font {
typedef struct Camera3D { typedef struct Camera3D {
Vector3 position; // Camera position Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis) Vector3 up; // Camera up vector (rotation around the view axis)
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
int mode; // Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM int mode; // Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
@ -1153,13 +1153,8 @@ RLAPI float GetGesturePinchAngle(void); // Get gesture pinch ang
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Camera System Functions (Module: rcamera) // Camera System Functions (Module: rcamera)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
RLAPI void SetCameraMode(Camera* camera, int mode); // Set camera mode (multiple camera modes available) RLAPI void SetCameraMode(Camera3D* camera, int mode); // Set camera mode (multiple camera modes available)
RLAPI void UpdateCamera(Camera *camera); // Update camera position for selected mode RLAPI void UpdateCamera(Camera3D *camera); // Update camera position for selected mode
RLAPI void SetCameraPanControl(int keyPan); // Set camera pan key to combine with mouse movement (free camera)
RLAPI void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera)
RLAPI void SetCameraSmoothZoomControl(int keySmoothZoom); // Set camera smooth zoom key to combine with mouse (free camera)
RLAPI void SetCameraMoveControls(int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown); // Set camera move controls (1st person and 3rd person cameras)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Basic Shapes Drawing Functions (Module: shapes) // Basic Shapes Drawing Functions (Module: shapes)

View File

@ -2,8 +2,6 @@
* *
* rcamera - Basic camera system for multiple camera modes * rcamera - Basic camera system for multiple camera modes
* *
* NOTE: Memory footprint of this library is aproximately ??? TODO bytes (global variables)
*
* CONFIGURATION: * CONFIGURATION:
* *
* #define CAMERA_IMPLEMENTATION * #define CAMERA_IMPLEMENTATION
@ -88,8 +86,6 @@
int type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC int type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
} Camera3D; } Camera3D;
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
// Camera system modes // Camera system modes
typedef enum { typedef enum {
CAMERA_CUSTOM = 0, CAMERA_CUSTOM = 0,
@ -109,7 +105,7 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
//...
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Declaration // Module Functions Declaration
@ -120,15 +116,20 @@ extern "C" { // Prevents name mangling of functions
#endif #endif
#if defined(CAMERA_STANDALONE) #if defined(CAMERA_STANDALONE)
void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available) void SetCameraMode(Camera3D* camera, int mode);
void UpdateCamera(Camera *camera); // Update camera position for selected mode Vector3 GetCameraForward(Camera3D* camera);
Vector3 GetCameraUp(Camera3D* camera);
void SetCameraPanControl(int keyPan); // Set camera pan key to combine with mouse movement (free camera) Vector3 GetCameraRight(Camera3D* camera);
void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera) void CameraMoveForward(Camera3D* camera, float distance);
void SetCameraSmoothZoomControl(int szoomKey); // Set camera smooth zoom key to combine with mouse (free camera) void CameraMoveUp(Camera3D* camera, float distance);
void SetCameraMoveControls(int keyFront, int keyBack, void CameraMoveRight(Camera3D* camera, float distance);
int keyRight, int keyLeft, void CameraZoom(Camera3D* camera, float delta);
int keyUp, int keyDown); // Set camera move controls (1st person and 3rd person cameras) void CameraYaw(Camera3D* camera, float angle);
void CameraPitch(Camera3D* camera, float angle);
void CameraRoll(Camera3D* camera, float angle);
void CameraViewBobbing(Camera3D* camera);
Matrix GetCameraViewMatrix(Camera3D* camera);
Matrix GetCameraProjectionMatrix(Camera3D* camera, float aspect);
#endif #endif
#if defined(__cplusplus) #if defined(__cplusplus)
@ -172,21 +173,22 @@ void SetCameraMoveControls(int keyFront, int keyBack,
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO review
// Camera actions // Camera actions
typedef enum { //typedef enum {
CAMERA_MOVE_FORWARD = 0, // CAMERA_MOVE_FORWARD = 0,
CAMERA_MOVE_BACK, // CAMERA_MOVE_BACK,
CAMERA_MOVE_RIGHT, // CAMERA_MOVE_RIGHT,
CAMERA_MOVE_LEFT, // CAMERA_MOVE_LEFT,
CAMERA_MOVE_UP, // CAMERA_MOVE_UP,
CAMERA_MOVE_DOWN, // CAMERA_MOVE_DOWN,
CAMERA_YAW_RIGHT, // CAMERA_YAW_RIGHT,
CAMERA_YAW_LEFT, // CAMERA_YAW_LEFT,
CAMERA_PITCH_UP, // CAMERA_PITCH_UP,
CAMERA_PITCH_DOWN, // CAMERA_PITCH_DOWN,
CAMERA_ROLL_RIGHT, // CAMERA_ROLL_RIGHT,
CAMERA_ROLL_LEFT, // CAMERA_ROLL_LEFT,
} CameraActions; //} CameraActions;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -209,11 +211,6 @@ Vector3 Vector3RotateAxis(Vector3 v, Vector3 axis, float angle) { // TODO there
// Module Functions Definition // Module Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO declare all functions in raylib.h and standalone "header"
void CameraPitch(Camera3D *camera, float angle);
void CameraYaw(Camera3D *camera, float angle);
void CameraRoll(Camera3D *camera, float angle);
// Select camera mode (multiple camera modes available) // Select camera mode (multiple camera modes available)
void SetCameraMode(Camera3D *camera, int mode) void SetCameraMode(Camera3D *camera, int mode)
{ {
@ -471,6 +468,8 @@ Matrix GetCameraProjectionMatrix(Camera3D *camera, float aspect)
#ifndef CAMERA_STANDALONE #ifndef CAMERA_STANDALONE
static int init_frames = 3; // TODO review and remove static int init_frames = 3; // TODO review and remove
// Update camera position for selected mode
void UpdateCamera(Camera3D *camera) void UpdateCamera(Camera3D *camera)
{ {
// Avoid inital mouse "jump" // Avoid inital mouse "jump"