Merge branch 'main' into dev

This commit is contained in:
Edward R. Gonzalez 2023-11-17 19:26:21 -05:00
commit 053daaf877
20 changed files with 8704 additions and 8624 deletions

14
.vscode/bookmarks.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"files": [
{
"path": "project/auxillary/vis_ast/dependencies/temp/raylib-master/src/rcamera.h",
"bookmarks": [
{
"line": 140,
"column": 14,
"label": ""
}
]
}
]
}

View File

@ -30,7 +30,13 @@
"list": "cpp", "list": "cpp",
"xhash": "cpp", "xhash": "cpp",
"glfw3.h": "c", "glfw3.h": "c",
"stdbool.h": "c" "stdbool.h": "c",
"objbase.h": "c",
"mmreg.h": "c",
"mmsystem.h": "c",
"propidl.h": "c",
"android_native_app_glue.h": "c",
"raylib.h": "c"
}, },
"C_Cpp.intelliSenseEngineFallback": "disabled", "C_Cpp.intelliSenseEngineFallback": "disabled",
"mesonbuild.configureOnOpen": true, "mesonbuild.configureOnOpen": true,

View File

@ -1,3 +1,4 @@
#pragma once
#if INTELLISENSE_DIRECTIVES #if INTELLISENSE_DIRECTIVES
#include "vendor/compiler.hpp" #include "vendor/compiler.hpp"
#endif #endif

View File

@ -1,4 +1,5 @@
// Platform architecture // Platform architecture
#pragma once
#if defined( _WIN64 ) || defined( __x86_64__ ) || defined( _M_X64 ) || defined( __64BIT__ ) || defined( __powerpc64__ ) || defined( __ppc64__ ) || defined( __aarch64__ ) #if defined( _WIN64 ) || defined( __x86_64__ ) || defined( _M_X64 ) || defined( __64BIT__ ) || defined( __powerpc64__ ) || defined( __ppc64__ ) || defined( __aarch64__ )
# ifndef ARCH_64_BIT # ifndef ARCH_64_BIT

View File

@ -1,4 +1,5 @@
// Platform compiler // Platform compiler
#pragma once
#if defined( _MSC_VER ) #if defined( _MSC_VER )
# define Compiler_MSVC 1 # define Compiler_MSVC 1

View File

@ -1,4 +1,5 @@
// Platform OS detection // Platform OS detection
#pragma once
#if defined( _WIN32 ) || defined( _WIN64 ) #if defined( _WIN32 ) || defined( _WIN64 )
# ifndef System_Windows # ifndef System_Windows

View File

@ -1 +1,3 @@
#pragma once
using HINSTANCE = void*; using HINSTANCE = void*;

View File

