Update rcamera.h

This commit is contained in:
Ray
2025-12-31 20:50:27 +01:00
parent 0133a4e6c6
commit 2377506843

View File

@ -50,14 +50,14 @@
// Function specifiers in case library is build/used as a shared library (Windows) // Function specifiers in case library is build/used as a shared library (Windows)
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
#if defined(_WIN32) #if defined(_WIN32)
#if defined(BUILD_LIBTYPE_SHARED) #if defined(BUILD_LIBTYPE_SHARED)
#if defined(__TINYC__) #if defined(__TINYC__)
#define __declspec(x) __attribute__((x)) #define __declspec(x) __attribute__((x))
#endif #endif
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll) #define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
#elif defined(USE_LIBTYPE_SHARED) #elif defined(USE_LIBTYPE_SHARED)
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll) #define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
#endif #endif
#endif #endif
#ifndef RLAPI #ifndef RLAPI
@ -191,19 +191,21 @@ RLAPI Matrix GetCameraProjectionMatrix(Camera *camera, float aspect);
// IsKeyDown() // IsKeyDown()
// IsKeyPressed() // IsKeyPressed()
// GetFrameTime() // GetFrameTime()
#include <math.h> // Required for: fabsf()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#define CAMERA_MOVE_SPEED 5.4f // Units per second #define CAMERA_MOVE_SPEED 5.4f // Units per second
#define CAMERA_ROTATION_SPEED 0.03f #define CAMERA_ROTATION_SPEED 0.03f
#define CAMERA_PAN_SPEED 0.2f #define CAMERA_PAN_SPEED 0.2f
// Camera mouse movement sensitivity // Camera mouse movement sensitivity
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f #define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f
// Camera orbital speed in CAMERA_ORBITAL mode // Camera orbital speed in CAMERA_ORBITAL mode
#define CAMERA_ORBITAL_SPEED 0.5f // Radians per second #define CAMERA_ORBITAL_SPEED 0.5f // Radians per second
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
@ -253,12 +255,10 @@ void CameraMoveForward(Camera *camera, float distance, bool moveInWorldPlane)
if (moveInWorldPlane) if (moveInWorldPlane)
{ {
// Project vector onto world plane (the plane defined by the up vector) // Project vector onto world plane (the plane defined by the up vector)
if (fabsf(camera->up.z) > 0) if (fabsf(camera->up.z) > 0) forward.z = 0;
forward.z = 0; else if (fabsf(camera->up.x) > 0) forward.x = 0;
else if (fabsf(camera->up.x) > 0) else forward.y = 0;
forward.x = 0;
else
forward.y = 0;
forward = Vector3Normalize(forward); forward = Vector3Normalize(forward);
} }
@ -291,12 +291,9 @@ void CameraMoveRight(Camera *camera, float distance, bool moveInWorldPlane)
if (moveInWorldPlane) if (moveInWorldPlane)
{ {
// Project vector onto world plane (the plane defined by the up vector) // Project vector onto world plane (the plane defined by the up vector)
if (fabsf(camera->up.z) > 0) if (fabsf(camera->up.z) > 0) right.z = 0;
right.z = 0; else if (fabsf(camera->up.x) > 0) right.x = 0;
else if (fabsf(camera->up.x) > 0) else right.y = 0;
right.x = 0;
else
right.y = 0;
right = Vector3Normalize(right); right = Vector3Normalize(right);
} }
@ -356,7 +353,7 @@ void CameraYaw(Camera *camera, float angle, bool rotateAroundTarget)
// - lockView prevents camera overrotation (aka "somersaults") // - lockView prevents camera overrotation (aka "somersaults")
// - rotateAroundTarget defines if rotation is around target or around its position // - rotateAroundTarget defines if rotation is around target or around its position
// - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE) // - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
// NOTE: angle must be provided in radians // NOTE: [angle] must be provided in radians
void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp) void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp)
{ {
// Up direction // Up direction
@ -393,7 +390,7 @@ void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTa
// Move position relative to target // Move position relative to target
camera->position = Vector3Subtract(camera->target, targetPosition); camera->position = Vector3Subtract(camera->target, targetPosition);
} }
else // rotate around camera.position else // Rotate around camera.position
{ {
// Move target relative to position // Move target relative to position
camera->target = Vector3Add(camera->position, targetPosition); camera->target = Vector3Add(camera->position, targetPosition);