Added raylib library. Removed third_party dir.
This commit is contained in:
372
raylib/include/config.h
Normal file
372
raylib/include/config.h
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
/**********************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib configuration flags
|
||||||
|
*
|
||||||
|
* This file defines the configuration flags for different raylib features per-module
|
||||||
|
*
|
||||||
|
* NOTE: Additional values are configured per-module and can be set on compile time
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018-2026 Ahmad Fatoum and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* 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 CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#if !defined(EXTERNAL_CONFIG_FLAGS)
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module selection - Some modules could be avoided
|
||||||
|
// Mandatory modules: rcore, rlgl
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
#ifndef SUPPORT_MODULE_RSHAPES
|
||||||
|
#define SUPPORT_MODULE_RSHAPES 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_MODULE_RTEXTURES
|
||||||
|
#define SUPPORT_MODULE_RTEXTURES 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_MODULE_RTEXT
|
||||||
|
#define SUPPORT_MODULE_RTEXT 1 // WARNING: It requires SUPPORT_MODULE_RTEXTURES to load sprite font textures
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_MODULE_RMODELS
|
||||||
|
#define SUPPORT_MODULE_RMODELS 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_MODULE_RAUDIO
|
||||||
|
#define SUPPORT_MODULE_RAUDIO 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: rcore - Configuration Flags
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
#ifndef SUPPORT_TRACELOG
|
||||||
|
// Show TRACELOG() output messages
|
||||||
|
#define SUPPORT_TRACELOG 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_CAMERA_SYSTEM
|
||||||
|
// Camera module is included (rcamera.h) and multiple predefined
|
||||||
|
// cameras are available: free, 1st/3rd person, orbital
|
||||||
|
#define SUPPORT_CAMERA_SYSTEM 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_GESTURES_SYSTEM
|
||||||
|
// Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
|
||||||
|
#define SUPPORT_GESTURES_SYSTEM 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_RPRAND_GENERATOR
|
||||||
|
// Include pseudo-random numbers generator (rprand.h), based on Xoshiro128** and SplitMix64
|
||||||
|
#define SUPPORT_RPRAND_GENERATOR 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_MOUSE_GESTURES
|
||||||
|
// Mouse gestures are directly mapped like touches and processed by gestures system
|
||||||
|
#define SUPPORT_MOUSE_GESTURES 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_SSH_KEYBOARD_RPI
|
||||||
|
// Reconfigure standard input to receive key inputs, works with SSH connection
|
||||||
|
#define SUPPORT_SSH_KEYBOARD_RPI 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_WINMM_HIGHRES_TIMER
|
||||||
|
// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions
|
||||||
|
// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often
|
||||||
|
#define SUPPORT_WINMM_HIGHRES_TIMER 1
|
||||||
|
#endif
|
||||||
|
#if !SUPPORT_BUSY_WAIT_LOOP && !SUPPORT_PARTIALBUSY_WAIT_LOOP
|
||||||
|
// Use busy wait loop for timing sync, if not defined, a high-resolution timer is set up and used
|
||||||
|
#define SUPPORT_BUSY_WAIT_LOOP 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#if !SUPPORT_PARTIALBUSY_WAIT_LOOP && !SUPPORT_BUSY_WAIT_LOOP
|
||||||
|
// Use a partial-busy wait loop, in this case frame sleeps for most of the time,
|
||||||
|
// but then runs a busy loop at the end for accuracy
|
||||||
|
#define SUPPORT_PARTIALBUSY_WAIT_LOOP 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_SCREEN_CAPTURE
|
||||||
|
// Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
|
||||||
|
// WARNING: It requires SUPPORT_FILEFORMAT_PNG flag
|
||||||
|
#define SUPPORT_SCREEN_CAPTURE 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_COMPRESSION_API
|
||||||
|
// Support CompressData() and DecompressData() functions
|
||||||
|
#define SUPPORT_COMPRESSION_API 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_AUTOMATION_EVENTS
|
||||||
|
// Support automatic generated events, loading and recording of those events when required
|
||||||
|
#define SUPPORT_AUTOMATION_EVENTS 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_CUSTOM_FRAME_CONTROL
|
||||||
|
// Support custom frame control, only for advanced users
|
||||||
|
// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents()
|
||||||
|
// Enabling this flag allows manual control of the frame processes, use at your own risk
|
||||||
|
#define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_CLIPBOARD_IMAGE
|
||||||
|
// Support for clipboard image loading
|
||||||
|
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
|
||||||
|
// WARNING: It requires support for some additional flags:
|
||||||
|
// - SUPPORT_MODULE_RTEXTURES
|
||||||
|
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
|
||||||
|
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
|
||||||
|
// - SUPPORT_FILEFORMAT_JPG
|
||||||
|
#define SUPPORT_CLIPBOARD_IMAGE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// rcore: Configuration values
|
||||||
|
// NOTE: Below values are alread defined inside [rcore.c] so there is no need to be
|
||||||
|
// redefined here, in case it must be done, just uncomment the required line and update
|
||||||
|
// the value; it can also be done on compilation with -DVALUE_TO_REDEFINE=128
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
//#define MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message
|
||||||
|
//#define MAX_FILEPATH_CAPACITY 8192 // Maximum file paths capacity
|
||||||
|
//#define MAX_FILEPATH_LENGTH 4096 // Maximum length for filepaths (Linux PATH_MAX default value)
|
||||||
|
//#define MAX_KEYBOARD_KEYS 512 // Maximum number of keyboard keys supported
|
||||||
|
//#define MAX_MOUSE_BUTTONS 8 // Maximum number of mouse buttons supported
|
||||||
|
//#define MAX_GAMEPADS 4 // Maximum number of gamepads supported
|
||||||
|
//#define MAX_GAMEPAD_AXES 8 // Maximum number of axes supported (per gamepad)
|
||||||
|
//#define MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
|
||||||
|
//#define MAX_GAMEPAD_VIBRATION_TIME 2.0f // Maximum vibration time in seconds
|
||||||
|
//#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
||||||
|
//#define MAX_KEY_PRESSED_QUEUE 16 // Maximum number of keys in the key input queue
|
||||||
|
//#define MAX_CHAR_PRESSED_QUEUE 16 // Maximum number of characters in the char input queue
|
||||||
|
//#define MAX_DECOMPRESSION_SIZE 64 // Max size allocated for decompression in MB
|
||||||
|
//#define MAX_AUTOMATION_EVENTS 16384 // Maximum number of automation events to record
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: rlgl - Configuration values
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
#ifndef RLGL_ENABLE_OPENGL_DEBUG_CONTEXT
|
||||||
|
// Request OpenGL debug context (only available on OpenGL 4.3)
|
||||||
|
#define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT 0
|
||||||
|
#endif
|
||||||
|
#ifndef RLGL_SHOW_GL_DETAILS_INFO
|
||||||
|
// Show OpenGL detailed info on initialization,
|
||||||
|
// supported GL extensions and GL capabilities
|
||||||
|
#define RLGL_SHOW_GL_DETAILS_INFO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// rlgl: Configuration values
|
||||||
|
// NOTE: Below values are alread defined inside [rlgl.h] so there is no need to be
|
||||||
|
// redefined here, in case it must be done, just uncomment the required line and update
|
||||||
|
// the value; it can also be done on compilation with -DVALUE_TO_REDEFINE=128
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
//#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 (SetShaderValueTexture())
|
||||||
|
//#define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
|
||||||
|
//#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
||||||
|
//#define RL_CULL_DISTANCE_NEAR 0.05 // Default projection matrix near cull distance
|
||||||
|
//#define RL_CULL_DISTANCE_FAR 4000.0 // Default projection matrix far cull distance
|
||||||
|
|
||||||
|
// Default shader vertex attribute locations
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION 0
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD 1
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL 2
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 6
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES 7
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM 9
|
||||||
|
|
||||||
|
// Default shader vertex attribute/uniform names to set location points
|
||||||
|
// NOTE: When a new shader is loaded, locations are tried to be set for convenience, looking for the names defined here
|
||||||
|
// In case custom shader names are used, it's up to the user to set locations with GetShaderLocation*() functions
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEINDICES "vertexBoneIndices" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS
|
||||||
|
//#define RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM "instanceTransform" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM
|
||||||
|
//#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 (tint color, multiplied by texture color)
|
||||||
|
//#define RL_DEFAULT_SHADER_UNIFORM_NAME_BONEMATRICES "boneMatrices" // bone matrices
|
||||||
|
//#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)
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: rshapes - Configuration Flags
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
#ifndef SUPPORT_QUADS_DRAW_MODE
|
||||||
|
// Use QUADS instead of TRIANGLES for drawing when possible
|
||||||
|
// Some lines-based shapes could still use lines
|
||||||
|
#define SUPPORT_QUADS_DRAW_MODE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: rtextures - Configuration Flags
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Selected desired fileformats to be supported for image data loading
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_PNG
|
||||||
|
#define SUPPORT_FILEFORMAT_PNG 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_BMP
|
||||||
|
// NOTE: BMP support required for clipboard images on Windows
|
||||||
|
#define SUPPORT_FILEFORMAT_BMP 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_TGA
|
||||||
|
#define SUPPORT_FILEFORMAT_TGA 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_JPG
|
||||||
|
#define SUPPORT_FILEFORMAT_JPG 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_GIF
|
||||||
|
#define SUPPORT_FILEFORMAT_GIF 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_QOI
|
||||||
|
#define SUPPORT_FILEFORMAT_QOI 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_PSD
|
||||||
|
#define SUPPORT_FILEFORMAT_PSD 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_DDS
|
||||||
|
#define SUPPORT_FILEFORMAT_DDS 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_HDR
|
||||||
|
#define SUPPORT_FILEFORMAT_HDR 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_PIC
|
||||||
|
#define SUPPORT_FILEFORMAT_PIC 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_KTX
|
||||||
|
#define SUPPORT_FILEFORMAT_KTX 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_ASTC
|
||||||
|
#define SUPPORT_FILEFORMAT_ASTC 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_PKM
|
||||||
|
#define SUPPORT_FILEFORMAT_PKM 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_PVR
|
||||||
|
#define SUPPORT_FILEFORMAT_PVR 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SUPPORT_IMAGE_EXPORT
|
||||||
|
// Support image export functionality (.png, .bmp, .tga, .jpg, .qoi)
|
||||||
|
// NOTE: Image export requires stb_image_write.h library
|
||||||
|
#define SUPPORT_IMAGE_EXPORT 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_IMAGE_GENERATION
|
||||||
|
// Support procedural image generation functionality: gradient, spot, perlin-noise, cellular...
|
||||||
|
// NOTE: Perlin noise requires stb_perlin.h library
|
||||||
|
#define SUPPORT_IMAGE_GENERATION 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: rtext - Configuration Flags
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Selected desired font fileformats to be supported for loading
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_TTF
|
||||||
|
#define SUPPORT_FILEFORMAT_TTF 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_FNT
|
||||||
|
#define SUPPORT_FILEFORMAT_FNT 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_BDF
|
||||||
|
#define SUPPORT_FILEFORMAT_BDF 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: rmodels - Configuration Flags
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Selected desired model fileformats to be supported for loading
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_OBJ
|
||||||
|
#define SUPPORT_FILEFORMAT_OBJ 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_MTL
|
||||||
|
#define SUPPORT_FILEFORMAT_MTL 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_IQM
|
||||||
|
#define SUPPORT_FILEFORMAT_IQM 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_GLTF
|
||||||
|
#define SUPPORT_FILEFORMAT_GLTF 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_VOX
|
||||||
|
#define SUPPORT_FILEFORMAT_VOX 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_M3D
|
||||||
|
#define SUPPORT_FILEFORMAT_M3D 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_MESH_GENERATION
|
||||||
|
// Support procedural mesh generation functions, uses external par_shapes.h library
|
||||||
|
// NOTE: Some generated meshes DO NOT include generated texture coordinates
|
||||||
|
#define SUPPORT_MESH_GENERATION 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_GPU_SKINNING
|
||||||
|
// GPU skinning disabled by default, some GPUs do not support more than 8 VBOs
|
||||||
|
#define SUPPORT_GPU_SKINNING 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module: raudio - Configuration Flags
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Desired audio fileformats to be supported for loading
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_WAV
|
||||||
|
#define SUPPORT_FILEFORMAT_WAV 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_OGG
|
||||||
|
#define SUPPORT_FILEFORMAT_OGG 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_MP3
|
||||||
|
#define SUPPORT_FILEFORMAT_MP3 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_QOA
|
||||||
|
#define SUPPORT_FILEFORMAT_QOA 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_FLAC
|
||||||
|
#define SUPPORT_FILEFORMAT_FLAC 0 // Disabled by default
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_XM
|
||||||
|
#define SUPPORT_FILEFORMAT_XM 1
|
||||||
|
#endif
|
||||||
|
#ifndef SUPPORT_FILEFORMAT_MOD
|
||||||
|
#define SUPPORT_FILEFORMAT_MOD 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// raudio: Configuration values
|
||||||
|
// NOTE: Below values are alread defined inside [rlgl.h] so there is no need to be
|
||||||
|
// redefined here, in case it must be done, just uncomment the required line and update
|
||||||
|
// the value; it can also be done on compilation with -DVALUE_TO_REDEFINE=128
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
//#define AUDIO_DEVICE_FORMAT ma_format_f32 // Device output format (miniaudio: float-32bit)
|
||||||
|
//#define AUDIO_DEVICE_CHANNELS 2 // Device output channels: stereo
|
||||||
|
//#define AUDIO_DEVICE_SAMPLE_RATE 0 // Device sample rate (device default)
|
||||||
|
//#define AUDIO_DEVICE_PERIOD_SIZE_IN_FRAMES 0 // Device period size (controls latency, 0 defaults to 10ms)
|
||||||
|
//#define MAX_AUDIO_BUFFER_POOL_CHANNELS 16 // Maximum number of audio pool channels
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
#endif // !EXTERNAL_CONFIG_FLAGS
|
||||||
|
|
||||||
|
// NOTE: Following macro depends on config flag that can
|
||||||
|
// be externally defined, so, it needs to be outside EXTERNAL_CONFIG_FLAGS
|
||||||
|
#if SUPPORT_TRACELOG
|
||||||
|
#define TRACELOG(level, ...) TraceLog(level, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define TRACELOG(level, ...) (void)0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // CONFIG_H
|
||||||
1740
raylib/include/raylib.h
Normal file
1740
raylib/include/raylib.h
Normal file
File diff suppressed because it is too large
Load Diff
3146
raylib/include/raymath.h
Normal file
3146
raylib/include/raymath.h
Normal file
File diff suppressed because it is too large
Load Diff
563
raylib/include/rcamera.h
Normal file
563
raylib/include/rcamera.h
Normal file
@@ -0,0 +1,563 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* rcamera - Basic camera system with support for multiple camera modes
|
||||||
|
*
|
||||||
|
* CONFIGURATION:
|
||||||
|
* #define RCAMERA_IMPLEMENTATION
|
||||||
|
* Generates the implementation of the library into the included file.
|
||||||
|
* If not defined, the library is in header only mode and can be included in other headers
|
||||||
|
* or source files without problems. But only ONE file should hold the implementation.
|
||||||
|
*
|
||||||
|
* #define RCAMERA_STANDALONE
|
||||||
|
* If defined, the library can be used as standalone as a camera system but some
|
||||||
|
* functions must be redefined to manage inputs accordingly.
|
||||||
|
*
|
||||||
|
* CONTRIBUTORS:
|
||||||
|
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||||
|
* Christoph Wagner: Complete redesign, using raymath (2022)
|
||||||
|
* Marc Palau: Initial implementation (2014)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022-2026 Christoph Wagner (@Crydsch) and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* 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 RCAMERA_H
|
||||||
|
#define RCAMERA_H
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Function specifiers definition
|
||||||
|
|
||||||
|
// 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
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if defined(BUILD_LIBTYPE_SHARED)
|
||||||
|
#if defined(__TINYC__)
|
||||||
|
#define __declspec(x) __attribute__((x))
|
||||||
|
#endif
|
||||||
|
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||||
|
#elif defined(USE_LIBTYPE_SHARED)
|
||||||
|
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef RLAPI
|
||||||
|
#define RLAPI // Functions defined as 'extern' by default (implicit specifiers)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(RCAMERA_STANDALONE)
|
||||||
|
#define CAMERA_CULL_DISTANCE_NEAR 0.05
|
||||||
|
#define CAMERA_CULL_DISTANCE_FAR 4000.0
|
||||||
|
#else
|
||||||
|
#define CAMERA_CULL_DISTANCE_NEAR RL_CULL_DISTANCE_NEAR
|
||||||
|
#define CAMERA_CULL_DISTANCE_FAR RL_CULL_DISTANCE_FAR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
// NOTE: Below types are required for standalone usage
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#if defined(RCAMERA_STANDALONE)
|
||||||
|
// Vector2, 2 components
|
||||||
|
typedef struct Vector2 {
|
||||||
|
float x; // Vector x component
|
||||||
|
float y; // Vector y component
|
||||||
|
} Vector2;
|
||||||
|
|
||||||
|
// Vector3, 3 components
|
||||||
|
typedef struct Vector3 {
|
||||||
|
float x; // Vector x component
|
||||||
|
float y; // Vector y component
|
||||||
|
float z; // Vector z component
|
||||||
|
} Vector3;
|
||||||
|
|
||||||
|
// Matrix, 4x4 components, column major, OpenGL style, right-handed
|
||||||
|
typedef struct Matrix {
|
||||||
|
float m0, m4, m8, m12; // Matrix first row (4 components)
|
||||||
|
float m1, m5, m9, m13; // Matrix second row (4 components)
|
||||||
|
float m2, m6, m10, m14; // Matrix third row (4 components)
|
||||||
|
float m3, m7, m11, m15; // Matrix fourth row (4 components)
|
||||||
|
} Matrix;
|
||||||
|
|
||||||
|
// Camera type, defines a camera position/orientation in 3d space
|
||||||
|
typedef struct Camera3D {
|
||||||
|
Vector3 position; // Camera position
|
||||||
|
Vector3 target; // Camera target it looks-at
|
||||||
|
Vector3 up; // Camera up vector (rotation over its axis)
|
||||||
|
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
|
||||||
|
int projection; // Camera projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||||
|
} 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
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RLAPI Vector3 GetCameraForward(Camera *camera);
|
||||||
|
RLAPI Vector3 GetCameraUp(Camera *camera);
|
||||||
|
RLAPI Vector3 GetCameraRight(Camera *camera);
|
||||||
|
|
||||||
|
// Camera movement
|
||||||
|
RLAPI void CameraMoveForward(Camera *camera, float distance, bool moveInWorldPlane);
|
||||||
|
RLAPI void CameraMoveUp(Camera *camera, float distance);
|
||||||
|
RLAPI void CameraMoveRight(Camera *camera, float distance, bool moveInWorldPlane);
|
||||||
|
RLAPI void CameraMoveToTarget(Camera *camera, float delta);
|
||||||
|
|
||||||
|
// Camera rotation
|
||||||
|
RLAPI void CameraYaw(Camera *camera, float angle, bool rotateAroundTarget);
|
||||||
|
RLAPI void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
|
||||||
|
RLAPI void CameraRoll(Camera *camera, float angle);
|
||||||
|
|
||||||
|
RLAPI Matrix GetCameraViewMatrix(Camera *camera);
|
||||||
|
RLAPI Matrix GetCameraProjectionMatrix(Camera *camera, float aspect);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // RCAMERA_H
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* CAMERA IMPLEMENTATION
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(RCAMERA_IMPLEMENTATION)
|
||||||
|
|
||||||
|
#include "raymath.h" // Required for vector maths:
|
||||||
|
// Vector3Add()
|
||||||
|
// Vector3Subtract()
|
||||||
|
// Vector3Scale()
|
||||||
|
// Vector3Normalize()
|
||||||
|
// Vector3Distance()
|
||||||
|
// Vector3CrossProduct()
|
||||||
|
// Vector3RotateByAxisAngle()
|
||||||
|
// Vector3Angle()
|
||||||
|
// Vector3Negate()
|
||||||
|
// MatrixLookAt()
|
||||||
|
// MatrixPerspective()
|
||||||
|
// MatrixOrtho()
|
||||||
|
// MatrixIdentity()
|
||||||
|
|
||||||
|
// raylib required functionality:
|
||||||
|
// GetMouseDelta()
|
||||||
|
// GetMouseWheelMove()
|
||||||
|
// IsKeyDown()
|
||||||
|
// IsKeyPressed()
|
||||||
|
// GetFrameTime()
|
||||||
|
|
||||||
|
#include <math.h> // Required for: fabsf()
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#define CAMERA_MOVE_SPEED 5.4f // Units per second
|
||||||
|
#define CAMERA_ROTATION_SPEED 0.03f
|
||||||
|
#define CAMERA_PAN_SPEED 2.0f
|
||||||
|
|
||||||
|
// Camera mouse movement sensitivity
|
||||||
|
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f
|
||||||
|
|
||||||
|
// Camera orbital speed in CAMERA_ORBITAL mode
|
||||||
|
#define CAMERA_ORBITAL_SPEED 0.5f // Radians per second
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Internal Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Returns the cameras forward vector (normalized)
|
||||||
|
Vector3 GetCameraForward(Camera *camera)
|
||||||
|
{
|
||||||
|
return Vector3Normalize(Vector3Subtract(camera->target, camera->position));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the cameras up vector (normalized)
|
||||||
|
// Note: The up vector might not be perpendicular to the forward vector
|
||||||
|
Vector3 GetCameraUp(Camera *camera)
|
||||||
|
{
|
||||||
|
return Vector3Normalize(camera->up);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the cameras right vector (normalized)
|
||||||
|
Vector3 GetCameraRight(Camera *camera)
|
||||||
|
{
|
||||||
|
Vector3 forward = GetCameraForward(camera);
|
||||||
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
|
||||||
|
return Vector3Normalize(Vector3CrossProduct(forward, up));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moves the camera in its forward direction
|
||||||
|
void CameraMoveForward(Camera *camera, float distance, bool moveInWorldPlane)
|
||||||
|
{
|
||||||
|
Vector3 forward = GetCameraForward(camera);
|
||||||
|
|
||||||
|
if (moveInWorldPlane)
|
||||||
|
{
|
||||||
|
// Project vector onto world plane (the plane defined by the up vector)
|
||||||
|
if (fabsf(camera->up.z) > 0.7071f) forward.z = 0;
|
||||||
|
else if (fabsf(camera->up.x) > 0.7071f) forward.x = 0;
|
||||||
|
else forward.y = 0;
|
||||||
|
|
||||||
|
forward = Vector3Normalize(forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale by distance
|
||||||
|
forward = Vector3Scale(forward, distance);
|
||||||
|
|
||||||
|
// Move position and target
|
||||||
|
camera->position = Vector3Add(camera->position, forward);
|
||||||
|
camera->target = Vector3Add(camera->target, forward);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moves the camera in its up direction
|
||||||
|
void CameraMoveUp(Camera *camera, float distance)
|
||||||
|
{
|
||||||
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
|
||||||
|
// Scale by distance
|
||||||
|
up = Vector3Scale(up, distance);
|
||||||
|
|
||||||
|
// Move position and target
|
||||||
|
camera->position = Vector3Add(camera->position, up);
|
||||||
|
camera->target = Vector3Add(camera->target, up);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moves the camera target in its current right direction
|
||||||
|
void CameraMoveRight(Camera *camera, float distance, bool moveInWorldPlane)
|
||||||
|
{
|
||||||
|
Vector3 right = GetCameraRight(camera);
|
||||||
|
|
||||||
|
if (moveInWorldPlane)
|
||||||
|
{
|
||||||
|
// Project vector onto world plane (the plane defined by the up vector)
|
||||||
|
if (fabsf(camera->up.z) > 0.7071f) right.z = 0;
|
||||||
|
else if (fabsf(camera->up.x) > 0.7071f) right.x = 0;
|
||||||
|
else right.y = 0;
|
||||||
|
|
||||||
|
right = Vector3Normalize(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale by distance
|
||||||
|
right = Vector3Scale(right, distance);
|
||||||
|
|
||||||
|
// Move position and target
|
||||||
|
camera->position = Vector3Add(camera->position, right);
|
||||||
|
camera->target = Vector3Add(camera->target, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moves the camera position closer/farther to/from the camera target
|
||||||
|
void CameraMoveToTarget(Camera *camera, float delta)
|
||||||
|
{
|
||||||
|
float distance = Vector3Distance(camera->position, camera->target);
|
||||||
|
|
||||||
|
// Apply delta
|
||||||
|
distance += delta;
|
||||||
|
|
||||||
|
// Distance must be greater than 0
|
||||||
|
if (distance <= 0) distance = 0.001f;
|
||||||
|
|
||||||
|
// Set new distance by moving the position along the forward vector
|
||||||
|
Vector3 forward = GetCameraForward(camera);
|
||||||
|
camera->position = Vector3Add(camera->target, Vector3Scale(forward, -distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotates the camera around its up vector
|
||||||
|
// Yaw is "looking left and right"
|
||||||
|
// If rotateAroundTarget is false, the camera rotates around its position
|
||||||
|
// Note: angle must be provided in radians
|
||||||
|
void CameraYaw(Camera *camera, float angle, bool rotateAroundTarget)
|
||||||
|
{
|
||||||
|
// Rotation axis
|
||||||
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
|
||||||
|
// View vector
|
||||||
|
Vector3 targetPosition = Vector3Subtract(camera->target, camera->position);
|
||||||
|
|
||||||
|
// Rotate view vector around up axis
|
||||||
|
targetPosition = Vector3RotateByAxisAngle(targetPosition, up, angle);
|
||||||
|
|
||||||
|
if (rotateAroundTarget)
|
||||||
|
{
|
||||||
|
// Move position relative to target
|
||||||
|
camera->position = Vector3Subtract(camera->target, targetPosition);
|
||||||
|
}
|
||||||
|
else // rotate around camera.position
|
||||||
|
{
|
||||||
|
// Move target relative to position
|
||||||
|
camera->target = Vector3Add(camera->position, targetPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotates the camera around its right vector, pitch is "looking up and down"
|
||||||
|
// - lockView prevents camera overrotation (aka "somersaults")
|
||||||
|
// - rotateAroundTarget defines if rotation is around target or around its position
|
||||||
|
// - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
|
||||||
|
// NOTE: [angle] must be provided in radians
|
||||||
|
void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp)
|
||||||
|
{
|
||||||
|
// Up direction
|
||||||
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
|
||||||
|
// View vector
|
||||||
|
Vector3 targetPosition = Vector3Subtract(camera->target, camera->position);
|
||||||
|
|
||||||
|
if (lockView)
|
||||||
|
{
|
||||||
|
// In these camera modes we clamp the Pitch angle
|
||||||
|
// to allow only viewing straight up or down.
|
||||||
|
|
||||||
|
// Clamp view up
|
||||||
|
float maxAngleUp = Vector3Angle(up, targetPosition);
|
||||||
|
maxAngleUp -= 0.001f; // avoid numerical errors
|
||||||
|
if (angle > maxAngleUp) angle = maxAngleUp;
|
||||||
|
|
||||||
|
// Clamp view down
|
||||||
|
float maxAngleDown = Vector3Angle(Vector3Negate(up), targetPosition);
|
||||||
|
maxAngleDown *= -1.0f; // downwards angle is negative
|
||||||
|
maxAngleDown += 0.001f; // avoid numerical errors
|
||||||
|
if (angle < maxAngleDown) angle = maxAngleDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotation axis
|
||||||
|
Vector3 right = GetCameraRight(camera);
|
||||||
|
|
||||||
|
// Rotate view vector around right axis
|
||||||
|
targetPosition = Vector3RotateByAxisAngle(targetPosition, right, angle);
|
||||||
|
|
||||||
|
if (rotateAroundTarget)
|
||||||
|
{
|
||||||
|
// Move position relative to target
|
||||||
|
camera->position = Vector3Subtract(camera->target, targetPosition);
|
||||||
|
}
|
||||||
|
else // Rotate around camera.position
|
||||||
|
{
|
||||||
|
// Move target relative to position
|
||||||
|
camera->target = Vector3Add(camera->position, targetPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotateUp)
|
||||||
|
{
|
||||||
|
// Rotate up direction around right axis
|
||||||
|
camera->up = Vector3RotateByAxisAngle(camera->up, right, angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotates the camera around its forward vector
|
||||||
|
// Roll is "turning your head sideways to the left or right"
|
||||||
|
// Note: angle must be provided in radians
|
||||||
|
void CameraRoll(Camera *camera, float angle)
|
||||||
|
{
|
||||||
|
// Rotation axis
|
||||||
|
Vector3 forward = GetCameraForward(camera);
|
||||||
|
|
||||||
|
// Rotate up direction around forward axis
|
||||||
|
camera->up = Vector3RotateByAxisAngle(camera->up, forward, angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the camera view matrix
|
||||||
|
Matrix GetCameraViewMatrix(Camera *camera)
|
||||||
|
{
|
||||||
|
return MatrixLookAt(camera->position, camera->target, camera->up);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the camera projection matrix
|
||||||
|
Matrix GetCameraProjectionMatrix(Camera *camera, float aspect)
|
||||||
|
{
|
||||||
|
if (camera->projection == CAMERA_PERSPECTIVE)
|
||||||
|
{
|
||||||
|
return MatrixPerspective(camera->fovy*DEG2RAD, aspect, CAMERA_CULL_DISTANCE_NEAR, CAMERA_CULL_DISTANCE_FAR);
|
||||||
|
}
|
||||||
|
else if (camera->projection == CAMERA_ORTHOGRAPHIC)
|
||||||
|
{
|
||||||
|
double top = camera->fovy/2.0;
|
||||||
|
double right = top*aspect;
|
||||||
|
|
||||||
|
return MatrixOrtho(-right, right, -top, top, CAMERA_CULL_DISTANCE_NEAR, CAMERA_CULL_DISTANCE_FAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MatrixIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(RCAMERA_STANDALONE)
|
||||||
|
// Update camera position for selected mode
|
||||||
|
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
|
||||||
|
void UpdateCamera(Camera *camera, int mode)
|
||||||
|
{
|
||||||
|
Vector2 mousePositionDelta = GetMouseDelta();
|
||||||
|
|
||||||
|
bool moveInWorldPlane = ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON));
|
||||||
|
bool rotateAroundTarget = ((mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||||
|
bool lockView = ((mode == CAMERA_FREE) || (mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||||
|
bool rotateUp = false;
|
||||||
|
|
||||||
|
// Camera speeds based on frame time
|
||||||
|
float cameraMoveSpeed = CAMERA_MOVE_SPEED*GetFrameTime();
|
||||||
|
float cameraRotationSpeed = CAMERA_ROTATION_SPEED*GetFrameTime();
|
||||||
|
float cameraPanSpeed = CAMERA_PAN_SPEED*GetFrameTime();
|
||||||
|
float cameraOrbitalSpeed = CAMERA_ORBITAL_SPEED*GetFrameTime();
|
||||||
|
|
||||||
|
if (mode == CAMERA_CUSTOM) {}
|
||||||
|
else if (mode == CAMERA_ORBITAL)
|
||||||
|
{
|
||||||
|
// Orbital can just orbit
|
||||||
|
Matrix rotation = MatrixRotate(GetCameraUp(camera), cameraOrbitalSpeed);
|
||||||
|
Vector3 view = Vector3Subtract(camera->position, camera->target);
|
||||||
|
view = Vector3Transform(view, rotation);
|
||||||
|
camera->position = Vector3Add(camera->target, view);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Camera rotation
|
||||||
|
if (IsKeyDown(KEY_DOWN)) CameraPitch(camera, -cameraRotationSpeed, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
if (IsKeyDown(KEY_UP)) CameraPitch(camera, cameraRotationSpeed, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
if (IsKeyDown(KEY_RIGHT)) CameraYaw(camera, -cameraRotationSpeed, rotateAroundTarget);
|
||||||
|
if (IsKeyDown(KEY_LEFT)) CameraYaw(camera, cameraRotationSpeed, rotateAroundTarget);
|
||||||
|
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -cameraRotationSpeed);
|
||||||
|
if (IsKeyDown(KEY_E)) CameraRoll(camera, cameraRotationSpeed);
|
||||||
|
|
||||||
|
// Camera movement
|
||||||
|
// Camera pan (for CAMERA_FREE)
|
||||||
|
if ((mode == CAMERA_FREE) && (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)))
|
||||||
|
{
|
||||||
|
const Vector2 mouseDelta = GetMouseDelta();
|
||||||
|
if (mouseDelta.x > 0.0f) CameraMoveRight(camera, cameraPanSpeed, moveInWorldPlane);
|
||||||
|
if (mouseDelta.x < 0.0f) CameraMoveRight(camera, -cameraPanSpeed, moveInWorldPlane);
|
||||||
|
if (mouseDelta.y > 0.0f) CameraMoveUp(camera, -cameraPanSpeed);
|
||||||
|
if (mouseDelta.y < 0.0f) CameraMoveUp(camera, cameraPanSpeed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Mouse support
|
||||||
|
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||||
|
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard support
|
||||||
|
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
|
||||||
|
// Gamepad movement
|
||||||
|
if (IsGamepadAvailable(0))
|
||||||
|
{
|
||||||
|
// Gamepad controller support
|
||||||
|
CameraYaw(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*2)*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||||
|
CameraPitch(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*2)*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
|
||||||
|
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) <= -0.25f) CameraMoveForward(camera, cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) <= -0.25f) CameraMoveRight(camera, -cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) >= 0.25f) CameraMoveForward(camera, -cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) >= 0.25f) CameraMoveRight(camera, cameraMoveSpeed, moveInWorldPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == CAMERA_FREE)
|
||||||
|
{
|
||||||
|
if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, cameraMoveSpeed);
|
||||||
|
if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -cameraMoveSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL) || (mode == CAMERA_FREE))
|
||||||
|
{
|
||||||
|
// Zoom target distance
|
||||||
|
CameraMoveToTarget(camera, -GetMouseWheelMove());
|
||||||
|
if (IsKeyPressed(KEY_KP_SUBTRACT)) CameraMoveToTarget(camera, 2.0f);
|
||||||
|
if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // !RCAMERA_STANDALONE
|
||||||
|
|
||||||
|
// Update camera movement, movement/rotation values should be provided by user
|
||||||
|
void UpdateCameraPro(Camera *camera, Vector3 movement, 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 rotateAroundTarget = false;
|
||||||
|
bool rotateUp = false;
|
||||||
|
bool moveInWorldPlane = true;
|
||||||
|
|
||||||
|
// Camera rotation
|
||||||
|
CameraPitch(camera, -rotation.y*DEG2RAD, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
CameraYaw(camera, -rotation.x*DEG2RAD, rotateAroundTarget);
|
||||||
|
CameraRoll(camera, rotation.z*DEG2RAD);
|
||||||
|
|
||||||
|
// Camera movement
|
||||||
|
CameraMoveForward(camera, movement.x, moveInWorldPlane);
|
||||||
|
CameraMoveRight(camera, movement.y, moveInWorldPlane);
|
||||||
|
CameraMoveUp(camera, movement.z);
|
||||||
|
|
||||||
|
// Zoom target distance
|
||||||
|
CameraMoveToTarget(camera, zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // RCAMERA_IMPLEMENTATION
|
||||||
555
raylib/include/rgestures.h
Normal file
555
raylib/include/rgestures.h
Normal file
@@ -0,0 +1,555 @@
|
|||||||
|
/**********************************************************************************************
|
||||||
|
*
|
||||||
|
* rgestures - Gestures system, gestures processing based on input events (touch/mouse)
|
||||||
|
*
|
||||||
|
* CONFIGURATION:
|
||||||
|
* #define RGESTURES_IMPLEMENTATION
|
||||||
|
* Generates the implementation of the library into the included file.
|
||||||
|
* If not defined, the library is in header only mode and can be included in other headers
|
||||||
|
* or source files without problems. But only ONE file should hold the implementation.
|
||||||
|
*
|
||||||
|
* #define RGESTURES_STANDALONE
|
||||||
|
* If defined, the library can be used as standalone to process gesture events with
|
||||||
|
* no external dependencies.
|
||||||
|
*
|
||||||
|
* CONTRIBUTORS:
|
||||||
|
* Marc Palau: Initial implementation (2014)
|
||||||
|
* Albert Martos: Complete redesign and testing (2015)
|
||||||
|
* Ian Eito: Complete redesign and testing (2015)
|
||||||
|
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2026 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* 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 RGESTURES_H
|
||||||
|
#define RGESTURES_H
|
||||||
|
|
||||||
|
#ifndef PI
|
||||||
|
#define PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#ifndef MAX_TOUCH_POINTS
|
||||||
|
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
// NOTE: Below types are required for standalone usage
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Boolean type
|
||||||
|
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||||
|
#include <stdbool.h>
|
||||||
|
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
||||||
|
typedef enum bool { false = 0, true = !false } bool;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(RL_VECTOR2_TYPE)
|
||||||
|
// Vector2 type
|
||||||
|
typedef struct Vector2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
} Vector2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(RGESTURES_STANDALONE)
|
||||||
|
// Gestures type
|
||||||
|
// NOTE: It could be used as flags to enable only some gestures
|
||||||
|
typedef enum {
|
||||||
|
GESTURE_NONE = 0,
|
||||||
|
GESTURE_TAP = 1,
|
||||||
|
GESTURE_DOUBLETAP = 2,
|
||||||
|
GESTURE_HOLD = 4,
|
||||||
|
GESTURE_DRAG = 8,
|
||||||
|
GESTURE_SWIPE_RIGHT = 16,
|
||||||
|
GESTURE_SWIPE_LEFT = 32,
|
||||||
|
GESTURE_SWIPE_UP = 64,
|
||||||
|
GESTURE_SWIPE_DOWN = 128,
|
||||||
|
GESTURE_PINCH_IN = 256,
|
||||||
|
GESTURE_PINCH_OUT = 512
|
||||||
|
} Gesture;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TOUCH_ACTION_UP = 0,
|
||||||
|
TOUCH_ACTION_DOWN,
|
||||||
|
TOUCH_ACTION_MOVE,
|
||||||
|
TOUCH_ACTION_CANCEL
|
||||||
|
} TouchAction;
|
||||||
|
|
||||||
|
// Gesture event
|
||||||
|
typedef struct {
|
||||||
|
int touchAction;
|
||||||
|
int pointCount;
|
||||||
|
int pointId[MAX_TOUCH_POINTS];
|
||||||
|
Vector2 position[MAX_TOUCH_POINTS];
|
||||||
|
} GestureEvent;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
|
||||||
|
void UpdateGestures(void); // Update gestures detected (must be called every frame)
|
||||||
|
|
||||||
|
#if defined(RGESTURES_STANDALONE)
|
||||||
|
void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
|
||||||
|
bool IsGestureDetected(int gesture); // Check if a gesture have been detected
|
||||||
|
int GetGestureDetected(void); // Get latest detected gesture
|
||||||
|
|
||||||
|
float GetGestureHoldDuration(void); // Get gesture hold time in seconds
|
||||||
|
Vector2 GetGestureDragVector(void); // Get gesture drag vector
|
||||||
|
float GetGestureDragAngle(void); // Get gesture drag angle
|
||||||
|
Vector2 GetGesturePinchVector(void); // Get gesture pinch delta
|
||||||
|
float GetGesturePinchAngle(void); // Get gesture pinch angle
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // RGESTURES_H
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* RGESTURES IMPLEMENTATION
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(RGESTURES_IMPLEMENTATION)
|
||||||
|
|
||||||
|
#if defined(RGESTURES_STANDALONE)
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
// Functions required to query time on Windows
|
||||||
|
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||||
|
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#elif defined(__linux__)
|
||||||
|
#if _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
|
||||||
|
#include <sys/time.h> // Required for: timespec
|
||||||
|
#include <time.h> // Required for: clock_gettime()
|
||||||
|
|
||||||
|
#include <math.h> // Required for: sqrtf(), atan2f()
|
||||||
|
#endif
|
||||||
|
#if defined(__APPLE__) // macOS also defines __MACH__
|
||||||
|
#include <mach/clock.h> // Required for: clock_get_time()
|
||||||
|
#include <mach/mach.h> // Required for: mach_timespec_t
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#define 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 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 TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds
|
||||||
|
#define 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)
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Gestures module state context [136 bytes]
|
||||||
|
typedef struct {
|
||||||
|
unsigned int current; // Current detected gesture
|
||||||
|
unsigned int enabledFlags; // Enabled gestures flags
|
||||||
|
struct {
|
||||||
|
int firstId; // Touch id for first touch point
|
||||||
|
int pointCount; // Touch points counter
|
||||||
|
double eventTime; // Time stamp when an event happened
|
||||||
|
Vector2 upPosition; // Touch up position
|
||||||
|
Vector2 downPositionA; // First touch down position
|
||||||
|
Vector2 downPositionB; // Second touch down position
|
||||||
|
Vector2 downDragPosition; // Touch drag position
|
||||||
|
Vector2 moveDownPositionA; // First touch down position on move
|
||||||
|
Vector2 moveDownPositionB; // Second touch down position on move
|
||||||
|
Vector2 previousPositionA; // Previous position A to compare for pinch gestures
|
||||||
|
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)
|
||||||
|
} Touch;
|
||||||
|
struct {
|
||||||
|
bool resetRequired; // HOLD reset to get first touch point again
|
||||||
|
double timeDuration; // HOLD duration in seconds
|
||||||
|
} Hold;
|
||||||
|
struct {
|
||||||
|
Vector2 vector; // DRAG vector (between initial and current position)
|
||||||
|
float angle; // DRAG angle (relative to x-axis)
|
||||||
|
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)
|
||||||
|
} Drag;
|
||||||
|
struct {
|
||||||
|
double startTime; // SWIPE start time to calculate drag intensity
|
||||||
|
} Swipe;
|
||||||
|
struct {
|
||||||
|
Vector2 vector; // PINCH vector (between first and second touch points)
|
||||||
|
float angle; // PINCH angle (relative to x-axis)
|
||||||
|
float distance; // PINCH displacement distance (normalized [0..1])
|
||||||
|
} Pinch;
|
||||||
|
} GesturesData;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static GesturesData GESTURES = {
|
||||||
|
.current = GESTURE_NONE, // No current gesture detected
|
||||||
|
.Touch.firstId = -1,
|
||||||
|
.enabledFlags = 0b0000001111111111 // All gestures supported by default
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Internal Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static float rgVector2Angle(Vector2 initialPosition, Vector2 finalPosition);
|
||||||
|
static float rgVector2Distance(Vector2 v1, Vector2 v2);
|
||||||
|
static double rgGetCurrentTime(void);
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Enable only desired gestures to be detected
|
||||||
|
void SetGesturesEnabled(unsigned int flags)
|
||||||
|
{
|
||||||
|
GESTURES.enabledFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a gesture have been detected
|
||||||
|
bool IsGestureDetected(unsigned int gesture)
|
||||||
|
{
|
||||||
|
if ((GESTURES.enabledFlags & GESTURES.current) == gesture) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process gesture event and translate it into gestures
|
||||||
|
void ProcessGestureEvent(GestureEvent event)
|
||||||
|
{
|
||||||
|
// Reset required variables
|
||||||
|
GESTURES.Touch.pointCount = event.pointCount; // Required on UpdateGestures()
|
||||||
|
|
||||||
|
if (GESTURES.Touch.pointCount == 1) // One touch point
|
||||||
|
{
|
||||||
|
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||||
|
{
|
||||||
|
GESTURES.Touch.tapCounter++; // Tap counter
|
||||||
|
|
||||||
|
// Detect GESTURE_DOUBLE_TAP
|
||||||
|
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((rgGetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (rgVector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
|
||||||
|
{
|
||||||
|
GESTURES.current = GESTURE_DOUBLETAP;
|
||||||
|
GESTURES.Touch.tapCounter = 0;
|
||||||
|
}
|
||||||
|
else // Detect GESTURE_TAP
|
||||||
|
{
|
||||||
|
GESTURES.Touch.tapCounter = 1;
|
||||||
|
GESTURES.current = GESTURE_TAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
GESTURES.Touch.downPositionA = event.position[0];
|
||||||
|
GESTURES.Touch.downDragPosition = event.position[0];
|
||||||
|
|
||||||
|
GESTURES.Touch.upPosition = GESTURES.Touch.downPositionA;
|
||||||
|
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||||
|
|
||||||
|
GESTURES.Swipe.startTime = rgGetCurrentTime();
|
||||||
|
|
||||||
|
GESTURES.Drag.vector = (Vector2){ 0.0f, 0.0f };
|
||||||
|
}
|
||||||
|
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
|
||||||
|
if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0];
|
||||||
|
|
||||||
|
// NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen
|
||||||
|
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||||
|
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.startTime));
|
||||||
|
|
||||||
|
// Detect GESTURE_SWIPE
|
||||||
|
if ((GESTURES.Drag.intensity > FORCE_TO_SWIPE) && (GESTURES.current != GESTURE_DRAG))
|
||||||
|
{
|
||||||
|
// NOTE: Angle should be inverted in Y
|
||||||
|
GESTURES.Drag.angle = 360.0f - rgVector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||||
|
|
||||||
|
if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right
|
||||||
|
else if ((GESTURES.Drag.angle >= 30) && (GESTURES.Drag.angle <= 150)) GESTURES.current = GESTURE_SWIPE_UP; // Up
|
||||||
|
else if ((GESTURES.Drag.angle > 150) && (GESTURES.Drag.angle < 210)) 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
|
||||||
|
{
|
||||||
|
GESTURES.Drag.distance = 0.0f;
|
||||||
|
GESTURES.Drag.intensity = 0.0f;
|
||||||
|
GESTURES.Drag.angle = 0.0f;
|
||||||
|
|
||||||
|
GESTURES.current = GESTURE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GESTURES.Touch.downDragPosition = (Vector2){ 0.0f, 0.0f };
|
||||||
|
GESTURES.Touch.pointCount = 0;
|
||||||
|
}
|
||||||
|
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||||
|
{
|
||||||
|
GESTURES.Touch.moveDownPositionA = event.position[0];
|
||||||
|
|
||||||
|
if (GESTURES.current == GESTURE_HOLD)
|
||||||
|
{
|
||||||
|
if (GESTURES.Hold.resetRequired) GESTURES.Touch.downPositionA = event.position[0];
|
||||||
|
|
||||||
|
GESTURES.Hold.resetRequired = false;
|
||||||
|
|
||||||
|
// Detect GESTURE_DRAG
|
||||||
|
if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > DRAG_TIMEOUT)
|
||||||
|
{
|
||||||
|
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||||
|
GESTURES.current = GESTURE_DRAG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GESTURES.Drag.vector.x = GESTURES.Touch.moveDownPositionA.x - GESTURES.Touch.downDragPosition.x;
|
||||||
|
GESTURES.Drag.vector.y = GESTURES.Touch.moveDownPositionA.y - GESTURES.Touch.downDragPosition.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (GESTURES.Touch.pointCount == 2) // Two touch points
|
||||||
|
{
|
||||||
|
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||||
|
{
|
||||||
|
GESTURES.Touch.downPositionA = event.position[0];
|
||||||
|
GESTURES.Touch.downPositionB = event.position[1];
|
||||||
|
|
||||||
|
GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA;
|
||||||
|
GESTURES.Touch.previousPositionB = GESTURES.Touch.downPositionB;
|
||||||
|
|
||||||
|
//GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
|
||||||
|
|
||||||
|
GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x;
|
||||||
|
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
|
||||||
|
|
||||||
|
GESTURES.current = GESTURE_HOLD;
|
||||||
|
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||||
|
}
|
||||||
|
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||||
|
{
|
||||||
|
GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||||
|
|
||||||
|
GESTURES.Touch.moveDownPositionA = event.position[0];
|
||||||
|
GESTURES.Touch.moveDownPositionB = event.position[1];
|
||||||
|
|
||||||
|
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
|
||||||
|
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
|
||||||
|
|
||||||
|
if ((rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
|
||||||
|
{
|
||||||
|
if ( rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB) > rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) ) GESTURES.current = GESTURE_PINCH_IN;
|
||||||
|
else GESTURES.current = GESTURE_PINCH_OUT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GESTURES.current = GESTURE_HOLD;
|
||||||
|
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Angle should be inverted in Y
|
||||||
|
GESTURES.Pinch.angle = 360.0f - rgVector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||||
|
}
|
||||||
|
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||||
|
{
|
||||||
|
GESTURES.Pinch.distance = 0.0f;
|
||||||
|
GESTURES.Pinch.angle = 0.0f;
|
||||||
|
GESTURES.Pinch.vector = (Vector2){ 0.0f, 0.0f };
|
||||||
|
GESTURES.Touch.pointCount = 0;
|
||||||
|
|
||||||
|
GESTURES.current = GESTURE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (GESTURES.Touch.pointCount > 2) // More than two touch points
|
||||||
|
{
|
||||||
|
// TODO: Process gesture events for more than two points
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update gestures detected (must be called every frame)
|
||||||
|
void UpdateGestures(void)
|
||||||
|
{
|
||||||
|
// NOTE: Gestures are processed through system callbacks on touch events
|
||||||
|
|
||||||
|
// Detect GESTURE_HOLD
|
||||||
|
if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) && (GESTURES.Touch.pointCount < 2))
|
||||||
|
{
|
||||||
|
GESTURES.current = GESTURE_HOLD;
|
||||||
|
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect GESTURE_NONE
|
||||||
|
if ((GESTURES.current == GESTURE_SWIPE_RIGHT) || (GESTURES.current == GESTURE_SWIPE_UP) || (GESTURES.current == GESTURE_SWIPE_LEFT) || (GESTURES.current == GESTURE_SWIPE_DOWN))
|
||||||
|
{
|
||||||
|
GESTURES.current = GESTURE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get latest detected gesture
|
||||||
|
int GetGestureDetected(void)
|
||||||
|
{
|
||||||
|
// Get current gesture only if enabled
|
||||||
|
return (GESTURES.enabledFlags & GESTURES.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hold time measured in seconds
|
||||||
|
float GetGestureHoldDuration(void)
|
||||||
|
{
|
||||||
|
// NOTE: time is calculated on current gesture HOLD
|
||||||
|
|
||||||
|
double time = 0.0;
|
||||||
|
|
||||||
|
if (GESTURES.current == GESTURE_HOLD) time = rgGetCurrentTime() - GESTURES.Hold.timeDuration;
|
||||||
|
|
||||||
|
return (float)time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get drag vector (between initial touch point to current)
|
||||||
|
Vector2 GetGestureDragVector(void)
|
||||||
|
{
|
||||||
|
// NOTE: drag vector is calculated on one touch points TOUCH_ACTION_MOVE
|
||||||
|
|
||||||
|
return GESTURES.Drag.vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get drag angle
|
||||||
|
// NOTE: Angle in degrees, horizontal-right is 0, counterclockwise
|
||||||
|
float GetGestureDragAngle(void)
|
||||||
|
{
|
||||||
|
// NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP
|
||||||
|
|
||||||
|
return GESTURES.Drag.angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get distance between two pinch points
|
||||||
|
Vector2 GetGesturePinchVector(void)
|
||||||
|
{
|
||||||
|
// NOTE: Pinch distance is calculated on two touch points TOUCH_ACTION_MOVE
|
||||||
|
|
||||||
|
return GESTURES.Pinch.vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get angle between two pinch points
|
||||||
|
// NOTE: Angle in degrees, horizontal-right is 0, counterclockwise
|
||||||
|
float GetGesturePinchAngle(void)
|
||||||
|
{
|
||||||
|
// NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE
|
||||||
|
|
||||||
|
return GESTURES.Pinch.angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Internal Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Get angle from two-points vector with X-axis
|
||||||
|
static float rgVector2Angle(Vector2 v1, Vector2 v2)
|
||||||
|
{
|
||||||
|
float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
|
||||||
|
|
||||||
|
if (angle < 0) angle += 360.0f;
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate distance between two Vector2
|
||||||
|
static float rgVector2Distance(Vector2 v1, Vector2 v2)
|
||||||
|
{
|
||||||
|
float result;
|
||||||
|
|
||||||
|
float dx = v2.x - v1.x;
|
||||||
|
float dy = v2.y - v1.y;
|
||||||
|
|
||||||
|
result = (float)sqrt(dx*dx + dy*dy);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time measure returned are seconds
|
||||||
|
static double rgGetCurrentTime(void)
|
||||||
|
{
|
||||||
|
double time = 0;
|
||||||
|
|
||||||
|
#if !defined(RGESTURES_STANDALONE)
|
||||||
|
time = GetTime();
|
||||||
|
#else
|
||||||
|
#if defined(_WIN32)
|
||||||
|
unsigned long long int clockFrequency, currentTime;
|
||||||
|
|
||||||
|
QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
|
||||||
|
QueryPerformanceCounter(¤tTime);
|
||||||
|
|
||||||
|
time = (double)currentTime/clockFrequency; // Time in seconds
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
// NOTE: Only for Linux-based systems
|
||||||
|
struct timespec now;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
|
||||||
|
|
||||||
|
time = ((double)nowTime*1e-9); // Time in seconds
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
//#define CLOCK_REALTIME CALENDAR_CLOCK // returns UTC time since 1970-01-01
|
||||||
|
//#define CLOCK_MONOTONIC SYSTEM_CLOCK // returns the time since boot time
|
||||||
|
|
||||||
|
clock_serv_t cclock;
|
||||||
|
mach_timespec_t now;
|
||||||
|
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||||
|
|
||||||
|
// NOTE: OS X does not have clock_gettime(), using clock_get_time()
|
||||||
|
clock_get_time(cclock, &now);
|
||||||
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
|
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
|
||||||
|
|
||||||
|
time = ((double)nowTime*1e-9); // Time in seconds
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // RGESTURES_IMPLEMENTATION
|
||||||
5392
raylib/include/rlgl.h
Normal file
5392
raylib/include/rlgl.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
raylib/lib/x86_64-linux/libraylib.a
Normal file
BIN
raylib/lib/x86_64-linux/libraylib.a
Normal file
Binary file not shown.
Reference in New Issue
Block a user