@ -25,26 +25,28 @@
* *
**********************************************************************************************/ **********************************************************************************************/
#ifndef CONFIG_H #ifndef RL_CONFIG_H
#define RL_CONFIG_H #define RL_CONFIG_H
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module selection - Some modules could be avoided // Module selection - Some modules could be avoided
// Mandatory modules: rcore, rlgl, utils // Mandatory modules: rcore, RLGL_, utils
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
#define RL_SUPPORT_MODULE_RSHAPES 1 #define RL_SUPPORT_MODULE_RSHAPES 1
#define RL_SUPPORT_MODULE_RTEXTURES 1 #define RL_SUPPORT_MODULE_RTEXTURES 1
#define RL_SUPPORT_MODULE_RTEXT 1 // WARNING: It requires SUPPORT_MODULE_RTEXTURES to load sprite font textures #define RL_SUPPORT_MODULE_RTEXT 1 // WARNING: It requires RL_SUPPORT_MODULE_RTEXTURES to load sprite font textures
#define RL_SUPPORT_MODULE_RMODELS 1 #define RL_SUPPORT_MODULE_RMODELS 1
#define RL_SUPPORT_MODULE_RAUDIO 1 #define RL_SUPPORT_MODULE_RAUDIO 1
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module: rcore - Configuration Flags // Module: rcore - Configuration Flags
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Camera module is included (rcamera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital // RL_Camera module is included (rcamera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
#define RL_SUPPORT_CAMERA_SYSTEM 1 #define RL_SUPPORT_CAMERA_SYSTEM 1
// Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag // Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
#define RL_SUPPORT_GESTURES_SYSTEM 1 #define RL_SUPPORT_GESTURES_SYSTEM 1
// Include pseudo-random numbers generator (rprand.h), based on Xoshiro128** and SplitMix64
#define SUPPORT_RPRAND_GENERATOR 1
// Mouse gestures are directly mapped like touches and processed by gestures system // Mouse gestures are directly mapped like touches and processed by gestures system
#define RL_SUPPORT_MOUSE_GESTURES 1 #define RL_SUPPORT_MOUSE_GESTURES 1
// Reconfigure standard input to receive key inputs, works with SSH connection. // Reconfigure standard input to receive key inputs, works with SSH connection.
@ -60,12 +62,12 @@
#define RL_SUPPORT_SCREEN_CAPTURE 1 #define RL_SUPPORT_SCREEN_CAPTURE 1
// Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback() // Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
#define RL_SUPPORT_GIF_RECORDING 1 #define RL_SUPPORT_GIF_RECORDING 1
// Support CompressData() and DecompressData() functions // Support RL_CompressData() and RL_DecompressData() functions
#define RL_SUPPORT_COMPRESSION_API 1 #define RL_SUPPORT_COMPRESSION_API 1
// Support automatic generated events, loading and recording of those events when required // Support automatic generated events, loading and recording of those events when required
// #define SUPPORT_EVENTS_AUTOMATION 1 #define RL_SUPPORT_AUTOMATION_EVENTS 1
// Support custom frame control, only for advance users // Support custom frame control, only for advance users
// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents() // By default RL_EndDrawing() does this job: draws everything + RL_SwapScreenBuffer() + manage frame timing + RL_PollInputEvents()
// Enabling this flag allows manual control of the frame processes, use at your own risk // Enabling this flag allows manual control of the frame processes, use at your own risk
//#define SUPPORT_CUSTOM_FRAME_CONTROL 1 //#define SUPPORT_CUSTOM_FRAME_CONTROL 1
@ -85,9 +87,10 @@
#define RL_MAX_DECOMPRESSION_SIZE 64 // Max size allocated for decompression in MB #define RL_MAX_DECOMPRESSION_SIZE 64 // Max size allocated for decompression in MB
#define RL_MAX_AUTOMATION_EVENTS 16384 // Maximum number of automation events to record
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module: rlgl - Configuration values // Module: RLGL_ - Configuration values
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Enable OpenGL Debug Context (only available on OpenGL 4.3) // Enable OpenGL Debug Context (only available on OpenGL 4.3)
@ -97,13 +100,35 @@
//#define RLGL_SHOW_GL_DETAILS_INFO 1 //#define RLGL_SHOW_GL_DETAILS_INFO 1
//#define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 4096 // Default internal render batch elements limits //#define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 4096 // Default internal render batch elements limits
#define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
#define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
#define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (RL_SetShaderValueTexture())
#define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal RL_Matrix stack
#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
#define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
#define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
// Default shader vertex attribute names to set location points // Default shader vertex attribute names to set location points
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience // NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
@ -113,33 +138,37 @@
// Some lines-based shapes could still use lines // Some lines-based shapes could still use lines
#define RL_SUPPORT_QUADS_DRAW_MODE 1 #define RL_SUPPORT_QUADS_DRAW_MODE 1
// rshapes: Configuration values
//------------------------------------------------------------------------------------
#define SPLINE_SEGMENT_DIVISIONS 24 // Spline segments subdivisions
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module: rtextures - Configuration Flags // Module: rtextures - Configuration Flags
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Selecte desired fileformats to be supported for image data loading // Selecte desired fileformats to be supported for image data loading
#define RL_SUPPORT_FILEFORMAT_PNG 1 #define RL_SUPPORT_FILEFORMAT_PNG 1
// #define SUPPORT_FILEFORMAT_BMP 1 //#define RL_SUPPORT_FILEFORMAT_BMP 1
// #define SUPPORT_FILEFORMAT_TGA 1 //#define RL_SUPPORT_FILEFORMAT_TGA 1
// #define SUPPORT_FILEFORMAT_JPG 1 //#define RL_SUPPORT_FILEFORMAT_JPG 1
#define RL_SUPPORT_FILEFORMAT_GIF 1 #define RL_SUPPORT_FILEFORMAT_GIF 1
#define RL_SUPPORT_FILEFORMAT_QOI 1 #define RL_SUPPORT_FILEFORMAT_QOI 1
// #define SUPPORT_FILEFORMAT_PSD 1 //#define RL_SUPPORT_FILEFORMAT_PSD 1
#define RL_SUPPORT_FILEFORMAT_DDS 1 #define RL_SUPPORT_FILEFORMAT_DDS 1
// #define SUPPORT_FILEFORMAT_HDR 1 //#define RL_SUPPORT_FILEFORMAT_HDR 1
// #define SUPPORT_FILEFORMAT_PIC 1 //#define RL_SUPPORT_FILEFORMAT_PIC 1
// #define SUPPORT_FILEFORMAT_KTX 1 //#define RL_SUPPORT_FILEFORMAT_KTX 1
// #define SUPPORT_FILEFORMAT_ASTC 1 //#define RL_SUPPORT_FILEFORMAT_ASTC 1
// #define SUPPORT_FILEFORMAT_PKM 1 //#define RL_SUPPORT_FILEFORMAT_PKM 1
// #define SUPPORT_FILEFORMAT_PVR 1 //#define RL_SUPPORT_FILEFORMAT_PVR 1
// #define SUPPORT_FILEFORMAT_SVG 1 //#define RL_SUPPORT_FILEFORMAT_SVG 1
// Support image export functionality (.png, .bmp, .tga, .jpg, .qoi) // Support image export functionality (.png, .bmp, .tga, .jpg, .qoi)
#define RL_SUPPORT_IMAGE_EXPORT 1 #define RL_SUPPORT_IMAGE_EXPORT 1
// Support procedural image generation functionality (gradient, spot, perlin-noise, cellular) // Support procedural image generation functionality (gradient, spot, perlin-noise, cellular)
#define RL_SUPPORT_IMAGE_GENERATION 1 #define RL_SUPPORT_IMAGE_GENERATION 1
// Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop... // Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop...
// If not defined, still some functions are supported: ImageFormat(), ImageCrop(), ImageToPOT() // If not defined, still some functions are supported: RL_ImageFormat(), RL_ImageCrop(), RL_ImageToPOT()
#define RL_SUPPORT_IMAGE_MANIPULATION 1 #define RL_SUPPORT_IMAGE_MANIPULATION 1
@ -154,18 +183,18 @@
#define RL_SUPPORT_FILEFORMAT_TTF 1 #define RL_SUPPORT_FILEFORMAT_TTF 1
// Support text management functions // Support text management functions
// If not defined, still some functions are supported: TextLength(), TextFormat() // If not defined, still some functions are supported: RL_TextLength(), RL_TextFormat()
#define RL_SUPPORT_TEXT_MANIPULATION 1 #define RL_SUPPORT_TEXT_MANIPULATION 1
// On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle // On font atlas image generation [RL_GenImageFontAtlas()], add a 3x3 pixels white rectangle
// at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow // at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow
// drawing text and shapes with a single draw call [SetShapesTexture()]. // drawing text and shapes with a single draw call [RL_SetShapesTexture()].
#define RL_SUPPORT_FONT_ATLAS_WHITE_REC 1 #define RL_SUPPORT_FONT_ATLAS_WHITE_REC 1
// rtext: Configuration values // rtext: Configuration values
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
#define RL_MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions: #define RL_MAX_TEXT_BUFFER_LENGTH 1024 // RL_Size of internal static buffers used on some functions:
// TextFormat(), TextSubtext(), TextToUpper(), TextToLower(), TextToPascal(), TextSplit() // RL_TextFormat(), RL_TextSubtext(), RL_TextToUpper(), RL_TextToLower(), RL_TextToPascal(), TextSplit()
#define RL_MAX_TEXTSPLIT_COUNT 128 // Maximum number of substrings to split: TextSplit() #define RL_MAX_TEXTSPLIT_COUNT 128 // Maximum number of substrings to split: TextSplit()
@ -196,7 +225,7 @@
#define RL_SUPPORT_FILEFORMAT_OGG 1 #define RL_SUPPORT_FILEFORMAT_OGG 1
#define RL_SUPPORT_FILEFORMAT_MP3 1 #define RL_SUPPORT_FILEFORMAT_MP3 1
#define RL_SUPPORT_FILEFORMAT_QOA 1 #define RL_SUPPORT_FILEFORMAT_QOA 1
// #define SUPPORT_FILEFORMAT_FLAC 1 //#define RL_SUPPORT_FILEFORMAT_FLAC 1
#define RL_SUPPORT_FILEFORMAT_XM 1 #define RL_SUPPORT_FILEFORMAT_XM 1
#define RL_SUPPORT_FILEFORMAT_MOD 1 #define RL_SUPPORT_FILEFORMAT_MOD 1
@ -213,14 +242,21 @@
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Standard file io library (stdio.h) included // Standard file io library (stdio.h) included
#define RL_SUPPORT_STANDARD_FILEIO 1 #define RL_SUPPORT_STANDARD_FILEIO 1
// Show TRACELOG() output messages // Show RL_TRACELOG() output messages
// NOTE: By default LOG_DEBUG traces not shown // NOTE: By default RL_LOG_DEBUG traces not shown
#define RL_SUPPORT_TRACELOG 1 #define RL_SUPPORT_TRACELOG 1
// #define SUPPORT_TRACELOG_DEBUG 1 //#define RL_SUPPORT_TRACELOG_DEBUG 1
// utils: Configuration values // utils: Configuration values
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
#define RL_MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message #define RL_MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message
#endif // RL_CONFIG_H
#if defined(__cplusplus)
#define RL_NS_BEGIN namespace raylib {
#define RL_NS_END }
#else
#define RL_NS_BEGIN
#define RL_NS_END
#endif #endif
// CONFIG_H

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,7 @@
**********************************************************************************************/ **********************************************************************************************/
#ifndef RCAMERA_H #ifndef RCAMERA_H
#define RL_RCAMERA_H #define RCAMERA_H
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
@ -50,15 +50,18 @@
// 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(RL_BUILD_LIBTYPE_SHARED)
#if defined(__TINYC__) #if defined(__TINYC__)
#define RL___declspec( x ) __attribute__( ( x ) ) #define __declspec(x) __attribute__((x))
#endif #endif
#elif defined( USE_LIBTYPE_SHARED ) #define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
#elif defined(RL_USE_LIBTYPE_SHARED)
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
#endif #endif
#endif #endif
#ifndef RLAPI #ifndef RLAPI
#define RLAPI // Functions defined as 'extern' by default (implicit specifiers)
#endif #endif
#if defined(RCAMERA_STANDALONE) #if defined(RCAMERA_STANDALONE)
@ -74,64 +77,52 @@
// NOTE: Below types are required for standalone usage // NOTE: Below types are required for standalone usage
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(RCAMERA_STANDALONE) #if defined(RCAMERA_STANDALONE)
// Vector2, 2 components // RL_Vector2, 2 components
typedef struct Vector2 typedef struct RL_Vector2 {
{ float x; // Vector x component
f32 x; // Vector x component float y; // Vector y component
f32 y; // Vector y component } RL_Vector2;
} Vector2; // RL_Vector3, 3 components
typedef struct RL_Vector3 {
float x; // Vector x component
float y; // Vector y component
float z; // Vector z component
} RL_Vector3;
// Vector3, 3 components // RL_Matrix, 4x4 components, column major, OpenGL style, right-handed
typedef struct Vector3 typedef struct RL_Matrix {
{ float m0, m4, m8, m12; // RL_Matrix first row (4 components)
f32 x; // Vector x component float m1, m5, m9, m13; // RL_Matrix second row (4 components)
f32 y; // Vector y component float m2, m6, m10, m14; // RL_Matrix third row (4 components)
f32 z; // Vector z component float m3, m7, m11, m15; // RL_Matrix fourth row (4 components)
} RL_Matrix;
} Vector3; // RL_Camera type, defines a camera position/orientation in 3d space
typedef struct RL_Camera3D {
RL_Vector3 position; // RL_Camera position
RL_Vector3 target; // RL_Camera target it looks-at
RL_Vector3 up; // RL_Camera up vector (rotation over its axis)
float fovy; // RL_Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
int projection; // RL_Camera projection type: RL_CAMERA_PERSPECTIVE or RL_CAMERA_ORTHOGRAPHIC
} RL_Camera3D;
// Matrix, 4x4 components, column major, OpenGL style, right-handed typedef RL_Camera3D RL_Camera; // RL_Camera type fallback, defaults to RL_Camera3D
typedef struct Matrix
{
f32 m0, m4, m8, m12; // Matrix first row (4 components)
f32 m1, m5, m9, m13; // Matrix second row (4 components)
f32 m2, m6, m10, m14; // Matrix third row (4 components)
f32 m3, m7, m11, m15; // Matrix fourth row (4 components)
} Matrix; // RL_Camera projection
typedef enum {
RL_CAMERA_PERSPECTIVE = 0, // Perspective projection
RL_CAMERA_ORTHOGRAPHIC // Orthographic projection
} RL_CameraProjection;
// Camera type, defines a camera position/orientation in 3d space // RL_Camera system modes
typedef struct Camera3D typedef enum {
{ RL_CAMERA_CUSTOM = 0, // RL_Camera custom, controlled by user (RL_UpdateCamera() does nothing)
Vector3 position; // Camera position RL_CAMERA_FREE, // RL_Camera free mode
Vector3 target; // Camera target it looks-at RL_CAMERA_ORBITAL, // RL_Camera orbital, around target, zoom supported
Vector3 up; // Camera up vector (rotation over its axis) RL_CAMERA_FIRST_PERSON, // RL_Camera first person
f32 fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic RL_CAMERA_THIRD_PERSON // RL_Camera third person
s32 projection; // Camera projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC } RL_CameraMode;
} Camera3D;
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
// Camera projection
typedef enum
{
Camera_Perspective = 0, // Perspective projection
Camera_Orthographic // orthographic projection
} CameraProjection;
// Camera system modes
typedef enum
{
Camera_Custom = 0, // Camera custom, controlled by user (UpdateCamera() does nothing)
Camera_Free, // Camera free mode
Camera_Orbital, // Camera orbital, around target, zoom supported
Camera_First_Person, // Camera first person
Camera_Third_Person // camera third person
} CameraMode;
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -144,38 +135,32 @@ typedef enum
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(__cplusplus) #if defined(__cplusplus)
namespace raylib extern "C" { // Prevents name mangling of functions
{
extern "C"
{
// Prevents name mangling of functions
#endif #endif
RLAPI Vector3 get_camera_forward( Camera* camera ); RLAPI RL_Vector3 GetCameraForward(RL_Camera *camera);
RLAPI Vector3 get_camera_up( Camera* camera ); RLAPI RL_Vector3 GetCameraUp(RL_Camera *camera);
RLAPI Vector3 get_camera_right( Camera* camera ); RLAPI RL_Vector3 GetCameraRight(RL_Camera *camera);
// Camera movement // RL_Camera movement
RLAPI void camera_move_forward( Camera* camera, f32 distance, bool moveInWorldPlane ); RLAPI void CameraMoveForward(RL_Camera *camera, float distance, bool moveInWorldPlane);
RLAPI void camera_move_up( Camera* camera, f32 distance ); RLAPI void CameraMoveUp(RL_Camera *camera, float distance);
RLAPI void camera_move_right( Camera* camera, f32 distance, bool moveInWorldPlane ); RLAPI void CameraMoveRight(RL_Camera *camera, float distance, bool moveInWorldPlane);
RLAPI void camera_move_to_target( Camera* camera, f32 delta ); RLAPI void CameraMoveToTarget(RL_Camera *camera, float delta);
// Camera rotation // RL_Camera rotation
RLAPI void camera_yaw( Camera* camera, f32 angle, bool rotateAroundTarget ); RLAPI void CameraYaw(RL_Camera *camera, float angle, bool rotateAroundTarget);
RLAPI void camera_pitch( Camera* camera, f32 angle, bool lockView, bool rotateAroundTarget, bool rotateUp ); RLAPI void CameraPitch(RL_Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
RLAPI void camera_roll( Camera* camera, f32 angle ); RLAPI void CameraRoll(RL_Camera *camera, float angle);
RLAPI Matrix get_camera_view_matrix( Camera* camera ); RLAPI RL_Matrix GetCameraViewMatrix(RL_Camera *camera);
RLAPI Matrix get_camera_projection_matrix( Camera* camera, f32 aspect ); RLAPI RL_Matrix GetCameraProjectionMatrix(RL_Camera* camera, float aspect);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
}
#endif #endif
#endif #endif // RCAMERA_H
// RCAMERA_H
/*********************************************************************************** /***********************************************************************************
@ -186,28 +171,27 @@ namespace raylib
#if defined(RCAMERA_IMPLEMENTATION) #if defined(RCAMERA_IMPLEMENTATION)
#include "raymath.h" #include "raymath.h" // Required for vector maths:
// Required for vector maths: // RL_Vector3Add()
// Vector3Add() // RL_Vector3Subtract()
// Vector3Subtract() // RL_Vector3Scale()
// Vector3Scale() // RL_Vector3Normalize()
// Vector3Normalize() // RL_Vector3Distance()
// Vector3Distance() // RL_Vector3CrossProduct()
// Vector3CrossProduct() // RL_Vector3RotateByAxisAngle()
// Vector3RotateByAxisAngle() // RL_Vector3Angle()
// Vector3Angle() // RL_Vector3Negate()
// Vector3Negate() // RL_MatrixLookAt()
// MatrixLookAt() // RL_MatrixPerspective()
// MatrixPerspective() // RL_MatrixOrtho()
// MatrixOrtho() // RL_MatrixIdentity()
// MatrixIdentity()
// raylib required functionality: // raylib required functionality:
// GetMouseDelta() // RL_GetMouseDelta()
// GetMouseWheelMove() // RL_GetMouseWheelMove()
// IsKeyDown() // RL_IsKeyDown()
// IsKeyPressed() // RL_IsKeyPressed()
// GetFrameTime() // RL_GetFrameTime()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
@ -216,7 +200,7 @@ namespace raylib
#define RL_CAMERA_ROTATION_SPEED 0.03f #define RL_CAMERA_ROTATION_SPEED 0.03f
#define RL_CAMERA_PAN_SPEED 0.2f #define RL_CAMERA_PAN_SPEED 0.2f
// Camera mouse movement sensitivity // RL_Camera mouse movement sensitivity
#define RL_CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f // TODO: it should be independant of framerate #define RL_CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f // TODO: it should be independant of framerate
#define RL_CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f #define RL_CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
@ -249,340 +233,320 @@ namespace raylib
// Module Functions Definition // Module Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Returns the cameras forward vector (normalized) // Returns the cameras forward vector (normalized)
Vector3 get_camera_forward( Camera* camera ) RL_Vector3 GetCameraForward(RL_Camera *camera)
{ {
return Vector3Normalize( Vector3Subtract( camera->target, camera->position ) ); return RL_Vector3Normalize(RL_Vector3Subtract(camera->target, camera->position));
} }
// Returns the cameras up vector (normalized) // Returns the cameras up vector (normalized)
// Note: The up vector might not be perpendicular to the forward vector // Note: The up vector might not be perpendicular to the forward vector
Vector3 get_camera_up( Camera* camera ) RL_Vector3 GetCameraUp(RL_Camera *camera)
{ {
return Vector3Normalize( camera->up ); return RL_Vector3Normalize(camera->up);
} }
// Returns the cameras right vector (normalized) // Returns the cameras right vector (normalized)
Vector3 get_camera_right( Camera* camera ) RL_Vector3 GetCameraRight(RL_Camera *camera)
{ {
Vector3 forward = GetCameraForward( camera ); RL_Vector3 forward = GetCameraForward(camera);
Vector3 up = GetCameraUp( camera ); RL_Vector3 up = GetCameraUp(camera);
return Vector3CrossProduct( forward, up ); return RL_Vector3CrossProduct(forward, up);
} }
// Moves the camera in its forward direction // Moves the camera in its forward direction
void camera_move_forward( Camera* camera, f32 distance, bool moveInWorldPlane ) void CameraMoveForward(RL_Camera *camera, float distance, bool moveInWorldPlane)
{ {
Vector3 forward = GetCameraForward( camera ); RL_Vector3 forward = GetCameraForward(camera);
if (moveInWorldPlane) if (moveInWorldPlane)
{ {
// Project vector onto world plane // Project vector onto world plane
forward.y = 0; forward.y = 0;
forward = Vector3Normalize( forward ); forward = RL_Vector3Normalize(forward);
} }
// Scale by distance // Scale by distance
forward = Vector3Scale( forward, distance ); forward = RL_Vector3Scale(forward, distance);
// Move position and target // Move position and target
camera->position = Vector3Add( camera->position, forward ); camera->position = RL_Vector3Add(camera->position, forward);
camera->target = Vector3Add( camera->target, forward ); camera->target = RL_Vector3Add(camera->target, forward);
} }
// Moves the camera in its up direction // Moves the camera in its up direction
void camera_move_up( Camera* camera, f32 distance ) void CameraMoveUp(RL_Camera *camera, float distance)
{ {
Vector3 up = GetCameraUp( camera ); RL_Vector3 up = GetCameraUp(camera);
// Scale by distance // Scale by distance
up = Vector3Scale( up, distance ); up = RL_Vector3Scale(up, distance);
// Move position and target // Move position and target
camera->position = Vector3Add( camera->position, up ); camera->position = RL_Vector3Add(camera->position, up);
camera->target = Vector3Add( camera->target, up ); camera->target = RL_Vector3Add(camera->target, up);
} }
// Moves the camera target in its current right direction // Moves the camera target in its current right direction
void camera_move_right( Camera* camera, f32 distance, bool moveInWorldPlane ) void CameraMoveRight(RL_Camera *camera, float distance, bool moveInWorldPlane)
{ {
Vector3 right = GetCameraRight( camera ); RL_Vector3 right = GetCameraRight(camera);
if (moveInWorldPlane) if (moveInWorldPlane)
{ {
// Project vector onto world plane // Project vector onto world plane
right.y = 0; right.y = 0;
right = Vector3Normalize( right ); right = RL_Vector3Normalize(right);
} }
// Scale by distance // Scale by distance
right = Vector3Scale( right, distance ); right = RL_Vector3Scale(right, distance);
// Move position and target // Move position and target
camera->position = Vector3Add( camera->position, right ); camera->position = RL_Vector3Add(camera->position, right);
camera->target = Vector3Add( camera->target, right ); camera->target = RL_Vector3Add(camera->target, right);
} }
// Moves the camera position closer/farther to/from the camera target // Moves the camera position closer/farther to/from the camera target
void camera_move_to_target( Camera* camera, f32 delta ) void CameraMoveToTarget(RL_Camera *camera, float delta)
{ {
float distance = Vector3Distance( camera->position, camera->target ); float distance = RL_Vector3Distance(camera->position, camera->target);
// Apply delta // Apply delta
distance += delta; distance += delta;
// Distance must be greater than 0 // Distance must be greater than 0
if ( distance <= 0 ) if (distance <= 0) distance = 0.001f;
distance = 0.001f;
// Set new distance by moving the position along the forward vector // Set new distance by moving the position along the forward vector
Vector3 forward = GetCameraForward( camera ); RL_Vector3 forward = GetCameraForward(camera);
camera->position = Vector3Add( camera->target, Vector3Scale( forward, -distance ) ); camera->position = RL_Vector3Add(camera->target, RL_Vector3Scale(forward, -distance));
} }
// Rotates the camera around its up vector // Rotates the camera around its up vector
// Yaw is "looking left and right" // Yaw is "looking left and right"
// If rotateAroundTarget is false, the camera rotates around its position // If rotateAroundTarget is false, the camera rotates around its position
// Note: angle must be provided in radians // Note: angle must be provided in radians
void camera_yaw( Camera* camera, f32 angle, bool rotateAroundTarget ) void CameraYaw(RL_Camera *camera, float angle, bool rotateAroundTarget)
{ {
Vector3 up = GetCameraUp( camera ); // Rotation axis
RL_Vector3 up = GetCameraUp(camera);
// View vector // View vector
Vector3 targetPosition = Vector3Subtract( camera->target, camera->position ); RL_Vector3 targetPosition = RL_Vector3Subtract(camera->target, camera->position);
// Rotate view vector around up axis // Rotate view vector around up axis
targetPosition = Vector3RotateByAxisAngle( targetPosition, up, angle ); targetPosition = RL_Vector3RotateByAxisAngle(targetPosition, up, angle);
if (rotateAroundTarget) if (rotateAroundTarget)
{ {
// Move position relative to target // Move position relative to target
camera->position = Vector3Subtract( camera->target, targetPosition ); camera->position = RL_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 = RL_Vector3Add(camera->position, targetPosition);
} }
} }
// Rotates the camera around its right vector, pitch is "looking up and down" // Rotates the camera around its right vector, pitch is "looking up and down"
// - 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 RL_CAMERA_FREE)
// NOTE: angle must be provided in radians // NOTE: angle must be provided in radians
void camera_pitch( Camera* camera, f32 angle, bool lockView, bool rotateAroundTarget, bool rotateUp ) void CameraPitch(RL_Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp)
{ {
Vector3 up = GetCameraUp( camera ); // Up direction
RL_Vector3 up = GetCameraUp(camera);
// View vector // View vector
Vector3 targetPosition = Vector3Subtract( camera->target, camera->position ); RL_Vector3 targetPosition = RL_Vector3Subtract(camera->target, camera->position);
if (lockView) if (lockView)
{ {
// In these camera modes we clamp the Pitch angle // In these camera modes we clamp the Pitch angle
// to allow only viewing straight up or down. // to allow only viewing straight up or down.
// Clamp view up // RL_Clamp view up
float maxAngleUp = Vector3Angle( up, targetPosition ); float maxAngleUp = RL_Vector3Angle(up, targetPosition);
maxAngleUp -= 0.001f; // avoid numerical errors maxAngleUp -= 0.001f; // avoid numerical errors
if ( angle > maxAngleUp ) if (angle > maxAngleUp) angle = maxAngleUp;
angle = maxAngleUp;
// Clamp view down // RL_Clamp view down
float maxAngleDown = Vector3Angle( Vector3Negate( up ), targetPosition ); float maxAngleDown = RL_Vector3Angle(RL_Vector3Negate(up), targetPosition);
maxAngleDown *= -1.0f; // downwards angle is negative maxAngleDown *= -1.0f; // downwards angle is negative
maxAngleDown += 0.001f; // avoid numerical errors maxAngleDown += 0.001f; // avoid numerical errors
if ( angle < maxAngleDown ) if (angle < maxAngleDown) angle = maxAngleDown;
angle = maxAngleDown;
} }
// Rotation axis // Rotation axis
Vector3 right = GetCameraRight( camera ); RL_Vector3 right = GetCameraRight(camera);
// Rotate view vector around right axis // Rotate view vector around right axis
targetPosition = Vector3RotateByAxisAngle( targetPosition, right, angle ); targetPosition = RL_Vector3RotateByAxisAngle(targetPosition, right, angle);
if (rotateAroundTarget) if (rotateAroundTarget)
{ {
// Move position relative to target // Move position relative to target
camera->position = Vector3Subtract( camera->target, targetPosition ); camera->position = RL_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 = RL_Vector3Add(camera->position, targetPosition);
} }
if (rotateUp) if (rotateUp)
{ {
// Rotate up direction around right axis // Rotate up direction around right axis
camera->up = Vector3RotateByAxisAngle( camera->up, right, angle ); camera->up = RL_Vector3RotateByAxisAngle(camera->up, right, angle);
} }
} }
// Rotates the camera around its forward vector // Rotates the camera around its forward vector
// Roll is "turning your head sideways to the left or right" // Roll is "turning your head sideways to the left or right"
// Note: angle must be provided in radians // Note: angle must be provided in radians
void camera_roll( Camera* camera, f32 angle ) void CameraRoll(RL_Camera *camera, float angle)
{ {
Vector3 forward = GetCameraForward( camera ); // Rotation axis
RL_Vector3 forward = GetCameraForward(camera);
// Rotate up direction around forward axis // Rotate up direction around forward axis
camera->up = Vector3RotateByAxisAngle( camera->up, forward, angle ); camera->up = RL_Vector3RotateByAxisAngle(camera->up, forward, angle);
} }
// Returns the camera view matrix // Returns the camera view matrix
Matrix get_camera_view_matrix( Camera* camera ) RL_Matrix GetCameraViewMatrix(RL_Camera *camera)
{ {
return MatrixLookAt( camera->position, camera->target, camera->up ); return RL_MatrixLookAt(camera->position, camera->target, camera->up);
} }
// Returns the camera projection matrix // Returns the camera projection matrix
Matrix get_camera_projection_matrix( Camera* camera, f32 aspect ) RL_Matrix GetCameraProjectionMatrix(RL_Camera *camera, float aspect)
{ {
if ( camera->projection == CAMERA_PERSPECTIVE ) if (camera->projection == RL_CAMERA_PERSPECTIVE)
{ {
return MatrixPerspective( camera->fovy * DEG2RAD, aspect, CAMERA_CULL_DISTANCE_NEAR, CAMERA_CULL_DISTANCE_FAR ); return RL_MatrixPerspective(camera->fovy*RL_DEG2RAD, aspect, RL_CAMERA_CULL_DISTANCE_NEAR, RL_CAMERA_CULL_DISTANCE_FAR);
} }
else if ( camera->projection == CAMERA_ORTHOGRAPHIC ) else if (camera->projection == RL_CAMERA_ORTHOGRAPHIC)
{ {
double top = camera->fovy/2.0; double top = camera->fovy/2.0;
double right = top*aspect; double right = top*aspect;
return MatrixOrtho( -right, right, -top, top, CAMERA_CULL_DISTANCE_NEAR, CAMERA_CULL_DISTANCE_FAR ); return RL_MatrixOrtho(-right, right, -top, top, RL_CAMERA_CULL_DISTANCE_NEAR, RL_CAMERA_CULL_DISTANCE_FAR);
} }
return MatrixIdentity(); return RL_MatrixIdentity();
} }
#if !defined(RCAMERA_STANDALONE) #if !defined(RCAMERA_STANDALONE)
// Update camera position for selected mode // Update camera position for selected mode
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM // RL_Camera mode: RL_CAMERA_FREE, RL_CAMERA_FIRST_PERSON, RL_CAMERA_THIRD_PERSON, RL_CAMERA_ORBITAL or CUSTOM
void update_camera( Camera* camera, s32 mode ) void RL_UpdateCamera(RL_Camera *camera, int mode)
{ {
Vector2 mousePositionDelta = GetMouseDelta(); RL_Vector2 mousePositionDelta = RL_GetMouseDelta();
bool moveInWorldPlane = ( ( mode == CAMERA_FIRST_PERSON ) || ( mode == CAMERA_THIRD_PERSON ) ); bool moveInWorldPlane = ((mode == RL_CAMERA_FIRST_PERSON) || (mode == RL_CAMERA_THIRD_PERSON));
bool rotateAroundTarget = ( ( mode == CAMERA_THIRD_PERSON ) || ( mode == CAMERA_ORBITAL ) ); bool rotateAroundTarget = ((mode == RL_CAMERA_THIRD_PERSON) || (mode == RL_CAMERA_ORBITAL));
bool lockView = ( ( mode == CAMERA_FIRST_PERSON ) || ( mode == CAMERA_THIRD_PERSON ) || ( mode == CAMERA_ORBITAL ) ); bool lockView = ((mode == RL_CAMERA_FIRST_PERSON) || (mode == RL_CAMERA_THIRD_PERSON) || (mode == RL_CAMERA_ORBITAL));
bool rotateUp = false; bool rotateUp = false;
if ( mode == CAMERA_ORBITAL ) if (mode == RL_CAMERA_ORBITAL)
{ {
// Orbital can just orbit // Orbital can just orbit
Matrix rotation = MatrixRotate( GetCameraUp( camera ), CAMERA_ORBITAL_SPEED * GetFrameTime() ); RL_Matrix rotation = RL_MatrixRotate(GetCameraUp(camera), RL_CAMERA_ORBITAL_SPEED*RL_GetFrameTime());
Vector3 view = Vector3Subtract( camera->position, camera->target ); RL_Vector3 view = RL_Vector3Subtract(camera->position, camera->target);
view = Vector3Transform( view, rotation ); view = RL_Vector3Transform(view, rotation);
camera->position = Vector3Add( camera->target, view ); camera->position = RL_Vector3Add(camera->target, view);
} }
else else
{ {
// Camera rotation // RL_Camera rotation
if ( IsKeyDown( KEY_DOWN ) ) if (RL_IsKeyDown(RL_KEY_DOWN)) CameraPitch(camera, -RL_CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
CameraPitch( camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp ); if (RL_IsKeyDown(RL_KEY_UP)) CameraPitch(camera, RL_CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
if ( IsKeyDown( KEY_UP ) ) if (RL_IsKeyDown(RL_KEY_RIGHT)) CameraYaw(camera, -RL_CAMERA_ROTATION_SPEED, rotateAroundTarget);
CameraPitch( camera, CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp ); if (RL_IsKeyDown(RL_KEY_LEFT)) CameraYaw(camera, RL_CAMERA_ROTATION_SPEED, rotateAroundTarget);
if ( IsKeyDown( KEY_RIGHT ) ) if (RL_IsKeyDown(RL_KEY_Q)) CameraRoll(camera, -RL_CAMERA_ROTATION_SPEED);
CameraYaw( camera, -CAMERA_ROTATION_SPEED, rotateAroundTarget ); if (RL_IsKeyDown(RL_KEY_E)) CameraRoll(camera, RL_CAMERA_ROTATION_SPEED);
if ( IsKeyDown( KEY_LEFT ) )
CameraYaw( camera, CAMERA_ROTATION_SPEED, rotateAroundTarget );
if ( IsKeyDown( KEY_Q ) )
CameraRoll( camera, -CAMERA_ROTATION_SPEED );
if ( IsKeyDown( KEY_E ) )
CameraRoll( camera, CAMERA_ROTATION_SPEED );
// Camera movement // RL_Camera movement
if ( ! IsGamepadAvailable( 0 ) ) if (!RL_IsGamepadAvailable(0))
{ {
// Camera pan (for CAMERA_FREE) // RL_Camera pan (for RL_CAMERA_FREE)
if ( ( mode == CAMERA_FREE ) && ( IsMouseButtonDown( MOUSE_BUTTON_MIDDLE ) ) ) if ((mode == RL_CAMERA_FREE) && (RL_IsMouseButtonDown(RL_MOUSE_BUTTON_MIDDLE)))
{ {
const Vector2 mouseDelta = GetMouseDelta(); const RL_Vector2 mouseDelta = RL_GetMouseDelta();
if ( mouseDelta.x > 0.0f ) if (mouseDelta.x > 0.0f) CameraMoveRight(camera, RL_CAMERA_PAN_SPEED, moveInWorldPlane);
CameraMoveRight( camera, CAMERA_PAN_SPEED, moveInWorldPlane ); if (mouseDelta.x < 0.0f) CameraMoveRight(camera, -RL_CAMERA_PAN_SPEED, moveInWorldPlane);
if ( mouseDelta.x < 0.0f ) if (mouseDelta.y > 0.0f) CameraMoveUp(camera, -RL_CAMERA_PAN_SPEED);
CameraMoveRight( camera, -CAMERA_PAN_SPEED, moveInWorldPlane ); if (mouseDelta.y < 0.0f) CameraMoveUp(camera, RL_CAMERA_PAN_SPEED);
if ( mouseDelta.y > 0.0f )
CameraMoveUp( camera, -CAMERA_PAN_SPEED );
if ( mouseDelta.y < 0.0f )
CameraMoveUp( camera, CAMERA_PAN_SPEED );
} }
else else
{ {
// Mouse support // Mouse support
CameraYaw( camera, -mousePositionDelta.x * CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget ); CameraYaw(camera, -mousePositionDelta.x*RL_CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
CameraPitch( camera, -mousePositionDelta.y * CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp ); CameraPitch(camera, -mousePositionDelta.y*RL_CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
} }
// Keyboard support // Keyboard support
if ( IsKeyDown( KEY_W ) ) if (RL_IsKeyDown(RL_KEY_W)) CameraMoveForward(camera, RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
CameraMoveForward( camera, CAMERA_MOVE_SPEED, moveInWorldPlane ); if (RL_IsKeyDown(RL_KEY_A)) CameraMoveRight(camera, -RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
if ( IsKeyDown( KEY_A ) ) if (RL_IsKeyDown(RL_KEY_S)) CameraMoveForward(camera, -RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
CameraMoveRight( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane ); if (RL_IsKeyDown(RL_KEY_D)) CameraMoveRight(camera, RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
if ( IsKeyDown( KEY_S ) )
CameraMoveForward( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( IsKeyDown( KEY_D ) )
CameraMoveRight( camera, CAMERA_MOVE_SPEED, moveInWorldPlane );
} }
else else
{ {
// Gamepad controller support // Gamepad controller support
CameraYaw( camera, -( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_RIGHT_X ) * 2 ) * CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget ); CameraYaw(camera, -(RL_GetGamepadAxisMovement(0, RL_GAMEPAD_AXIS_RIGHT_X) * 2)*RL_CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
CameraPitch( CameraPitch(camera, -(RL_GetGamepadAxisMovement(0, RL_GAMEPAD_AXIS_RIGHT_Y) * 2)*RL_CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
camera,
-( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_RIGHT_Y ) * 2 ) * CAMERA_MOUSE_MOVE_SENSITIVITY,
lockView,
rotateAroundTarget,
rotateUp
);
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_Y ) <= -0.25f ) if (RL_GetGamepadAxisMovement(0, RL_GAMEPAD_AXIS_LEFT_Y) <= -0.25f) CameraMoveForward(camera, RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
CameraMoveForward( camera, CAMERA_MOVE_SPEED, moveInWorldPlane ); if (RL_GetGamepadAxisMovement(0, RL_GAMEPAD_AXIS_LEFT_X) <= -0.25f) CameraMoveRight(camera, -RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_X ) <= -0.25f ) if (RL_GetGamepadAxisMovement(0, RL_GAMEPAD_AXIS_LEFT_Y) >= 0.25f) CameraMoveForward(camera, -RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
CameraMoveRight( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane ); if (RL_GetGamepadAxisMovement(0, RL_GAMEPAD_AXIS_LEFT_X) >= 0.25f) CameraMoveRight(camera, RL_CAMERA_MOVE_SPEED, moveInWorldPlane);
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_Y ) >= 0.25f )
CameraMoveForward( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_X ) >= 0.25f )
CameraMoveRight( camera, CAMERA_MOVE_SPEED, moveInWorldPlane );
} }
if ( mode == CAMERA_FREE ) if (mode == RL_CAMERA_FREE)
{ {
if ( IsKeyDown( KEY_SPACE ) ) if (RL_IsKeyDown(RL_KEY_SPACE)) CameraMoveUp(camera, RL_CAMERA_MOVE_SPEED);
CameraMoveUp( camera, CAMERA_MOVE_SPEED ); if (RL_IsKeyDown(RL_KEY_LEFT_CONTROL)) CameraMoveUp(camera, -RL_CAMERA_MOVE_SPEED);
if ( IsKeyDown( KEY_LEFT_CONTROL ) )
CameraMoveUp( camera, -CAMERA_MOVE_SPEED );
} }
} }
if ( ( mode == CAMERA_THIRD_PERSON ) || ( mode == CAMERA_ORBITAL ) || ( mode == CAMERA_FREE ) ) if ((mode == RL_CAMERA_THIRD_PERSON) || (mode == RL_CAMERA_ORBITAL) || (mode == RL_CAMERA_FREE))
{ {
// Zoom target distance // Zoom target distance
CameraMoveToTarget( camera, -GetMouseWheelMove() ); CameraMoveToTarget(camera, -RL_GetMouseWheelMove());
if ( IsKeyPressed( KEY_KP_SUBTRACT ) ) if (RL_IsKeyPressed(RL_KEY_KP_SUBTRACT)) CameraMoveToTarget(camera, 2.0f);
CameraMoveToTarget( camera, 2.0f ); if (RL_IsKeyPressed(RL_KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
if ( IsKeyPressed( KEY_KP_ADD ) )
CameraMoveToTarget( camera, -2.0f );
} }
} }
#endif #endif // !RCAMERA_STANDALONE
// !RCAMERA_STANDALONE
// Update camera movement, movement/rotation values should be provided by user // Update camera movement, movement/rotation values should be provided by user
void update_camera_pro( Camera* camera, Vector3 movement, Vector3 rotation, f32 zoom ) void RL_UpdateCameraPro(RL_Camera *camera, RL_Vector3 movement, RL_Vector3 rotation, float zoom)
{ {
// Required values
// movement.x - Move forward/backward
// movement.y - Move right/left
// movement.z - Move up/down
// rotation.x - yaw
// rotation.y - pitch
// rotation.z - roll
// zoom - Move towards target
bool lockView = true; bool lockView = true;
bool rotateAroundTarget = false; bool rotateAroundTarget = false;
bool rotateUp = false; bool rotateUp = false;
bool moveInWorldPlane = true; bool moveInWorldPlane = true;
// Camera rotation // RL_Camera rotation
CameraPitch( camera, -rotation.y * DEG2RAD, lockView, rotateAroundTarget, rotateUp ); CameraPitch(camera, -rotation.y*RL_DEG2RAD, lockView, rotateAroundTarget, rotateUp);
CameraYaw( camera, -rotation.x * DEG2RAD, rotateAroundTarget ); CameraYaw(camera, -rotation.x*RL_DEG2RAD, rotateAroundTarget);
CameraRoll( camera, rotation.z * DEG2RAD ); CameraRoll(camera, rotation.z*RL_DEG2RAD);
// Camera movement // RL_Camera movement
CameraMoveForward(camera, movement.x, moveInWorldPlane); CameraMoveForward(camera, movement.x, moveInWorldPlane);
CameraMoveRight(camera, movement.y, moveInWorldPlane); CameraMoveRight(camera, movement.y, moveInWorldPlane);
CameraMoveUp(camera, movement.z); CameraMoveUp(camera, movement.z);
@ -591,5 +555,4 @@ void update_camera_pro( Camera* camera, Vector3 movement, Vector3 rotation, f32
CameraMoveToTarget(camera, zoom); CameraMoveToTarget(camera, zoom);
} }
#endif #endif // RCAMERA_IMPLEMENTATION
// RCAMERA_IMPLEMENTATION

View File

@ -1,233 +0,0 @@
/**********************************************************************************************
*
* rcore - Common types and globals (all platforms)
*
* LIMITATIONS:
* - Limitation 01
* - Limitation 02
*
* POSSIBLE IMPROVEMENTS:
* - Improvement 01
* - Improvement 02
*
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5) and contributors
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
**********************************************************************************************/
#ifndef RCORE_H
#define RCORE_H
#include "raylib.h"
#include "utils.h" // Required for: TRACELOG() macros
#include "rlgl.h" // Required for: graphics layer functionality
#define RAYMATH_IMPLEMENTATION
#include "raymath.h" // Required for: Vector2/Vector3/Matrix functionality
#include <stdlib.h> // Required for: srand(), rand(), atexit()
#include <stdio.h> // Required for: sprintf() [Used in OpenURL()]
#include <string.h> // Required for: strrchr(), strcmp(), strlen(), memset()
#include <time.h> // Required for: time() [Used in InitTimer()]
#include <math.h> // Required for: tan() [Used in BeginMode3D()], atan2f() [Used in LoadVrStereoConfig()]
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
#ifndef MAX_FILEPATH_CAPACITY
#define MAX_FILEPATH_CAPACITY 8192 // Maximum capacity for filepath
#endif
#ifndef MAX_FILEPATH_LENGTH
#define MAX_FILEPATH_LENGTH 4096 // Maximum length for filepaths (Linux PATH_MAX default value)
#endif
#ifndef MAX_KEYBOARD_KEYS
#define MAX_KEYBOARD_KEYS 512 // Maximum number of keyboard keys supported
#endif
#ifndef MAX_MOUSE_BUTTONS
#define MAX_MOUSE_BUTTONS 8 // Maximum number of mouse buttons supported
#endif
#ifndef MAX_GAMEPADS
#define MAX_GAMEPADS 4 // Maximum number of gamepads supported
#endif
#ifndef MAX_GAMEPAD_AXIS
#define MAX_GAMEPAD_AXIS 8 // Maximum number of axis supported (per gamepad)
#endif
#ifndef MAX_GAMEPAD_BUTTONS
#define MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
#endif
#ifndef MAX_TOUCH_POINTS
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
#endif
#ifndef MAX_KEY_PRESSED_QUEUE
#define MAX_KEY_PRESSED_QUEUE 16 // Maximum number of keys in the key input queue
#endif
#ifndef MAX_CHAR_PRESSED_QUEUE
#define MAX_CHAR_PRESSED_QUEUE 16 // Maximum number of characters in the char input queue
#endif
#ifndef MAX_DECOMPRESSION_SIZE
#define MAX_DECOMPRESSION_SIZE 64 // Maximum size allocated for decompression in MB
#endif
// Flags operation macros
#define FLAG_SET( n, f ) ( ( n ) |= ( f ) )
#define FLAG_CLEAR( n, f ) ( ( n ) &= ~( f ) )
#define FLAG_TOGGLE( n, f ) ( ( n ) ^= ( f ) )
#define FLAG_CHECK( n, f ) ( ( n ) & ( f ) )
#if ( defined( __linux__ ) || defined( PLATFORM_WEB ) ) && ( _POSIX_C_SOURCE < 199309L )
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext.
#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef struct
{
int x;
int y;
} Point;
typedef struct
{
unsigned int width;
unsigned int height;
} Size;
// Core global state context data
typedef struct CoreData
{
struct
{
const char* title; // Window text title const pointer
unsigned int flags; // Configuration flags (bit based), keeps window state
bool ready; // Check if window has been initialized successfully
bool fullscreen; // Check if fullscreen mode is enabled
bool shouldClose; // Check if window set for closing
bool resizedLastFrame; // Check if window has been resized last frame
bool eventWaiting; // Wait for events before ending frame
Point position; // Window position (required on fullscreen toggle)
Point previousPosition; // Window previous position (required on borderless windowed toggle)
Size display; // Display width and height (monitor, device-screen, LCD, ...)
Size screen; // Screen width and height (used render area)
Size previousScreen; // Screen previous width and height (required on borderless windowed toggle)
Size currentFbo; // Current render width and height (depends on active fbo)
Size render; // Framebuffer width and height (render area, including black bars if required)
Point renderOffset; // Offset from render area (must be divided by 2)
Size screenMin; // Screen minimum width and height (for resizable window)
Size screenMax; // Screen maximum width and height (for resizable window)
Matrix screenScale; // Matrix to scale screen (framebuffer rendering)
char** dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
unsigned int dropFileCount; // Count dropped files strings
} Window;
struct
{
const char* basePath; // Base path for data storage
} Storage;
struct
{
struct
{
int exitKey; // Default exit key
char currentKeyState[ MAX_KEYBOARD_KEYS ]; // Registers current frame key state
char previousKeyState[ MAX_KEYBOARD_KEYS ]; // Registers previous frame key state
// NOTE: Since key press logic involves comparing prev vs cur key state, we need to handle key repeats specially
char keyRepeatInFrame[ MAX_KEYBOARD_KEYS ]; // Registers key repeats for current frame.
int keyPressedQueue[ MAX_KEY_PRESSED_QUEUE ]; // Input keys queue
int keyPressedQueueCount; // Input keys queue count
int charPressedQueue[ MAX_CHAR_PRESSED_QUEUE ]; // Input characters queue (unicode)
int charPressedQueueCount; // Input characters queue count
} Keyboard;
struct
{
Vector2 offset; // Mouse offset
Vector2 scale; // Mouse scaling
Vector2 currentPosition; // Mouse position on screen
Vector2 previousPosition; // Previous mouse position
int cursor; // Tracks current mouse cursor
bool cursorHidden; // Track if cursor is hidden
bool cursorOnScreen; // Tracks if cursor is inside client area
char currentButtonState[ MAX_MOUSE_BUTTONS ]; // Registers current mouse button state
char previousButtonState[ MAX_MOUSE_BUTTONS ]; // Registers previous mouse button state
Vector2 currentWheelMove; // Registers current mouse wheel variation
Vector2 previousWheelMove; // Registers previous mouse wheel variation
} Mouse;
struct
{
int pointCount; // Number of touch points active
int pointId[ MAX_TOUCH_POINTS ]; // Point identifiers
Vector2 position[ MAX_TOUCH_POINTS ]; // Touch position on screen
char currentTouchState[ MAX_TOUCH_POINTS ]; // Registers current touch state
char previousTouchState[ MAX_TOUCH_POINTS ]; // Registers previous touch state
} Touch;
struct
{
int lastButtonPressed; // Register last gamepad button pressed
int axisCount[ MAX_GAMEPADS ]; // Register number of available gamepad axis
bool ready[ MAX_GAMEPADS ]; // Flag to know if gamepad is ready
char name[ MAX_GAMEPADS ][ 64 ]; // Gamepad name holder
char currentButtonState[ MAX_GAMEPADS ][ MAX_GAMEPAD_BUTTONS ]; // Current gamepad buttons state
char previousButtonState[ MAX_GAMEPADS ][ MAX_GAMEPAD_BUTTONS ]; // Previous gamepad buttons state
float axisState[ MAX_GAMEPADS ][ MAX_GAMEPAD_AXIS ]; // Gamepad axis state
} Gamepad;
} Input;
struct
{
double current; // Current time measure
double previous; // Previous time measure
double update; // Time measure for frame update
double draw; // Time measure for frame draw
double frame; // Time measure for one frame
double target; // Desired time for one frame, if 0 not applied
unsigned long long int base; // Base time measure for hi-res timer (PLATFORM_ANDROID, PLATFORM_DRM)
unsigned int frameCounter; // Frame counter
} Time;
} CoreData;
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
extern CoreData CORE;
#endif

View File

@ -43,15 +43,15 @@
#ifndef RGESTURES_H #ifndef RGESTURES_H
#define RGESTURES_H #define RGESTURES_H
#ifndef PI #ifndef RL_PI
#define PI 3.14159265358979323846 #define RL_PI 3.14159265358979323846
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#ifndef MAX_TOUCH_POINTS #ifndef RL_MAX_TOUCH_POINTS
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported #define RL_MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -62,57 +62,49 @@
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800) #if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
#include <stdbool.h> #include <stdbool.h>
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE) #elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
typedef enum bool typedef enum bool { false = 0, true = !false } bool;
{
false = 0,
true = ! false
} bool;
#endif #endif
#if !defined(RL_VECTOR2_TYPE) #if !defined(RL_VECTOR2_TYPE)
// Vector2 type // RL_Vector2 type
typedef struct Vector2 typedef struct RL_Vector2 {
{
float x; float x;
float y; float y;
} Vector2; } RL_Vector2;
#endif #endif
#if defined(RGESTURES_STANDALONE) #if defined(RGESTURES_STANDALONE)
// Gestures type // Gestures type
// NOTE: It could be used as flags to enable only some gestures // NOTE: It could be used as flags to enable only some gestures
typedef enum typedef enum {
{ RL_GESTURE_NONE = 0,
GESTURE_NONE = 0, RL_GESTURE_TAP = 1,
GESTURE_TAP = 1, RL_GESTURE_DOUBLETAP = 2,
GESTURE_DOUBLETAP = 2, RL_GESTURE_HOLD = 4,
GESTURE_HOLD = 4, RL_GESTURE_DRAG = 8,
GESTURE_DRAG = 8, RL_GESTURE_SWIPE_RIGHT = 16,
GESTURE_SWIPE_RIGHT = 16, RL_GESTURE_SWIPE_LEFT = 32,
GESTURE_SWIPE_LEFT = 32, RL_GESTURE_SWIPE_UP = 64,
GESTURE_SWIPE_UP = 64, RL_GESTURE_SWIPE_DOWN = 128,
GESTURE_SWIPE_DOWN = 128, RL_GESTURE_PINCH_IN = 256,
GESTURE_PINCH_IN = 256, RL_GESTURE_PINCH_OUT = 512
GESTURE_PINCH_OUT = 512 } RL_Gesture;
} Gesture;
#endif #endif
typedef enum typedef enum {
{
TOUCH_ACTION_UP = 0, TOUCH_ACTION_UP = 0,
TOUCH_ACTION_DOWN, TOUCH_ACTION_DOWN,
TOUCH_ACTION_MOVE, TOUCH_ACTION_MOVE,
TOUCH_ACTION_CANCEL TOUCH_ACTION_CANCEL
} TouchAction; } RL_TouchAction;
// Gesture event // RL_Gesture event
typedef struct typedef struct {
{
int touchAction; int touchAction;
int pointCount; int pointCount;
int pointId[ MAX_TOUCH_POINTS ]; int pointId[RL_MAX_TOUCH_POINTS];
Vector2 position[ MAX_TOUCH_POINTS ]; RL_Vector2 position[RL_MAX_TOUCH_POINTS];
} GestureEvent; } RL_GestureEvent;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
@ -124,23 +116,22 @@ typedef struct
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" extern "C" { // Prevents name mangling of functions
{ // Prevents name mangling of functions
#endif #endif
void ProcessGestureEvent( GestureEvent event ); // Process gesture event and translate it into gestures void RL_ProcessGestureEvent(RL_GestureEvent event); // Process gesture event and translate it into gestures
void UpdateGestures( void ); // Update gestures detected (must be called every frame) void RL_UpdateGestures(void); // Update gestures detected (must be called every frame)
#if defined(RGESTURES_STANDALONE) #if defined(RGESTURES_STANDALONE)
void SetGesturesEnabled( unsigned int flags ); // Enable a set of gestures using flags void RL_SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
bool IsGestureDetected( int gesture ); // Check if a gesture have been detected bool RL_IsGestureDetected(int gesture); // Check if a gesture have been detected
int GetGestureDetected( void ); // Get latest detected gesture int RL_GetGestureDetected(void); // Get latest detected gesture
float GetGestureHoldDuration( void ); // Get gesture hold time in seconds float RL_GetGestureHoldDuration(void); // Get gesture hold time in seconds
Vector2 GetGestureDragVector( void ); // Get gesture drag vector RL_Vector2 RL_GetGestureDragVector(void); // Get gesture drag vector
float GetGestureDragAngle( void ); // Get gesture drag angle float RL_GetGestureDragAngle(void); // Get gesture drag angle
Vector2 GetGesturePinchVector( void ); // Get gesture pinch delta RL_Vector2 RL_GetGesturePinchVector(void); // Get gesture pinch delta
float GetGesturePinchAngle( void ); // Get gesture pinch angle float RL_GetGesturePinchAngle(void); // Get gesture pinch angle
#endif #endif
#if defined(__cplusplus) #if defined(__cplusplus)
@ -160,12 +151,11 @@ extern "C"
#if defined(RGESTURES_STANDALONE) #if defined(RGESTURES_STANDALONE)
#if defined(_WIN32) #if defined(_WIN32)
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" extern "C" { // Prevents name mangling of functions
{ // Prevents name mangling of functions
#endif #endif
// Functions required to query time on Windows // Functions required to query time on Windows
int __stdcall QueryPerformanceCounter( unsigned long long int* lpPerformanceCount ); int __stdcall RL_QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
int __stdcall QueryPerformanceFrequency( unsigned long long int* lpFrequency ); int __stdcall RL_QueryPerformanceFrequency(unsigned long long int *lpFrequency);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
@ -188,81 +178,70 @@ extern "C"
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Defines and Macros // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#define FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time #define RL_FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time
#define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f) #define RL_MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f)
#define DRAG_TIMEOUT 0.3f // Drag minimum time for web, measured in seconds #define RL_DRAG_TIMEOUT 0.3f // Drag minimum time for web, measured in seconds
#define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f) #define RL_MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
#define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds #define RL_TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds
#define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds #define RL_PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds
#define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f) #define RL_DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Gestures module state context [136 bytes] // Gestures module state context [136 bytes]
typedef struct typedef struct {
{
unsigned int current; // Current detected gesture unsigned int current; // Current detected gesture
unsigned int enabledFlags; // Enabled gestures flags unsigned int enabledFlags; // Enabled gestures flags
struct {
struct
{
int firstId; // Touch id for first touch point int firstId; // Touch id for first touch point
int pointCount; // Touch points counter int pointCount; // Touch points counter
double eventTime; // Time stamp when an event happened double eventTime; // Time stamp when an event happened
Vector2 upPosition; // Touch up position RL_Vector2 upPosition; // Touch up position
Vector2 downPositionA; // First touch down position RL_Vector2 downPositionA; // First touch down position
Vector2 downPositionB; // Second touch down position RL_Vector2 downPositionB; // Second touch down position
Vector2 downDragPosition; // Touch drag position RL_Vector2 downDragPosition; // Touch drag position
Vector2 moveDownPositionA; // First touch down position on move RL_Vector2 moveDownPositionA; // First touch down position on move
Vector2 moveDownPositionB; // Second touch down position on move RL_Vector2 moveDownPositionB; // Second touch down position on move
Vector2 previousPositionA; // Previous position A to compare for pinch gestures RL_Vector2 previousPositionA; // Previous position A to compare for pinch gestures
Vector2 previousPositionB; // Previous position B to compare for pinch gestures RL_Vector2 previousPositionB; // Previous position B to compare for pinch gestures
int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions) int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions)
} Touch; } Touch;
struct {
struct
{
bool resetRequired; // HOLD reset to get first touch point again bool resetRequired; // HOLD reset to get first touch point again
double timeDuration; // HOLD duration in seconds double timeDuration; // HOLD duration in seconds
} Hold; } Hold;
struct {
struct RL_Vector2 vector; // DRAG vector (between initial and current position)
{
Vector2 vector; // DRAG vector (between initial and current position)
float angle; // DRAG angle (relative to x-axis) float angle; // DRAG angle (relative to x-axis)
float distance; // DRAG distance (from initial touch point to final) (normalized [0..1]) float distance; // DRAG distance (from initial touch point to final) (normalized [0..1])
float intensity; // DRAG intensity, how far why did the DRAG (pixels per frame) float intensity; // DRAG intensity, how far why did the DRAG (pixels per frame)
} Drag; } Drag;
struct {
struct
{
double startTime; // SWIPE start time to calculate drag intensity double startTime; // SWIPE start time to calculate drag intensity
} Swipe; } Swipe;
struct {
struct RL_Vector2 vector; // PINCH vector (between first and second touch points)
{
Vector2 vector; // PINCH vector (between first and second touch points)
float angle; // PINCH angle (relative to x-axis) float angle; // PINCH angle (relative to x-axis)
float distance; // PINCH displacement distance (normalized [0..1]) float distance; // PINCH displacement distance (normalized [0..1])
} Pinch; } Pinch;
} GesturesData; } RL_GesturesData;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static GesturesData GESTURES = { static RL_GesturesData RL_GESTURES = {
.Touch.firstId = -1, .Touch.firstId = -1,
.current = GESTURE_NONE, // No current gesture detected .current = RL_GESTURE_NONE, // No current gesture detected
.enabledFlags = 0b0000001111111111 // All gestures supported by default .enabledFlags = 0b0000001111111111 // All gestures supported by default
}; };
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Declaration // Module specific Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static float rgVector2Angle( Vector2 initialPosition, Vector2 finalPosition ); static float rgVector2Angle(RL_Vector2 initialPosition, RL_Vector2 finalPosition);
static float rgVector2Distance( Vector2 v1, Vector2 v2 ); static float rgVector2Distance(RL_Vector2 v1, RL_Vector2 v2);
static double rgGetCurrentTime(void); static double rgGetCurrentTime(void);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -270,270 +249,252 @@ static double rgGetCurrentTime( void );
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Enable only desired gestures to be detected // Enable only desired gestures to be detected
void SetGesturesEnabled( unsigned int flags ) void RL_SetGesturesEnabled(unsigned int flags)
{ {
GESTURES.enabledFlags = flags; RL_GESTURES.enabledFlags = flags;
} }
// Check if a gesture have been detected // Check if a gesture have been detected
bool IsGestureDetected( unsigned int gesture ) bool RL_IsGestureDetected(unsigned int gesture)
{ {
if ( ( GESTURES.enabledFlags & GESTURES.current ) == gesture ) if ((RL_GESTURES.enabledFlags & RL_GESTURES.current) == gesture) return true;
return true; else return false;
else
return false;
} }
// Process gesture event and translate it into gestures // Process gesture event and translate it into gestures
void ProcessGestureEvent( GestureEvent event ) void RL_ProcessGestureEvent(RL_GestureEvent event)
{ {
// Reset required variables // Reset required variables
GESTURES.Touch.pointCount = event.pointCount; // Required on UpdateGestures() RL_GESTURES.Touch.pointCount = event.pointCount; // Required on RL_UpdateGestures()
if ( GESTURES.Touch.pointCount == 1 ) // One touch point if (RL_GESTURES.Touch.pointCount == 1) // One touch point
{ {
if (event.touchAction == TOUCH_ACTION_DOWN) if (event.touchAction == TOUCH_ACTION_DOWN)
{ {
GESTURES.Touch.tapCounter++; // Tap counter RL_GESTURES.Touch.tapCounter++; // Tap counter
// Detect GESTURE_DOUBLE_TAP // Detect GESTURE_DOUBLE_TAP
if ( ( GESTURES.current == GESTURE_NONE ) && ( GESTURES.Touch.tapCounter >= 2 ) if ((RL_GESTURES.current == RL_GESTURE_NONE) && (RL_GESTURES.Touch.tapCounter >= 2) && ((rgGetCurrentTime() - RL_GESTURES.Touch.eventTime) < RL_TAP_TIMEOUT) && (rgVector2Distance(RL_GESTURES.Touch.downPositionA, event.position[0]) < RL_DOUBLETAP_RANGE))
&& ( ( rgGetCurrentTime() - GESTURES.Touch.eventTime ) < TAP_TIMEOUT )
&& ( rgVector2Distance( GESTURES.Touch.downPositionA, event.position[ 0 ] ) < DOUBLETAP_RANGE ) )
{ {
GESTURES.current = GESTURE_DOUBLETAP; RL_GESTURES.current = RL_GESTURE_DOUBLETAP;
GESTURES.Touch.tapCounter = 0; RL_GESTURES.Touch.tapCounter = 0;
} }
else // Detect GESTURE_TAP else // Detect RL_GESTURE_TAP
{ {
GESTURES.Touch.tapCounter = 1; RL_GESTURES.Touch.tapCounter = 1;
GESTURES.current = GESTURE_TAP; RL_GESTURES.current = RL_GESTURE_TAP;
} }
GESTURES.Touch.downPositionA = event.position[ 0 ]; RL_GESTURES.Touch.downPositionA = event.position[0];
GESTURES.Touch.downDragPosition = event.position[ 0 ]; RL_GESTURES.Touch.downDragPosition = event.position[0];
GESTURES.Touch.upPosition = GESTURES.Touch.downPositionA; RL_GESTURES.Touch.upPosition = RL_GESTURES.Touch.downPositionA;
GESTURES.Touch.eventTime = rgGetCurrentTime(); RL_GESTURES.Touch.eventTime = rgGetCurrentTime();
GESTURES.Swipe.startTime = rgGetCurrentTime(); RL_GESTURES.Swipe.startTime = rgGetCurrentTime();
GESTURES.Drag.vector = ( Vector2 ) { 0.0f, 0.0f }; RL_GESTURES.Drag.vector = (RL_Vector2){ 0.0f, 0.0f };
} }
else if (event.touchAction == TOUCH_ACTION_UP) else if (event.touchAction == TOUCH_ACTION_UP)
{ {
// A swipe can happen while the current gesture is drag, but (specially for web) also hold, so set upPosition for both cases // A swipe can happen while the current gesture is drag, but (specially for web) also hold, so set upPosition for both cases
if ( GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD ) if (RL_GESTURES.current == RL_GESTURE_DRAG || RL_GESTURES.current == RL_GESTURE_HOLD) RL_GESTURES.Touch.upPosition = event.position[0];
GESTURES.Touch.upPosition = event.position[ 0 ];
// NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen // NOTE: RL_GESTURES.Drag.intensity dependent on the resolution of the screen
GESTURES.Drag.distance = rgVector2Distance( GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition ); RL_GESTURES.Drag.distance = rgVector2Distance(RL_GESTURES.Touch.downPositionA, RL_GESTURES.Touch.upPosition);
GESTURES.Drag.intensity = GESTURES.Drag.distance / ( float )( ( rgGetCurrentTime() - GESTURES.Swipe.startTime ) ); RL_GESTURES.Drag.intensity = RL_GESTURES.Drag.distance/(float)((rgGetCurrentTime() - RL_GESTURES.Swipe.startTime));
// Detect GESTURE_SWIPE // Detect GESTURE_SWIPE
if ( ( GESTURES.Drag.intensity > FORCE_TO_SWIPE ) && ( GESTURES.current != GESTURE_DRAG ) ) if ((RL_GESTURES.Drag.intensity > RL_FORCE_TO_SWIPE) && (RL_GESTURES.current != RL_GESTURE_DRAG))
{ {
// NOTE: Angle should be inverted in Y // NOTE: Angle should be inverted in Y
GESTURES.Drag.angle = 360.0f - rgVector2Angle( GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition ); RL_GESTURES.Drag.angle = 360.0f - rgVector2Angle(RL_GESTURES.Touch.downPositionA, RL_GESTURES.Touch.upPosition);
if ( ( GESTURES.Drag.angle < 30 ) || ( GESTURES.Drag.angle > 330 ) ) if ((RL_GESTURES.Drag.angle < 30) || (RL_GESTURES.Drag.angle > 330)) RL_GESTURES.current = RL_GESTURE_SWIPE_RIGHT; // Right
GESTURES.current = GESTURE_SWIPE_RIGHT; // Right else if ((RL_GESTURES.Drag.angle >= 30) && (RL_GESTURES.Drag.angle <= 150)) RL_GESTURES.current = RL_GESTURE_SWIPE_UP; // Up
else if ( ( GESTURES.Drag.angle >= 30 ) && ( GESTURES.Drag.angle <= 150 ) ) else if ((RL_GESTURES.Drag.angle > 150) && (RL_GESTURES.Drag.angle < 210)) RL_GESTURES.current = RL_GESTURE_SWIPE_LEFT; // Left
GESTURES.current = GESTURE_SWIPE_UP; // Up else if ((RL_GESTURES.Drag.angle >= 210) && (RL_GESTURES.Drag.angle <= 330)) RL_GESTURES.current = RL_GESTURE_SWIPE_DOWN; // Down
else if ( ( GESTURES.Drag.angle > 150 ) && ( GESTURES.Drag.angle < 210 ) ) else RL_GESTURES.current = RL_GESTURE_NONE;
GESTURES.current = GESTURE_SWIPE_LEFT; // Left
else if ( ( GESTURES.Drag.angle >= 210 ) && ( GESTURES.Drag.angle <= 330 ) )
GESTURES.current = GESTURE_SWIPE_DOWN; // Down
else
GESTURES.current = GESTURE_NONE;
} }
else else
{ {
GESTURES.Drag.distance = 0.0f; RL_GESTURES.Drag.distance = 0.0f;
GESTURES.Drag.intensity = 0.0f; RL_GESTURES.Drag.intensity = 0.0f;
GESTURES.Drag.angle = 0.0f; RL_GESTURES.Drag.angle = 0.0f;
GESTURES.current = GESTURE_NONE; RL_GESTURES.current = RL_GESTURE_NONE;
} }
GESTURES.Touch.downDragPosition = ( Vector2 ) { 0.0f, 0.0f }; RL_GESTURES.Touch.downDragPosition = (RL_Vector2){ 0.0f, 0.0f };
GESTURES.Touch.pointCount = 0; RL_GESTURES.Touch.pointCount = 0;
} }
else if (event.touchAction == TOUCH_ACTION_MOVE) else if (event.touchAction == TOUCH_ACTION_MOVE)
{ {
GESTURES.Touch.moveDownPositionA = event.position[ 0 ]; RL_GESTURES.Touch.moveDownPositionA = event.position[0];
if ( GESTURES.current == GESTURE_HOLD ) if (RL_GESTURES.current == RL_GESTURE_HOLD)
{ {
if ( GESTURES.Hold.resetRequired ) if (RL_GESTURES.Hold.resetRequired) RL_GESTURES.Touch.downPositionA = event.position[0];
GESTURES.Touch.downPositionA = event.position[ 0 ];
GESTURES.Hold.resetRequired = false; RL_GESTURES.Hold.resetRequired = false;
// Detect GESTURE_DRAG // Detect RL_GESTURE_DRAG
if ( ( rgGetCurrentTime() - GESTURES.Touch.eventTime ) > DRAG_TIMEOUT ) if ((rgGetCurrentTime() - RL_GESTURES.Touch.eventTime) > RL_DRAG_TIMEOUT)
{ {
GESTURES.Touch.eventTime = rgGetCurrentTime(); RL_GESTURES.Touch.eventTime = rgGetCurrentTime();
GESTURES.current = GESTURE_DRAG; RL_GESTURES.current = RL_GESTURE_DRAG;
} }
} }
GESTURES.Drag.vector.x = GESTURES.Touch.moveDownPositionA.x - GESTURES.Touch.downDragPosition.x; RL_GESTURES.Drag.vector.x = RL_GESTURES.Touch.moveDownPositionA.x - RL_GESTURES.Touch.downDragPosition.x;
GESTURES.Drag.vector.y = GESTURES.Touch.moveDownPositionA.y - GESTURES.Touch.downDragPosition.y; RL_GESTURES.Drag.vector.y = RL_GESTURES.Touch.moveDownPositionA.y - RL_GESTURES.Touch.downDragPosition.y;
} }
} }
else if ( GESTURES.Touch.pointCount == 2 ) // Two touch points else if (RL_GESTURES.Touch.pointCount == 2) // Two touch points
{ {
if (event.touchAction == TOUCH_ACTION_DOWN) if (event.touchAction == TOUCH_ACTION_DOWN)
{ {
GESTURES.Touch.downPositionA = event.position[ 0 ]; RL_GESTURES.Touch.downPositionA = event.position[0];
GESTURES.Touch.downPositionB = event.position[ 1 ]; RL_GESTURES.Touch.downPositionB = event.position[1];
GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA; RL_GESTURES.Touch.previousPositionA = RL_GESTURES.Touch.downPositionA;
GESTURES.Touch.previousPositionB = GESTURES.Touch.downPositionB; RL_GESTURES.Touch.previousPositionB = RL_GESTURES.Touch.downPositionB;
// GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB); //RL_GESTURES.Pinch.distance = rgVector2Distance(RL_GESTURES.Touch.downPositionA, RL_GESTURES.Touch.downPositionB);
GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x; RL_GESTURES.Pinch.vector.x = RL_GESTURES.Touch.downPositionB.x - RL_GESTURES.Touch.downPositionA.x;
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y; RL_GESTURES.Pinch.vector.y = RL_GESTURES.Touch.downPositionB.y - RL_GESTURES.Touch.downPositionA.y;
GESTURES.current = GESTURE_HOLD; RL_GESTURES.current = RL_GESTURE_HOLD;
GESTURES.Hold.timeDuration = rgGetCurrentTime(); RL_GESTURES.Hold.timeDuration = rgGetCurrentTime();
} }
else if (event.touchAction == TOUCH_ACTION_MOVE) else if (event.touchAction == TOUCH_ACTION_MOVE)
{ {
GESTURES.Pinch.distance = rgVector2Distance( GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB ); RL_GESTURES.Pinch.distance = rgVector2Distance(RL_GESTURES.Touch.moveDownPositionA, RL_GESTURES.Touch.moveDownPositionB);
GESTURES.Touch.moveDownPositionA = event.position[ 0 ]; RL_GESTURES.Touch.moveDownPositionA = event.position[0];
GESTURES.Touch.moveDownPositionB = event.position[ 1 ]; RL_GESTURES.Touch.moveDownPositionB = event.position[1];
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x; RL_GESTURES.Pinch.vector.x = RL_GESTURES.Touch.moveDownPositionB.x - RL_GESTURES.Touch.moveDownPositionA.x;
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y; RL_GESTURES.Pinch.vector.y = RL_GESTURES.Touch.moveDownPositionB.y - RL_GESTURES.Touch.moveDownPositionA.y;
if ( ( rgVector2Distance( GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA ) >= MINIMUM_PINCH ) if ((rgVector2Distance(RL_GESTURES.Touch.previousPositionA, RL_GESTURES.Touch.moveDownPositionA) >= RL_MINIMUM_PINCH) || (rgVector2Distance(RL_GESTURES.Touch.previousPositionB, RL_GESTURES.Touch.moveDownPositionB) >= RL_MINIMUM_PINCH))
|| ( rgVector2Distance( GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB ) >= MINIMUM_PINCH ) )
{ {
if ( rgVector2Distance( GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB ) if ( rgVector2Distance(RL_GESTURES.Touch.previousPositionA, RL_GESTURES.Touch.previousPositionB) > rgVector2Distance(RL_GESTURES.Touch.moveDownPositionA, RL_GESTURES.Touch.moveDownPositionB) ) RL_GESTURES.current = RL_GESTURE_PINCH_IN;
> rgVector2Distance( GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB ) ) else RL_GESTURES.current = RL_GESTURE_PINCH_OUT;
GESTURES.current = GESTURE_PINCH_IN;
else
GESTURES.current = GESTURE_PINCH_OUT;
} }
else else
{ {
GESTURES.current = GESTURE_HOLD; RL_GESTURES.current = RL_GESTURE_HOLD;
GESTURES.Hold.timeDuration = rgGetCurrentTime(); RL_GESTURES.Hold.timeDuration = rgGetCurrentTime();
} }
// NOTE: Angle should be inverted in Y // NOTE: Angle should be inverted in Y
GESTURES.Pinch.angle = 360.0f - rgVector2Angle( GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB ); RL_GESTURES.Pinch.angle = 360.0f - rgVector2Angle(RL_GESTURES.Touch.moveDownPositionA, RL_GESTURES.Touch.moveDownPositionB);
} }
else if (event.touchAction == TOUCH_ACTION_UP) else if (event.touchAction == TOUCH_ACTION_UP)
{ {
GESTURES.Pinch.distance = 0.0f; RL_GESTURES.Pinch.distance = 0.0f;
GESTURES.Pinch.angle = 0.0f; RL_GESTURES.Pinch.angle = 0.0f;
GESTURES.Pinch.vector = ( Vector2 ) { 0.0f, 0.0f }; RL_GESTURES.Pinch.vector = (RL_Vector2){ 0.0f, 0.0f };
GESTURES.Touch.pointCount = 0; RL_GESTURES.Touch.pointCount = 0;
GESTURES.current = GESTURE_NONE; RL_GESTURES.current = RL_GESTURE_NONE;
} }
} }
else if ( GESTURES.Touch.pointCount > 2 ) // More than two touch points else if (RL_GESTURES.Touch.pointCount > 2) // More than two touch points
{ {
// TODO: Process gesture events for more than two points // TODO: Process gesture events for more than two points
} }
} }
// Update gestures detected (must be called every frame) // Update gestures detected (must be called every frame)
void UpdateGestures( void ) void RL_UpdateGestures(void)
{ {
// NOTE: Gestures are processed through system callbacks on touch events // NOTE: Gestures are processed through system callbacks on touch events
// Detect GESTURE_HOLD // Detect RL_GESTURE_HOLD
if ( ( ( GESTURES.current == GESTURE_TAP ) || ( GESTURES.current == GESTURE_DOUBLETAP ) ) && ( GESTURES.Touch.pointCount < 2 ) ) if (((RL_GESTURES.current == RL_GESTURE_TAP) || (RL_GESTURES.current == RL_GESTURE_DOUBLETAP)) && (RL_GESTURES.Touch.pointCount < 2))
{ {
GESTURES.current = GESTURE_HOLD; RL_GESTURES.current = RL_GESTURE_HOLD;
GESTURES.Hold.timeDuration = rgGetCurrentTime(); RL_GESTURES.Hold.timeDuration = rgGetCurrentTime();
} }
// Detect GESTURE_NONE // Detect RL_GESTURE_NONE
if ( ( GESTURES.current == GESTURE_SWIPE_RIGHT ) || ( GESTURES.current == GESTURE_SWIPE_UP ) || ( GESTURES.current == GESTURE_SWIPE_LEFT ) if ((RL_GESTURES.current == RL_GESTURE_SWIPE_RIGHT) || (RL_GESTURES.current == RL_GESTURE_SWIPE_UP) || (RL_GESTURES.current == RL_GESTURE_SWIPE_LEFT) || (RL_GESTURES.current == RL_GESTURE_SWIPE_DOWN))
|| ( GESTURES.current == GESTURE_SWIPE_DOWN ) )
{ {
GESTURES.current = GESTURE_NONE; RL_GESTURES.current = RL_GESTURE_NONE;
} }
} }
// Get latest detected gesture // Get latest detected gesture
int GetGestureDetected( void ) int RL_GetGestureDetected(void)
{ {
// Get current gesture only if enabled // Get current gesture only if enabled
return ( GESTURES.enabledFlags & GESTURES.current ); return (RL_GESTURES.enabledFlags & RL_GESTURES.current);
} }
// Hold time measured in ms // Hold time measured in ms
float GetGestureHoldDuration( void ) float RL_GetGestureHoldDuration(void)
{ {
// NOTE: time is calculated on current gesture HOLD // NOTE: time is calculated on current gesture HOLD
double time = 0.0; double time = 0.0;
if ( GESTURES.current == GESTURE_HOLD ) if (RL_GESTURES.current == RL_GESTURE_HOLD) time = rgGetCurrentTime() - RL_GESTURES.Hold.timeDuration;
time = rgGetCurrentTime() - GESTURES.Hold.timeDuration;
return (float)time; return (float)time;
} }
// Get drag vector (between initial touch point to current) // Get drag vector (between initial touch point to current)
Vector2 GetGestureDragVector( void ) RL_Vector2 RL_GetGestureDragVector(void)
{ {
// NOTE: drag vector is calculated on one touch points TOUCH_ACTION_MOVE // NOTE: drag vector is calculated on one touch points TOUCH_ACTION_MOVE
return GESTURES.Drag.vector; return RL_GESTURES.Drag.vector;
} }
// Get drag angle // Get drag angle
// NOTE: Angle in degrees, horizontal-right is 0, counterclockwise // NOTE: Angle in degrees, horizontal-right is 0, counterclockwise
float GetGestureDragAngle( void ) float RL_GetGestureDragAngle(void)
{ {
// NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP // NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP
return GESTURES.Drag.angle; return RL_GESTURES.Drag.angle;
} }
// Get distance between two pinch points // Get distance between two pinch points
Vector2 GetGesturePinchVector( void ) RL_Vector2 RL_GetGesturePinchVector(void)
{ {
// NOTE: Pinch distance is calculated on two touch points TOUCH_ACTION_MOVE // NOTE: Pinch distance is calculated on two touch points TOUCH_ACTION_MOVE
return GESTURES.Pinch.vector; return RL_GESTURES.Pinch.vector;
} }
// Get angle between two pinch points // Get angle between two pinch points
// NOTE: Angle in degrees, horizontal-right is 0, counterclockwise // NOTE: Angle in degrees, horizontal-right is 0, counterclockwise
float GetGesturePinchAngle( void ) float RL_GetGesturePinchAngle(void)
{ {
// NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE // NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE
return GESTURES.Pinch.angle; return RL_GESTURES.Pinch.angle;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Definition // Module specific Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Get angle from two-points vector with X-axis // Get angle from two-points vector with X-axis
static float rgVector2Angle( Vector2 v1, Vector2 v2 ) static float rgVector2Angle(RL_Vector2 v1, RL_Vector2 v2)
{ {
float angle = atan2f( v2.y - v1.y, v2.x - v1.x ) * ( 180.0f / PI ); float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/RL_PI);
if ( angle < 0 ) if (angle < 0) angle += 360.0f;
angle += 360.0f;
return angle; return angle;
} }
// Calculate distance between two Vector2 // Calculate distance between two RL_Vector2
static float rgVector2Distance( Vector2 v1, Vector2 v2 ) static float rgVector2Distance(RL_Vector2 v1, RL_Vector2 v2)
{ {
float result; float result;
@ -551,13 +512,13 @@ static double rgGetCurrentTime( void )
double time = 0; double time = 0;
#if !defined(RGESTURES_STANDALONE) #if !defined(RGESTURES_STANDALONE)
time = GetTime(); time = RL_GetTime();
#else #else
#if defined(_WIN32) #if defined(_WIN32)
unsigned long long int clockFrequency, currentTime; unsigned long long int clockFrequency, currentTime;
QueryPerformanceFrequency( &clockFrequency ); // BE CAREFUL: Costly operation! RL_QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
QueryPerformanceCounter( &currentTime ); RL_QueryPerformanceCounter(&currentTime);
time = (double)currentTime/clockFrequency; // Time in seconds time = (double)currentTime/clockFrequency; // Time in seconds
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -32,16 +32,16 @@
#include <android/asset_manager.h> // Required for: AAssetManager #include <android/asset_manager.h> // Required for: AAssetManager
#endif #endif
#if defined( SUPPORT_TRACELOG ) #if defined(RL_SUPPORT_TRACELOG)
#define TRACELOG( level, ... ) TraceLog( level, __VA_ARGS__ ) #define RL_TRACELOG(level, ...) RL_TraceLog(level, __VA_ARGS__)
#if defined( SUPPORT_TRACELOG_DEBUG ) #if defined(RL_SUPPORT_TRACELOG_DEBUG)
#define TRACELOGD( ... ) TraceLog( LOG_DEBUG, __VA_ARGS__ ) #define TRACELOGD(...) RL_TraceLog(RL_LOG_DEBUG, __VA_ARGS__)
#else #else
#define TRACELOGD(...) (void)0 #define TRACELOGD(...) (void)0
#endif #endif
#else #else
#define TRACELOG( level, ... ) ( void )0 #define RL_TRACELOG(level, ...) (void)0
#define TRACELOGD(...) (void)0 #define TRACELOGD(...) (void)0
#endif #endif
@ -66,8 +66,7 @@
// Module Functions Declaration // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" extern "C" { // Prevents name mangling of functions
{ // Prevents name mangling of functions
#endif #endif
#if defined(PLATFORM_ANDROID) #if defined(PLATFORM_ANDROID)

View File

@ -1,9 +0,0 @@
__VERSION 1
word SUPPORT_MODULE_RSHAPES, RL_SUPPORT_MODULE_RSHAPES
word SUPPORT_MODULE_RTEXTURES, RL_SUPPORT_MODULE_RTEXTURES
word SUPPORT_MODULE_RTEXT, RL_SUPPORT_MODULE_RTEXT
word SUPPORT_MODULE_RMODELS, RL_SUPPORT_MODULE_RMODELS
word SUPPORT_MODULE_RAUDIO, RL_SUPPORT_MODULE_RAUDIO

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,34 @@
// rlgl.h
//namespace rlgl, RL_
namespace rl, RLGL_
//namespace RL_, RLGL_
namespace RL_OPENGL, RLGL_OPENGL
//word RLAPI, RLGLAPI
not include rlgl.h
word TRACELOG, RL_TRACELOG
not word RL_TEXTURE_MIN_FILTER
not word RL_TEXTURE_MAG_FILTER
not word RL_TEXTURE_FILTER_LINEAR
not word RL_PROJECTION
not word RL_MODELVIEW
not word RL_LINES
not word RL_TRIANGLES
not word RL_QUADS
not word RL_FLOAT
not word RL_UNSIGNED_BYTE
not word RL_MATRIX
word RLGL, RLGL_GLOBAL_DATA
word Matrix, RL_Matrix
word LOG_WARNING, RL_LOG_WARNING
word rlglInit, RLGL_Init
word rlglClose, RLGL_Close

View File

@ -6,15 +6,24 @@
#include "gen.builder.cpp" #include "gen.builder.cpp"
constexpr char const* path_config = "config.h"; constexpr char const* path_config_h = "config.h";
constexpr char const* path_raylib = "raylib.h"; constexpr char const* path_raylib_h = "raylib.h";
constexpr char const* path_raymath = "raymath.h"; constexpr char const* path_raymath_h = "raymath.h";
constexpr char const* path_rcamera = "rcamera.h"; constexpr char const* path_rcamera_h = "rcamera.h";
constexpr char const* path_rcore = "rcore.h"; constexpr char const* path_rcore_h = "rcore.h";
constexpr char const* path_rgestures = "rgestures.h"; constexpr char const* path_rgestures_h = "rgestures.h";
constexpr char const* path_rgl = "rgl.h"; constexpr char const* path_rgl_h = "rgl.h";
constexpr char const* path_rtext = "rtext.h"; constexpr char const* path_rtext_h = "rtext.h";
constexpr char const* path_rcore_desktop_c = "rcore_desktop.c";
constexpr char const* path_raudio_c = "raudio.c";
constexpr char const* path_rcore_c = "rcore.c";
constexpr char const* path_rglfw_c = "rglfw.c";
constexpr char const* path_rmodels_c = "rmodels.c";
constexpr char const* path_rtext_c = "rtext.c";
constexpr char const* path_rtextures_c = "rtextures.c";
constexpr char const* path_rutils_c = "rutils.c";
using namespace gen; using namespace gen;
@ -117,6 +126,18 @@ StringCached pascal_to_lower_snake(StringCached str)
return result; return result;
} }
void refactor_define( CodeDefine& code )
{
local_persist String name_scratch = String::make_reserve( GlobalAllocator, kilobytes(1) );
if ( str_compare( elem->Name, txt("RL"), 2 ) == 0 || str_compare( elem->Name, txt("RAYLIB"), 6 ) == 0 )
continue;
name_scratch.append_fmt( "%RL_%S", elem->Name );
elem->Name = get_cached_string( name_scratch );
name_scratch.clear();
}
void refactor_enum( CodeEnum& code ) void refactor_enum( CodeEnum& code )
{ {
for ( Code elem : code->Body ) for ( Code elem : code->Body )
@ -181,8 +202,11 @@ void refactor_typename( CodeType& type )
void refactor_fn( CodeFn& fn ) void refactor_fn( CodeFn& fn )
{ {
StringCached original_name = fn->Name;
fn->Name = pascal_to_lower_snake( fn->Name ); fn->Name = pascal_to_lower_snake( fn->Name );
log_fmt( "%S", "Proc ID: %S -> %S", original_name, fn->Name );
for ( CodeParam param : fn->Params ) for ( CodeParam param : fn->Params )
{ {
refactor_typename( param->ValueType ); refactor_typename( param->ValueType );
@ -206,7 +230,7 @@ void refactor_file( char const* path )
FileContents contents = file_read_contents( GlobalAllocator, true, path ); FileContents contents = file_read_contents( GlobalAllocator, true, path );
CodeBody code = parse_global_body( { contents.size, rcast(char const*, contents.data) } ); CodeBody code = parse_global_body( { contents.size, rcast(char const*, contents.data) } );
String name_scratch = String::make_reserve( GlobalAllocator, kilobytes(1) ); local_perist String name_scratch = String::make_reserve( GlobalAllocator, kilobytes(1) );
// CodeBody includes // CodeBody includes
// CodeBody nspace_body = def_body( ECode::Namespace ); // CodeBody nspace_body = def_body( ECode::Namespace );
@ -216,12 +240,7 @@ void refactor_file( char const* path )
{ {
if ( elem->Type == ECode::Preprocess_Define ) if ( elem->Type == ECode::Preprocess_Define )
{ {
if ( str_compare( elem->Name, txt("RL"), 2 ) == 0 || str_compare( elem->Name, txt("RAYLIB"), 6 ) == 0 ) refactor_define( elem.cast<CodeDefine>() );
continue;
name_scratch.append_fmt( "%RL_%S", elem->Name );
elem->Name = get_cached_string( name_scratch );
name_scratch.clear();
} }
if ( elem->Type == ECode::Enum ) if ( elem->Type == ECode::Enum )
@ -275,16 +294,29 @@ void refactor_file( char const* path )
Builder builder = Builder::open( path ); Builder builder = Builder::open( path );
builder.print( new_code ); builder.print( new_code );
builder.write(); builder.write();
name_scratch.clear();
} }
int gen_main() int gen_main()
{ {
gen::init(); gen::init();
refactor_file( path_config ); refactor_file( path_config_h );
refactor_file( path_raylib ); refactor_file( path_raylib_h );
refactor_file( path_raymath ); refactor_file( path_rcamera_h );
refactor_file( path_rcamera ); refactor_file( path_raymath_h );
refactor_file( path_rcore_h );
refactor_file( path_rgl_h );
refactor_file( path_rtext_h );
refactor_file( path_rcore_desktop_c );
refactor_file( path_raudio_c );
refactor_file( path_rcore_c );
refactor_file( path_rglfw_c );
refactor_file( path_rmodels_c );
refactor_file( path_rtext_c );
refactor_file( path_rutils_c );
return 0; return 0;
} }

View File

@ -67,12 +67,14 @@ function setup-raylib {
new-item -path $path_raylib_inc -ItemType Directory new-item -path $path_raylib_inc -ItemType Directory
new-item -path $path_raylib_lib -ItemType Directory new-item -path $path_raylib_lib -ItemType Directory
$url_raylib_zip = 'https://github.com/raysan5/raylib/archive/refs/heads/master.zip' $url_raylib_zip = 'https://github.com/Ed94/raylib_refactored/archive/refs/heads/refactor-support.zip'
$path_raylib_zip = join-path $path_temp 'raylib.zip' $path_raylib_zip = join-path $path_temp 'raylib.zip'
$path_raylib_master = join-path $path_temp 'raylib-master' $path_raylib_master = join-path $path_temp 'raylib_refactored-refactor-support'
$path_raylib_src = join-path $path_raylib_master 'src' $path_raylib_src = join-path $path_raylib_master 'src'
$path_raylib_platforms = join-path $path_raylib_src 'platforms'
$path_raylib_glfw_inc = join-path $path_raylib_src 'external/glfw/include' $path_raylib_glfw_inc = join-path $path_raylib_src 'external/glfw/include'
$path_raylib_gputex = join-path $path_raylib_src 'external/rl_gputex.h'
remove-item $path_raylib_master -Recurse remove-item $path_raylib_master -Recurse
#invoke-webrequest -uri $url_raylib_zip -outfile $path_raylib_zip #invoke-webrequest -uri $url_raylib_zip -outfile $path_raylib_zip
@ -85,11 +87,79 @@ function setup-raylib {
New-Item $path_build -ItemType Directory New-Item $path_build -ItemType Directory
} }
$raylib_headers = Get-ChildItem -Path $path_raylib_src -Filter "*.h" -File $raylib_headers = Get-ChildItem -Path $path_raylib_src -Filter '*.h' -File
$raylib_modules = get-childitem -path $path_raylib_src -filter "*.c" -file $raylib_modules = get-childitem -path $path_raylib_src -filter '*.c' -file
# Refactor raylib # Refactor with refactor.exe
if ( $true ) { if ( $true ) {
$path_refactor = join-path $path_raylib 'raylib_c.refactor'
$path_refactor_rlgl = join-path $path_raylib 'raylib_c_gl.refactor'
$fmt_includes = @()
foreach ( $header in $raylib_headers ) {
$file_name = split-path $header -leaf
if ( -not $file_name.Equals('rlgl.h' ) ) {
$fmt_includes += "$header"
}
}
foreach ( $module in $raylib_modules ) {
$fmt_includes += "$module"
}
$fmt_includes += "$path_raylib_gputex"
$platform_modules = @()
foreach ( $module in (get-childitem -path $path_raylib_platforms -filter '*.c' -file) ) {
$platform_modules += "$module"
}
$path_rlgl = join-path $path_raylib_src 'rlgl.h'
Push-Location $path_raylib_src
write-host "Beginning refactor...`n"
$refactors = @(@())
$refactorParams = @(
"-debug",
"-num=$($fmt_includes.Count)"
"-src=$($fmt_includes)",
"-spec=$($path_refactor)"
)
& refactor $refactorParams
Write-Host "`nRefactoring complete`n`n"
Pop-Location
Push-Location $path_raylib_platforms
write-host "Beginning refactor...`n"
$refactors = @(@())
$refactorParams = @(
"-debug",
"-num=$($platform_modules.Count)"
"-src=$($platform_modules)",
"-spec=$($path_refactor)"
)
& refactor $refactorParams
Write-Host "`nRefactoring complete`n`n"
Pop-Location
Push-Location $path_raylib_src
$gl_modules = @( "$path_rlgl", "$path_raylib_gputex" )
write-host "Beginning refactor just for rlgl.h...`n"
$refactors = @(@())
$refactorParams = @(
"-debug",
"-num=$($gl_modules.Count)"
"-src=$($gl_modules)",
"-spec=$($path_refactor_rlgl)"
)
& refactor $refactorParams
Write-Host "`nRefactoring complete`n`n"
Pop-Location
}
# Refactor raylib with gencpp
if ( $false ) {
# if ( $false ) { # if ( $false ) {
$path_gencpp = join-path $path_root 'project/gen' $path_gencpp = join-path $path_root 'project/gen'
@ -133,7 +203,7 @@ function setup-raylib {
} }
# Build raylib # Build raylib
if ( $false ) { if ( $true ) {
# Microsoft # Microsoft
$lib_gdi32 = 'Gdi32.lib' $lib_gdi32 = 'Gdi32.lib'
$lib_shell32 = 'Shell32.lib' $lib_shell32 = 'Shell32.lib'