Update rcamera.h

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

View File

@ -192,6 +192,8 @@ RLAPI Matrix GetCameraProjectionMatrix(Camera *camera, float aspect);
// IsKeyPressed() // IsKeyPressed()
// GetFrameTime() // GetFrameTime()
#include <math.h> // Required for: fabsf()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -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);