WARNING: MODULES RENAMING!!!
raylib modules have been slightly renamed to add some identity and note that they are independent modules that can be used as standalone separate parts of raylib if required. The renamed modules are: - `core` -> `rcore` - `shapes` -> `rshapes` - `textures` -> `rtextures` - `text` -> `rtext` - `models` -> `rmodels` - `camera` -> `rcamera` - `gestures` -> `rgestures` - `core` -> `rcore` All the build systems has been adapted to this change.
This commit is contained in:
parent
8b3d054408
commit
99ab4d6cb8
20 changed files with 57 additions and 58 deletions
|
|
@ -27,9 +27,9 @@ endif()
|
||||||
option(INCLUDE_EVERYTHING "Include everything disabled by default (for CI usage" OFF)
|
option(INCLUDE_EVERYTHING "Include everything disabled by default (for CI usage" OFF)
|
||||||
set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \${OFF} to have it covered by this option")
|
set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \${OFF} to have it covered by this option")
|
||||||
|
|
||||||
# core.c
|
# rcore.c
|
||||||
cmake_dependent_option(SUPPORT_CAMERA_SYSTEM "Provide camera module (camera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_CAMERA_SYSTEM "Provide camera module (rcamera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_GESTURES_SYSTEM "Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_GESTURES_SYSTEM "Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches and processed by gestures system" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches and processed by gestures system" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_SSH_KEYBOARD_RPI "Reconfigure standard input to receive key inputs, works with SSH connection" OFF CUSTOMIZE_BUILD OFF)
|
cmake_dependent_option(SUPPORT_SSH_KEYBOARD_RPI "Reconfigure standard input to receive key inputs, works with SSH connection" OFF CUSTOMIZE_BUILD OFF)
|
||||||
cmake_dependent_option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
@ -41,10 +41,10 @@ cmake_dependent_option(SUPPORT_WINMM_HIGHRES_TIMER "Setting a higher resolution
|
||||||
cmake_dependent_option(SUPPORT_DATA_STORAGE "Support for persistent data storage" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_DATA_STORAGE "Support for persistent data storage" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_COMPRESSION_API "Support for compression API" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_COMPRESSION_API "Support for compression API" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
||||||
# shapes.c
|
# rshapes.c
|
||||||
cmake_dependent_option(SUPPORT_QUADS_DRAW_MODE "Use QUADS instead of TRIANGLES for drawing when possible. Some lines-based shapes could still use lines" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_QUADS_DRAW_MODE "Use QUADS instead of TRIANGLES for drawing when possible. Some lines-based shapes could still use lines" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
||||||
# textures.c
|
# rtextures.c
|
||||||
cmake_dependent_option(SUPPORT_IMAGE_EXPORT "Support image exporting to file" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_IMAGE_EXPORT "Support image exporting to file" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_IMAGE_GENERATION "Support procedural image generation functionality (gradient, spot, perlin-noise, cellular)" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_IMAGE_GENERATION "Support procedural image generation functionality (gradient, spot, perlin-noise, cellular)" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_IMAGE_MANIPULATION "Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop... If not defined only three image editing functions supported: ImageFormat(), ImageAlphaMask(), ImageToPOT()" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_IMAGE_MANIPULATION "Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop... If not defined only three image editing functions supported: ImageFormat(), ImageAlphaMask(), ImageToPOT()" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
@ -61,12 +61,12 @@ cmake_dependent_option(SUPPORT_FILEFORMAT_PSD "Support loading PSD as textures"
|
||||||
cmake_dependent_option(SUPPORT_FILEFORMAT_PKM "Support loading PKM as textures" ${OFF} CUSTOMIZE_BUILD OFF)
|
cmake_dependent_option(SUPPORT_FILEFORMAT_PKM "Support loading PKM as textures" ${OFF} CUSTOMIZE_BUILD OFF)
|
||||||
cmake_dependent_option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" ${OFF} CUSTOMIZE_BUILD OFF)
|
cmake_dependent_option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" ${OFF} CUSTOMIZE_BUILD OFF)
|
||||||
|
|
||||||
# text.c
|
# rtext.c
|
||||||
cmake_dependent_option(SUPPORT_FILEFORMAT_FNT "Support loading fonts in FNT format" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_FILEFORMAT_FNT "Support loading fonts in FNT format" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_FILEFORMAT_TTF "Support loading font in TTF/OTF format" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_FILEFORMAT_TTF "Support loading font in TTF/OTF format" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_TEXT_MANIPULATION "Support text manipulation functions" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_TEXT_MANIPULATION "Support text manipulation functions" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
||||||
# models.c
|
# rmodels.c
|
||||||
cmake_dependent_option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_FILEFORMAT_OBJ "Support loading OBJ file format" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_FILEFORMAT_OBJ "Support loading OBJ file format" ON CUSTOMIZE_BUILD ON)
|
||||||
cmake_dependent_option(SUPPORT_FILEFORMAT_MTL "Support loading MTL file format" ON CUSTOMIZE_BUILD ON)
|
cmake_dependent_option(SUPPORT_FILEFORMAT_MTL "Support loading MTL file format" ON CUSTOMIZE_BUILD ON)
|
||||||
|
|
|
||||||
10
HISTORY.md
10
HISTORY.md
|
|
@ -33,7 +33,7 @@ Lots of code changes and lot of testing have concluded in this amazing new rayli
|
||||||
notes on raylib 1.2
|
notes on raylib 1.2
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
On September 2014, after 5 month of raylib 1.1 release, it comes raylib 1.2. Again, this version presents a complete internal redesign of [core](https://github.com/raysan5/raylib/blob/master/src/core.c) module to support two new platforms: [Android](http://www.android.com/) and [Raspberry Pi](http://www.raspberrypi.org/).
|
On September 2014, after 5 month of raylib 1.1 release, it comes raylib 1.2. Again, this version presents a complete internal redesign of [core](https://github.com/raysan5/raylib/blob/master/src/rcore.c) module to support two new platforms: [Android](http://www.android.com/) and [Raspberry Pi](http://www.raspberrypi.org/).
|
||||||
|
|
||||||
It's been some month of really hard work to accomodate raylib to those new platforms while keeping it easy for the users. On Android, raylib manages internally the activity cicle, as well as the inputs; on Raspberry Pi, a complete raw input system has been written from scratch.
|
It's been some month of really hard work to accomodate raylib to those new platforms while keeping it easy for the users. On Android, raylib manages internally the activity cicle, as well as the inputs; on Raspberry Pi, a complete raw input system has been written from scratch.
|
||||||
|
|
||||||
|
|
@ -54,9 +54,9 @@ On September 2015, after 1 year of raylib 1.2 release, arrives raylib 1.3. This
|
||||||
|
|
||||||
- Textures module has grown to support most of the internal texture formats available in OpenGL (RGB565, RGB888, RGBA5551, RGBA4444, etc.), including compressed texture formats (DXT, ETC1, ETC2, ASTC, PVRT); raylib 1.3 can load .dds, .pkm, .ktx, .astc and .pvr files.
|
- Textures module has grown to support most of the internal texture formats available in OpenGL (RGB565, RGB888, RGBA5551, RGBA4444, etc.), including compressed texture formats (DXT, ETC1, ETC2, ASTC, PVRT); raylib 1.3 can load .dds, .pkm, .ktx, .astc and .pvr files.
|
||||||
|
|
||||||
- A brand new [camera](https://github.com/raysan5/raylib/blob/master/src/camera.c) module offers to the user multiple preconfigured ready-to-use camera systems (free camera, 1st person, 3rd person). Camera modes are very easy to use, just check examples: [core_3d_camera_free.c](https://github.com/raysan5/raylib/blob/master/examples/core_3d_camera_free.c) and [core_3d_camera_first_person.c](https://github.com/raysan5/raylib/blob/master/examples/core_3d_camera_first_person.c).
|
- A brand new [camera](https://github.com/raysan5/raylib/blob/master/src/rcamera.c) module offers to the user multiple preconfigured ready-to-use camera systems (free camera, 1st person, 3rd person). Camera modes are very easy to use, just check examples: [core_3d_camera_free.c](https://github.com/raysan5/raylib/blob/master/examples/core_3d_camera_free.c) and [core_3d_camera_first_person.c](https://github.com/raysan5/raylib/blob/master/examples/core_3d_camera_first_person.c).
|
||||||
|
|
||||||
- New [gestures](https://github.com/raysan5/raylib/blob/master/src/gestures.h) module simplifies gestures detection on Android and HTML5 programs.
|
- New [gestures](https://github.com/raysan5/raylib/blob/master/src/rgestures.h) module simplifies gestures detection on Android and HTML5 programs.
|
||||||
|
|
||||||
- [raygui](https://github.com/raysan5/raylib/blob/master/src/raygui.h), the new immediate-mode GUI module offers a set of functions to create simple user interfaces, primary intended for tools development. It's still in experimental state but already fully functional.
|
- [raygui](https://github.com/raysan5/raylib/blob/master/src/raygui.h), the new immediate-mode GUI module offers a set of functions to create simple user interfaces, primary intended for tools development. It's still in experimental state but already fully functional.
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ On February 2016, after 4 months of raylib 1.3 release, it comes raylib 1.4. For
|
||||||
|
|
||||||
- [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) module has been reviewed; some bugs have been solved and the module has been converted to a header-only file for easier portability, optionally, functions can also be used as inline.
|
- [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) module has been reviewed; some bugs have been solved and the module has been converted to a header-only file for easier portability, optionally, functions can also be used as inline.
|
||||||
|
|
||||||
- [gestures](https://github.com/raysan5/raylib/blob/master/src/gestures.c) module has redesigned and simplified, now it can process touch events from any source, including mouse. This way, gestures system can be used on any platform providing an unified way to work with inputs and allowing the user to create multiplatform games with only one source code.
|
- [gestures](https://github.com/raysan5/raylib/blob/master/src/rgestures.c) module has redesigned and simplified, now it can process touch events from any source, including mouse. This way, gestures system can be used on any platform providing an unified way to work with inputs and allowing the user to create multiplatform games with only one source code.
|
||||||
|
|
||||||
- Raspberry Pi input system has been redesigned to better read raw inputs using generic Linux event handlers (keyboard:`stdin`, mouse:`/dev/input/mouse0`, gamepad:`/dev/input/js0`). Gamepad support has also been added (experimental).
|
- Raspberry Pi input system has been redesigned to better read raw inputs using generic Linux event handlers (keyboard:`stdin`, mouse:`/dev/input/mouse0`, gamepad:`/dev/input/js0`). Gamepad support has also been added (experimental).
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ On July 2016, after 5 months of raylib 1.4 release, arrives raylib 1.5. This new
|
||||||
|
|
||||||
- Audio chiptunese support and mixing channels: Added support for module audio music (.xm, .mod) loading and playing. Multiple mixing channels are now also supported. All this features thanks to the amazing work of @kd7tck.
|
- Audio chiptunese support and mixing channels: Added support for module audio music (.xm, .mod) loading and playing. Multiple mixing channels are now also supported. All this features thanks to the amazing work of @kd7tck.
|
||||||
|
|
||||||
Other additions include a [2D camera system](https://github.com/raysan5/raylib/blob/master/examples/core_2d_camera.c), render textures for offline render (and most comprehensive [postprocessing](https://github.com/raysan5/raylib/blob/master/examples/shaders_postprocessing.c)) or support for legacy OpenGL 2.1 on desktop platforms.
|
Other additions include a [2D camera system](https://github.com/raysan5/raylib/blob/master/examples/core_2d_rcamera.c), render textures for offline render (and most comprehensive [postprocessing](https://github.com/raysan5/raylib/blob/master/examples/shaders_postprocessing.c)) or support for legacy OpenGL 2.1 on desktop platforms.
|
||||||
|
|
||||||
This new version is so massive that is difficult to list all the improvements, most of raylib modules have been reviewed and [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c) module has been completely redesigned to accomodate to new material-lighting systems and stereo rendering. You can check [CHANGELOG](https://github.com/raysan5/raylib/blob/master/CHANGELOG) file for a more detailed list of changes.
|
This new version is so massive that is difficult to list all the improvements, most of raylib modules have been reviewed and [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c) module has been completely redesigned to accomodate to new material-lighting systems and stereo rendering. You can check [CHANGELOG](https://github.com/raysan5/raylib/blob/master/CHANGELOG) file for a more detailed list of changes.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ cmd /c del /F libraylib.a
|
||||||
:: > Compile raylib modules
|
:: > Compile raylib modules
|
||||||
:: ------------------------------
|
:: ------------------------------
|
||||||
gcc -O2 -c rglfw.c -Wall -I. -Iexternal/glfw/include
|
gcc -O2 -c rglfw.c -Wall -I. -Iexternal/glfw/include
|
||||||
gcc -O2 -c core.c -std=c99 -Wall -Iexternal/glfw/include -DPLATFORM_DESKTOP -D%GRAPHICS_API%
|
gcc -O2 -c rcore.c -std=c99 -Wall -Iexternal/glfw/include -DPLATFORM_DESKTOP -D%GRAPHICS_API%
|
||||||
gcc -O2 -c shapes.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c rshapes.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c textures.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c rtextures.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c text.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c rtext.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c models.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c rmodels.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c raudio.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c raudio.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c utils.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c utils.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -303,16 +303,16 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\..\src\raudio.c" />
|
<ClCompile Include="..\..\..\src\raudio.c" />
|
||||||
<ClCompile Include="..\..\..\src\core.c" />
|
<ClCompile Include="..\..\..\src\rcore.c" />
|
||||||
<ClCompile Include="..\..\..\src\models.c" />
|
<ClCompile Include="..\..\..\src\rmodels.c" />
|
||||||
<ClCompile Include="..\..\..\src\rglfw.c" />
|
<ClCompile Include="..\..\..\src\rglfw.c" />
|
||||||
<ClCompile Include="..\..\..\src\shapes.c" />
|
<ClCompile Include="..\..\..\src\rshapes.c" />
|
||||||
<ClCompile Include="..\..\..\src\text.c" />
|
<ClCompile Include="..\..\..\src\rtext.c" />
|
||||||
<ClCompile Include="..\..\..\src\textures.c" />
|
<ClCompile Include="..\..\..\src\rtextures.c" />
|
||||||
<ClCompile Include="..\..\..\src\utils.c" />
|
<ClCompile Include="..\..\..\src\utils.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\src\camera.h" />
|
<ClInclude Include="..\..\..\src\rcamera.h" />
|
||||||
<ClInclude Include="..\..\..\src\config.h" />
|
<ClInclude Include="..\..\..\src\config.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\glad.h" />
|
<ClInclude Include="..\..\..\src\external\glad.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\jar_mod.h" />
|
<ClInclude Include="..\..\..\src\external\jar_mod.h" />
|
||||||
|
|
@ -324,7 +324,7 @@
|
||||||
<ClInclude Include="..\..\..\src\external\stb_rect_pack.h" />
|
<ClInclude Include="..\..\..\src\external\stb_rect_pack.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\stb_truetype.h" />
|
<ClInclude Include="..\..\..\src\external\stb_truetype.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\stb_vorbis.h" />
|
<ClInclude Include="..\..\..\src\external\stb_vorbis.h" />
|
||||||
<ClInclude Include="..\..\..\src\gestures.h" />
|
<ClInclude Include="..\..\..\src\rgestures.h" />
|
||||||
<ClInclude Include="..\..\..\src\raylib.h" />
|
<ClInclude Include="..\..\..\src\raylib.h" />
|
||||||
<ClInclude Include="..\..\..\src\raymath.h" />
|
<ClInclude Include="..\..\..\src\raymath.h" />
|
||||||
<ClInclude Include="..\..\..\src\rlgl.h" />
|
<ClInclude Include="..\..\..\src\rlgl.h" />
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ if [ ! -d "$TEMP_DIR" ]; then
|
||||||
mkdir -p $TEMP_DIR
|
mkdir -p $TEMP_DIR
|
||||||
cd $TEMP_DIR
|
cd $TEMP_DIR
|
||||||
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
|
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
|
||||||
RAYLIB_C_FILES="$RAYLIB_SRC/core.c $RAYLIB_SRC/shapes.c $RAYLIB_SRC/textures.c $RAYLIB_SRC/text.c $RAYLIB_SRC/models.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c $RAYLIB_SRC/rglfw.c"
|
RAYLIB_C_FILES="$RAYLIB_SRC/rcore.c $RAYLIB_SRC/rshapes.c $RAYLIB_SRC/rtextures.c $RAYLIB_SRC/rtext.c $RAYLIB_SRC/rmodels.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c $RAYLIB_SRC/rglfw.c"
|
||||||
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
|
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
|
||||||
|
|
||||||
if [ -n "$REALLY_QUIET" ]; then
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ if [ ! -d "$TEMP_DIR" ]; then
|
||||||
mkdir -p $TEMP_DIR
|
mkdir -p $TEMP_DIR
|
||||||
cd $TEMP_DIR
|
cd $TEMP_DIR
|
||||||
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
|
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
|
||||||
RAYLIB_C_FILES="$RAYLIB_SRC/core.c $RAYLIB_SRC/shapes.c $RAYLIB_SRC/textures.c $RAYLIB_SRC/text.c $RAYLIB_SRC/models.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c"
|
RAYLIB_C_FILES="$RAYLIB_SRC/rcore.c $RAYLIB_SRC/rshapes.c $RAYLIB_SRC/rtextures.c $RAYLIB_SRC/rtext.c $RAYLIB_SRC/rmodels.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c"
|
||||||
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
|
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
|
||||||
|
|
||||||
if [ -n "$REALLY_QUIET" ]; then
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ if [ ! -d "$TEMP_DIR" ]; then
|
||||||
mkdir -p $TEMP_DIR
|
mkdir -p $TEMP_DIR
|
||||||
cd $TEMP_DIR
|
cd $TEMP_DIR
|
||||||
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_RPI -DGRAPHICS_API_OPENGL_ES2"
|
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_RPI -DGRAPHICS_API_OPENGL_ES2"
|
||||||
RAYLIB_C_FILES="$RAYLIB_SRC/core.c $RAYLIB_SRC/shapes.c $RAYLIB_SRC/textures.c $RAYLIB_SRC/text.c $RAYLIB_SRC/models.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c"
|
RAYLIB_C_FILES="$RAYLIB_SRC/rcore.c $RAYLIB_SRC/rshapes.c $RAYLIB_SRC/rtextures.c $RAYLIB_SRC/rtext.c $RAYLIB_SRC/rmodels.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c"
|
||||||
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I/opt/vc/include"
|
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I/opt/vc/include"
|
||||||
|
|
||||||
if [ -n "$REALLY_QUIET" ]; then
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ IF NOT EXIST !TEMP_DIR!\ (
|
||||||
cd !TEMP_DIR!
|
cd !TEMP_DIR!
|
||||||
REM Raylib's src folder
|
REM Raylib's src folder
|
||||||
set "RAYLIB_DEFINES=/D_DEFAULT_SOURCE /DPLATFORM_DESKTOP /DGRAPHICS_API_OPENGL_33"
|
set "RAYLIB_DEFINES=/D_DEFAULT_SOURCE /DPLATFORM_DESKTOP /DGRAPHICS_API_OPENGL_33"
|
||||||
set RAYLIB_C_FILES="!RAYLIB_SRC!\core.c" "!RAYLIB_SRC!\shapes.c" "!RAYLIB_SRC!\textures.c" "!RAYLIB_SRC!\text.c" "!RAYLIB_SRC!\models.c" "!RAYLIB_SRC!\utils.c" "!RAYLIB_SRC!\raudio.c" "!RAYLIB_SRC!\rglfw.c"
|
set RAYLIB_C_FILES="!RAYLIB_SRC!\rcore.c" "!RAYLIB_SRC!\rshapes.c" "!RAYLIB_SRC!\rtextures.c" "!RAYLIB_SRC!\rtext.c" "!RAYLIB_SRC!\rmodels.c" "!RAYLIB_SRC!\utils.c" "!RAYLIB_SRC!\raudio.c" "!RAYLIB_SRC!\rglfw.c"
|
||||||
set RAYLIB_INCLUDE_FLAGS=/I"!RAYLIB_SRC!" /I"!RAYLIB_SRC!\external\glfw\include"
|
set RAYLIB_INCLUDE_FLAGS=/I"!RAYLIB_SRC!" /I"!RAYLIB_SRC!\external\glfw\include"
|
||||||
|
|
||||||
IF DEFINED REALLY_QUIET (
|
IF DEFINED REALLY_QUIET (
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ set(raylib_public_headers
|
||||||
|
|
||||||
# Sources to be compiled
|
# Sources to be compiled
|
||||||
set(raylib_sources
|
set(raylib_sources
|
||||||
core.c
|
rcore.c
|
||||||
models.c
|
rmodels.c
|
||||||
shapes.c
|
rshapes.c
|
||||||
text.c
|
rtext.c
|
||||||
textures.c
|
rtextures.c
|
||||||
utils.c
|
utils.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
10
src/Makefile
10
src/Makefile
|
|
@ -549,7 +549,7 @@ endif
|
||||||
# Compile all modules with their prerequisites
|
# Compile all modules with their prerequisites
|
||||||
|
|
||||||
# Compile core module
|
# Compile core module
|
||||||
core.o : core.c raylib.h rlgl.h utils.h raymath.h camera.h gestures.h
|
rcore.o : rcore.c raylib.h rlgl.h utils.h raymath.h rcamera.h rgestures.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
||||||
|
|
||||||
# Compile rglfw module
|
# Compile rglfw module
|
||||||
|
|
@ -557,15 +557,15 @@ rglfw.o : rglfw.c
|
||||||
$(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
$(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
||||||
|
|
||||||
# Compile shapes module
|
# Compile shapes module
|
||||||
shapes.o : shapes.c raylib.h rlgl.h
|
rshapes.o : rshapes.c raylib.h rlgl.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
||||||
|
|
||||||
# Compile textures module
|
# Compile textures module
|
||||||
textures.o : textures.c raylib.h rlgl.h utils.h
|
rtextures.o : rtextures.c raylib.h rlgl.h utils.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
||||||
|
|
||||||
# Compile text module
|
# Compile text module
|
||||||
text.o : text.c raylib.h utils.h
|
rtext.o : rtext.c raylib.h utils.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
||||||
|
|
||||||
# Compile utils module
|
# Compile utils module
|
||||||
|
|
@ -573,7 +573,7 @@ utils.o : utils.c utils.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
||||||
|
|
||||||
# Compile models module
|
# Compile models module
|
||||||
models.o : models.c raylib.h rlgl.h raymath.h
|
rmodels.o : rmodels.c raylib.h rlgl.h raymath.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
|
||||||
|
|
||||||
# Compile audio module
|
# Compile audio module
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Module: core - Configuration Flags
|
// Module: core - Configuration Flags
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Camera module is included (camera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
|
// Camera module is included (rcamera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
|
||||||
#define SUPPORT_CAMERA_SYSTEM 1
|
#define SUPPORT_CAMERA_SYSTEM 1
|
||||||
// Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag
|
// Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
|
||||||
#define SUPPORT_GESTURES_SYSTEM 1
|
#define SUPPORT_GESTURES_SYSTEM 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 SUPPORT_MOUSE_GESTURES 1
|
#define SUPPORT_MOUSE_GESTURES 1
|
||||||
|
|
|
||||||
526
src/rcamera.h
Normal file
526
src/rcamera.h
Normal file
|
|
@ -0,0 +1,526 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* rcamera - Basic camera system for multiple camera modes
|
||||||
|
*
|
||||||
|
* NOTE: Memory footprint of this library is aproximately 52 bytes (global variables)
|
||||||
|
*
|
||||||
|
* CONFIGURATION:
|
||||||
|
*
|
||||||
|
* #define CAMERA_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 CAMERA_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
|
||||||
|
* Marc Palau: Initial implementation (2014)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2021 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
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
// NOTE: Below types are required for CAMERA_STANDALONE usage
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#if defined(CAMERA_STANDALONE)
|
||||||
|
// Vector2 type
|
||||||
|
typedef struct Vector2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
} Vector2;
|
||||||
|
|
||||||
|
// Vector3 type
|
||||||
|
typedef struct Vector3 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
} Vector3;
|
||||||
|
|
||||||
|
// 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 type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||||
|
} Camera3D;
|
||||||
|
|
||||||
|
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
|
||||||
|
|
||||||
|
// Camera system modes
|
||||||
|
typedef enum {
|
||||||
|
CAMERA_CUSTOM = 0,
|
||||||
|
CAMERA_FREE,
|
||||||
|
CAMERA_ORBITAL,
|
||||||
|
CAMERA_FIRST_PERSON,
|
||||||
|
CAMERA_THIRD_PERSON
|
||||||
|
} CameraMode;
|
||||||
|
|
||||||
|
// Camera projection modes
|
||||||
|
typedef enum {
|
||||||
|
CAMERA_PERSPECTIVE = 0,
|
||||||
|
CAMERA_ORTHOGRAPHIC
|
||||||
|
} CameraProjection;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//...
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CAMERA_STANDALONE)
|
||||||
|
void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available)
|
||||||
|
void UpdateCamera(Camera *camera); // Update camera position for selected mode
|
||||||
|
|
||||||
|
void SetCameraPanControl(int keyPan); // Set camera pan key to combine with mouse movement (free camera)
|
||||||
|
void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera)
|
||||||
|
void SetCameraSmoothZoomControl(int szoomKey); // Set camera smooth zoom key to combine with mouse (free camera)
|
||||||
|
void SetCameraMoveControls(int keyFront, int keyBack,
|
||||||
|
int keyRight, int keyLeft,
|
||||||
|
int keyUp, int keyDown); // Set camera move controls (1st person and 3rd person cameras)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // CAMERA_H
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* CAMERA IMPLEMENTATION
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CAMERA_IMPLEMENTATION)
|
||||||
|
|
||||||
|
#include <math.h> // Required for: sinf(), cosf(), sqrtf()
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#ifndef PI
|
||||||
|
#define PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
#ifndef DEG2RAD
|
||||||
|
#define DEG2RAD (PI/180.0f)
|
||||||
|
#endif
|
||||||
|
#ifndef RAD2DEG
|
||||||
|
#define RAD2DEG (180.0f/PI)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Camera mouse movement sensitivity
|
||||||
|
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f
|
||||||
|
#define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
|
||||||
|
|
||||||
|
// FREE_CAMERA
|
||||||
|
#define CAMERA_FREE_MOUSE_SENSITIVITY 0.01f
|
||||||
|
#define CAMERA_FREE_DISTANCE_MIN_CLAMP 0.3f
|
||||||
|
#define CAMERA_FREE_DISTANCE_MAX_CLAMP 120.0f
|
||||||
|
#define CAMERA_FREE_MIN_CLAMP 85.0f
|
||||||
|
#define CAMERA_FREE_MAX_CLAMP -85.0f
|
||||||
|
#define CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY 0.05f
|
||||||
|
#define CAMERA_FREE_PANNING_DIVIDER 5.1f
|
||||||
|
|
||||||
|
// ORBITAL_CAMERA
|
||||||
|
#define CAMERA_ORBITAL_SPEED 0.01f // Radians per frame
|
||||||
|
|
||||||
|
// FIRST_PERSON
|
||||||
|
//#define CAMERA_FIRST_PERSON_MOUSE_SENSITIVITY 0.003f
|
||||||
|
#define CAMERA_FIRST_PERSON_FOCUS_DISTANCE 25.0f
|
||||||
|
#define CAMERA_FIRST_PERSON_MIN_CLAMP 89.0f
|
||||||
|
#define CAMERA_FIRST_PERSON_MAX_CLAMP -89.0f
|
||||||
|
|
||||||
|
#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f
|
||||||
|
#define CAMERA_FIRST_PERSON_STEP_DIVIDER 30.0f
|
||||||
|
#define CAMERA_FIRST_PERSON_WAVING_DIVIDER 200.0f
|
||||||
|
|
||||||
|
// THIRD_PERSON
|
||||||
|
//#define CAMERA_THIRD_PERSON_MOUSE_SENSITIVITY 0.003f
|
||||||
|
#define CAMERA_THIRD_PERSON_DISTANCE_CLAMP 1.2f
|
||||||
|
#define CAMERA_THIRD_PERSON_MIN_CLAMP 5.0f
|
||||||
|
#define CAMERA_THIRD_PERSON_MAX_CLAMP -85.0f
|
||||||
|
#define CAMERA_THIRD_PERSON_OFFSET (Vector3){ 0.4f, 0.0f, 0.0f }
|
||||||
|
|
||||||
|
// PLAYER (used by camera)
|
||||||
|
#define PLAYER_MOVEMENT_SENSITIVITY 20.0f
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Camera move modes (first person and third person cameras)
|
||||||
|
typedef enum {
|
||||||
|
MOVE_FRONT = 0,
|
||||||
|
MOVE_BACK,
|
||||||
|
MOVE_RIGHT,
|
||||||
|
MOVE_LEFT,
|
||||||
|
MOVE_UP,
|
||||||
|
MOVE_DOWN
|
||||||
|
} CameraMove;
|
||||||
|
|
||||||
|
// Camera global state context data [56 bytes]
|
||||||
|
typedef struct {
|
||||||
|
unsigned int mode; // Current camera mode
|
||||||
|
float targetDistance; // Camera distance from position to target
|
||||||
|
float playerEyesPosition; // Player eyes position from ground (in meters)
|
||||||
|
Vector2 angle; // Camera angle in plane XZ
|
||||||
|
Vector2 previousMousePosition; // Previous mouse position
|
||||||
|
|
||||||
|
// Camera movement control keys
|
||||||
|
int moveControl[6]; // Move controls (CAMERA_FIRST_PERSON)
|
||||||
|
int smoothZoomControl; // Smooth zoom control key
|
||||||
|
int altControl; // Alternative control key
|
||||||
|
int panControl; // Pan view control key
|
||||||
|
} CameraData;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static CameraData CAMERA = { // Global CAMERA state context
|
||||||
|
.mode = 0,
|
||||||
|
.targetDistance = 0,
|
||||||
|
.playerEyesPosition = 1.85f,
|
||||||
|
.angle = { 0 },
|
||||||
|
.previousMousePosition = { 0 },
|
||||||
|
.moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
|
||||||
|
.smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
|
||||||
|
.altControl = 342, // raylib: KEY_LEFT_ALT
|
||||||
|
.panControl = 2 // raylib: MOUSE_BUTTON_MIDDLE
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module specific Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#if defined(CAMERA_STANDALONE)
|
||||||
|
// NOTE: Camera controls depend on some raylib input functions
|
||||||
|
static void EnableCursor() {} // Unlock cursor
|
||||||
|
static void DisableCursor() {} // Lock cursor
|
||||||
|
|
||||||
|
static int IsKeyDown(int key) { return 0; }
|
||||||
|
|
||||||
|
static int IsMouseButtonDown(int button) { return 0;}
|
||||||
|
static float GetMouseWheelMove() { return 0.0f; }
|
||||||
|
static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Select camera mode (multiple camera modes available)
|
||||||
|
void SetCameraMode(Camera camera, int mode)
|
||||||
|
{
|
||||||
|
Vector3 v1 = camera.position;
|
||||||
|
Vector3 v2 = camera.target;
|
||||||
|
|
||||||
|
float dx = v2.x - v1.x;
|
||||||
|
float dy = v2.y - v1.y;
|
||||||
|
float dz = v2.z - v1.z;
|
||||||
|
|
||||||
|
CAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance to target
|
||||||
|
|
||||||
|
// Camera angle calculation
|
||||||
|
CAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
||||||
|
CAMERA.angle.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW)
|
||||||
|
|
||||||
|
CAMERA.playerEyesPosition = camera.position.y; // Init player eyes position to camera Y position
|
||||||
|
|
||||||
|
CAMERA.previousMousePosition = GetMousePosition(); // Init mouse position
|
||||||
|
|
||||||
|
// Lock cursor for first person and third person cameras
|
||||||
|
if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor();
|
||||||
|
else EnableCursor();
|
||||||
|
|
||||||
|
CAMERA.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update camera depending on selected mode
|
||||||
|
// NOTE: Camera controls depend on some raylib functions:
|
||||||
|
// System: EnableCursor(), DisableCursor()
|
||||||
|
// Mouse: IsMouseButtonDown(), GetMousePosition(), GetMouseWheelMove()
|
||||||
|
// Keys: IsKeyDown()
|
||||||
|
// TODO: Port to quaternion-based camera (?)
|
||||||
|
void UpdateCamera(Camera *camera)
|
||||||
|
{
|
||||||
|
static int swingCounter = 0; // Used for 1st person swinging movement
|
||||||
|
|
||||||
|
// TODO: Compute CAMERA.targetDistance and CAMERA.angle here (?)
|
||||||
|
|
||||||
|
// Mouse movement detection
|
||||||
|
Vector2 mousePositionDelta = { 0.0f, 0.0f };
|
||||||
|
Vector2 mousePosition = GetMousePosition();
|
||||||
|
float mouseWheelMove = GetMouseWheelMove();
|
||||||
|
|
||||||
|
// Keys input detection
|
||||||
|
// TODO: Input detection is raylib-dependant, it could be moved outside the module
|
||||||
|
bool keyPan = IsMouseButtonDown(CAMERA.panControl);
|
||||||
|
bool keyAlt = IsKeyDown(CAMERA.altControl);
|
||||||
|
bool szoomKey = IsKeyDown(CAMERA.smoothZoomControl);
|
||||||
|
bool direction[6] = { IsKeyDown(CAMERA.moveControl[MOVE_FRONT]),
|
||||||
|
IsKeyDown(CAMERA.moveControl[MOVE_BACK]),
|
||||||
|
IsKeyDown(CAMERA.moveControl[MOVE_RIGHT]),
|
||||||
|
IsKeyDown(CAMERA.moveControl[MOVE_LEFT]),
|
||||||
|
IsKeyDown(CAMERA.moveControl[MOVE_UP]),
|
||||||
|
IsKeyDown(CAMERA.moveControl[MOVE_DOWN]) };
|
||||||
|
|
||||||
|
if (CAMERA.mode != CAMERA_CUSTOM)
|
||||||
|
{
|
||||||
|
mousePositionDelta.x = mousePosition.x - CAMERA.previousMousePosition.x;
|
||||||
|
mousePositionDelta.y = mousePosition.y - CAMERA.previousMousePosition.y;
|
||||||
|
|
||||||
|
CAMERA.previousMousePosition = mousePosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support for multiple automatic camera modes
|
||||||
|
// NOTE: In case of CAMERA_CUSTOM nothing happens here, user must update it manually
|
||||||
|
switch (CAMERA.mode)
|
||||||
|
{
|
||||||
|
case CAMERA_FREE: // Camera free controls, using standard 3d-content-creation scheme
|
||||||
|
{
|
||||||
|
// Camera zoom
|
||||||
|
if ((CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
||||||
|
{
|
||||||
|
CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
|
||||||
|
if (CAMERA.targetDistance > CAMERA_FREE_DISTANCE_MAX_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MAX_CLAMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera looking down
|
||||||
|
else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
||||||
|
{
|
||||||
|
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
}
|
||||||
|
else if ((camera->position.y > camera->target.y) && (camera->target.y >= 0))
|
||||||
|
{
|
||||||
|
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
|
||||||
|
// if (camera->target.y < 0) camera->target.y = -0.001;
|
||||||
|
}
|
||||||
|
else if ((camera->position.y > camera->target.y) && (camera->target.y < 0) && (mouseWheelMove > 0))
|
||||||
|
{
|
||||||
|
CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
|
||||||
|
if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
|
||||||
|
}
|
||||||
|
// Camera looking up
|
||||||
|
else if ((camera->position.y < camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
||||||
|
{
|
||||||
|
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
}
|
||||||
|
else if ((camera->position.y < camera->target.y) && (camera->target.y <= 0))
|
||||||
|
{
|
||||||
|
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
|
||||||
|
|
||||||
|
// if (camera->target.y > 0) camera->target.y = 0.001;
|
||||||
|
}
|
||||||
|
else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (mouseWheelMove > 0))
|
||||||
|
{
|
||||||
|
CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
|
||||||
|
if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input keys checks
|
||||||
|
if (keyPan)
|
||||||
|
{
|
||||||
|
if (keyAlt) // Alternative key behaviour
|
||||||
|
{
|
||||||
|
if (szoomKey)
|
||||||
|
{
|
||||||
|
// Camera smooth zoom
|
||||||
|
CAMERA.targetDistance += (mousePositionDelta.y*CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Camera rotation
|
||||||
|
CAMERA.angle.x += mousePositionDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY;
|
||||||
|
CAMERA.angle.y += mousePositionDelta.y*-CAMERA_FREE_MOUSE_SENSITIVITY;
|
||||||
|
|
||||||
|
// Angle clamp
|
||||||
|
if (CAMERA.angle.y > CAMERA_FREE_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FREE_MIN_CLAMP*DEG2RAD;
|
||||||
|
else if (CAMERA.angle.y < CAMERA_FREE_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FREE_MAX_CLAMP*DEG2RAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Camera panning
|
||||||
|
camera->target.x += ((mousePositionDelta.x*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(CAMERA.angle.x)*sinf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
||||||
|
camera->target.y += ((mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
||||||
|
camera->target.z += ((mousePositionDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(CAMERA.angle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.x)*sinf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update camera position with changes
|
||||||
|
camera->position.x = -sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
|
||||||
|
camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance + camera->target.y;
|
||||||
|
camera->position.z = -cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
|
||||||
|
|
||||||
|
} break;
|
||||||
|
case CAMERA_ORBITAL: // Camera just orbits around target, only zoom allowed
|
||||||
|
{
|
||||||
|
CAMERA.angle.x += CAMERA_ORBITAL_SPEED; // Camera orbit angle
|
||||||
|
CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY); // Camera zoom
|
||||||
|
|
||||||
|
// Camera distance clamp
|
||||||
|
if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
|
||||||
|
|
||||||
|
// Update camera position with changes
|
||||||
|
camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
|
||||||
|
camera->position.y = ((CAMERA.angle.y <= 0.0f)? 1 : -1)*sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
|
||||||
|
camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
|
||||||
|
|
||||||
|
} break;
|
||||||
|
case CAMERA_FIRST_PERSON: // Camera moves as in a first-person game, controls are configurable
|
||||||
|
{
|
||||||
|
camera->position.x += (sinf(CAMERA.angle.x)*direction[MOVE_BACK] -
|
||||||
|
sinf(CAMERA.angle.x)*direction[MOVE_FRONT] -
|
||||||
|
cosf(CAMERA.angle.x)*direction[MOVE_LEFT] +
|
||||||
|
cosf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
|
camera->position.y += (sinf(CAMERA.angle.y)*direction[MOVE_FRONT] -
|
||||||
|
sinf(CAMERA.angle.y)*direction[MOVE_BACK] +
|
||||||
|
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
|
camera->position.z += (cosf(CAMERA.angle.x)*direction[MOVE_BACK] -
|
||||||
|
cosf(CAMERA.angle.x)*direction[MOVE_FRONT] +
|
||||||
|
sinf(CAMERA.angle.x)*direction[MOVE_LEFT] -
|
||||||
|
sinf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
|
// Camera orientation calculation
|
||||||
|
CAMERA.angle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||||
|
CAMERA.angle.y += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||||
|
|
||||||
|
// Angle clamp
|
||||||
|
if (CAMERA.angle.y > CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD;
|
||||||
|
else if (CAMERA.angle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
|
||||||
|
|
||||||
|
// Recalculate camera target considering translation and rotation
|
||||||
|
Matrix translation = MatrixTranslate(0, 0, (CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER));
|
||||||
|
Matrix rotation = MatrixRotateXYZ((Vector3){ PI*2 - CAMERA.angle.y, PI*2 - CAMERA.angle.x, 0 });
|
||||||
|
Matrix transform = MatrixMultiply(translation, rotation);
|
||||||
|
|
||||||
|
camera->target.x = camera->position.x - transform.m12;
|
||||||
|
camera->target.y = camera->position.y - transform.m13;
|
||||||
|
camera->target.z = camera->position.z - transform.m14;
|
||||||
|
|
||||||
|
// If movement detected (some key pressed), increase swinging
|
||||||
|
for (int i = 0; i < 6; i++) if (direction[i]) { swingCounter++; break; }
|
||||||
|
|
||||||
|
// Camera position update
|
||||||
|
// NOTE: On CAMERA_FIRST_PERSON player Y-movement is limited to player 'eyes position'
|
||||||
|
camera->position.y = CAMERA.playerEyesPosition - sinf(swingCounter/CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER)/CAMERA_FIRST_PERSON_STEP_DIVIDER;
|
||||||
|
|
||||||
|
camera->up.x = sinf(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
|
||||||
|
camera->up.z = -sinf(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
|
||||||
|
|
||||||
|
} break;
|
||||||
|
case CAMERA_THIRD_PERSON: // Camera moves as in a third-person game, following target at a distance, controls are configurable
|
||||||
|
{
|
||||||
|
camera->position.x += (sinf(CAMERA.angle.x)*direction[MOVE_BACK] -
|
||||||
|
sinf(CAMERA.angle.x)*direction[MOVE_FRONT] -
|
||||||
|
cosf(CAMERA.angle.x)*direction[MOVE_LEFT] +
|
||||||
|
cosf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
|
camera->position.y += (sinf(CAMERA.angle.y)*direction[MOVE_FRONT] -
|
||||||
|
sinf(CAMERA.angle.y)*direction[MOVE_BACK] +
|
||||||
|
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
|
camera->position.z += (cosf(CAMERA.angle.x)*direction[MOVE_BACK] -
|
||||||
|
cosf(CAMERA.angle.x)*direction[MOVE_FRONT] +
|
||||||
|
sinf(CAMERA.angle.x)*direction[MOVE_LEFT] -
|
||||||
|
sinf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
|
// Camera orientation calculation
|
||||||
|
CAMERA.angle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||||
|
CAMERA.angle.y += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||||
|
|
||||||
|
// Angle clamp
|
||||||
|
if (CAMERA.angle.y > CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD;
|
||||||
|
else if (CAMERA.angle.y < CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD;
|
||||||
|
|
||||||
|
// Camera zoom
|
||||||
|
CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
|
||||||
|
|
||||||
|
// Camera distance clamp
|
||||||
|
if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
|
||||||
|
|
||||||
|
// TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target...
|
||||||
|
camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
|
||||||
|
|
||||||
|
if (CAMERA.angle.y <= 0.0f) camera->position.y = sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
|
||||||
|
else camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
|
||||||
|
|
||||||
|
camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
|
||||||
|
|
||||||
|
} break;
|
||||||
|
case CAMERA_CUSTOM: break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set camera pan key to combine with mouse movement (free camera)
|
||||||
|
void SetCameraPanControl(int keyPan) { CAMERA.panControl = keyPan; }
|
||||||
|
|
||||||
|
// Set camera alt key to combine with mouse movement (free camera)
|
||||||
|
void SetCameraAltControl(int keyAlt) { CAMERA.altControl = keyAlt; }
|
||||||
|
|
||||||
|
// Set camera smooth zoom key to combine with mouse (free camera)
|
||||||
|
void SetCameraSmoothZoomControl(int szoomKey) { CAMERA.smoothZoomControl = szoomKey; }
|
||||||
|
|
||||||
|
// Set camera move controls (1st person and 3rd person cameras)
|
||||||
|
void SetCameraMoveControls(int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown)
|
||||||
|
{
|
||||||
|
CAMERA.moveControl[MOVE_FRONT] = keyFront;
|
||||||
|
CAMERA.moveControl[MOVE_BACK] = keyBack;
|
||||||
|
CAMERA.moveControl[MOVE_RIGHT] = keyRight;
|
||||||
|
CAMERA.moveControl[MOVE_LEFT] = keyLeft;
|
||||||
|
CAMERA.moveControl[MOVE_UP] = keyUp;
|
||||||
|
CAMERA.moveControl[MOVE_DOWN] = keyDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CAMERA_IMPLEMENTATION
|
||||||
6640
src/rcore.c
Normal file
6640
src/rcore.c
Normal file
File diff suppressed because it is too large
Load diff
566
src/rgestures.h
Normal file
566
src/rgestures.h
Normal file
|
|
@ -0,0 +1,566 @@
|
||||||
|
/**********************************************************************************************
|
||||||
|
*
|
||||||
|
* rgestures - Gestures system, gestures processing based on input events (touch/mouse)
|
||||||
|
*
|
||||||
|
* NOTE: Memory footprint of this library is aproximately 128 bytes (global variables)
|
||||||
|
*
|
||||||
|
* CONFIGURATION:
|
||||||
|
*
|
||||||
|
* #define GESTURES_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 GESTURES_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-2021 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 GESTURES_STANDALONE usage
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Boolean type
|
||||||
|
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
||||||
|
typedef enum bool { false, true } bool;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(RL_VECTOR2_TYPE)
|
||||||
|
// Vector2 type
|
||||||
|
typedef struct Vector2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
} Vector2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(GESTURES_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
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef __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(GESTURES_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 milliseconds
|
||||||
|
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
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // GESTURES_H
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* GESTURES IMPLEMENTATION
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(GESTURES_IMPLEMENTATION)
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#define FORCE_TO_SWIPE 0.0005f // 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 MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
|
||||||
|
#define TAP_TIMEOUT 300 // Tap minimum time, measured in milliseconds
|
||||||
|
#define PINCH_TIMEOUT 300 // Pinch minimum time, measured in milliseconds
|
||||||
|
#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
|
||||||
|
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 milliseconds
|
||||||
|
} 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 {
|
||||||
|
bool start; // SWIPE used to define when start measuring GESTURES.Swipe.timeDuration
|
||||||
|
double timeDuration; // SWIPE 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 = {
|
||||||
|
.Touch.firstId = -1,
|
||||||
|
.current = GESTURE_NONE, // No current gesture detected
|
||||||
|
.enabledFlags = 0b0000001111111111 // All gestures supported by default
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module specific 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 getures to be detected
|
||||||
|
void SetGesturesEnabled(unsigned int flags)
|
||||||
|
{
|
||||||
|
GESTURES.enabledFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a gesture have been detected
|
||||||
|
bool IsGestureDetected(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.Touch.firstId = event.pointId[0];
|
||||||
|
|
||||||
|
GESTURES.Drag.vector = (Vector2){ 0.0f, 0.0f };
|
||||||
|
}
|
||||||
|
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||||
|
{
|
||||||
|
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.upPosition = event.position[0];
|
||||||
|
|
||||||
|
// NOTE: GESTURES.Drag.intensity dependend 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.timeDuration));
|
||||||
|
|
||||||
|
GESTURES.Swipe.start = false;
|
||||||
|
|
||||||
|
// Detect GESTURE_SWIPE
|
||||||
|
if ((GESTURES.Drag.intensity > FORCE_TO_SWIPE) && (GESTURES.Touch.firstId == event.pointId[0]))
|
||||||
|
{
|
||||||
|
// 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 < 120)) GESTURES.current = GESTURE_SWIPE_UP; // Up
|
||||||
|
else if ((GESTURES.Drag.angle > 120) && (GESTURES.Drag.angle < 210)) GESTURES.current = GESTURE_SWIPE_LEFT; // Left
|
||||||
|
else if ((GESTURES.Drag.angle > 210) && (GESTURES.Drag.angle < 300)) 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)
|
||||||
|
{
|
||||||
|
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||||
|
|
||||||
|
if (!GESTURES.Swipe.start)
|
||||||
|
{
|
||||||
|
GESTURES.Swipe.timeDuration = rgGetCurrentTime();
|
||||||
|
GESTURES.Swipe.start = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG)
|
||||||
|
{
|
||||||
|
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.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.downPositionA = GESTURES.Touch.moveDownPositionA;
|
||||||
|
GESTURES.Touch.downPositionB = 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.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.downPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
|
||||||
|
{
|
||||||
|
if ((rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) - GESTURES.Pinch.distance) < 0) 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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((rgGetCurrentTime() - GESTURES.Touch.eventTime) > TAP_TIMEOUT) && (GESTURES.current == GESTURE_DRAG) && (GESTURES.Touch.pointCount < 2))
|
||||||
|
{
|
||||||
|
GESTURES.current = GESTURE_HOLD;
|
||||||
|
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||||
|
GESTURES.Hold.resetRequired = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 ms
|
||||||
|
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, counterclock-wise
|
||||||
|
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 beween two pinch points
|
||||||
|
// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise
|
||||||
|
float GetGesturePinchAngle(void)
|
||||||
|
{
|
||||||
|
// NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE
|
||||||
|
|
||||||
|
return GESTURES.Pinch.angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module specific 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 milliseconds
|
||||||
|
static double rgGetCurrentTime(void)
|
||||||
|
{
|
||||||
|
double time = 0;
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
unsigned long long int clockFrequency, currentTime;
|
||||||
|
|
||||||
|
QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
|
||||||
|
QueryPerformanceCounter(¤tTime);
|
||||||
|
|
||||||
|
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
|
||||||
|
#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/1000000.0); // Time in miliseconds
|
||||||
|
#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/1000000.0); // Time in miliseconds
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GESTURES_IMPLEMENTATION
|
||||||
5636
src/rmodels.c
Normal file
5636
src/rmodels.c
Normal file
File diff suppressed because it is too large
Load diff
1732
src/rshapes.c
Normal file
1732
src/rshapes.c
Normal file
File diff suppressed because it is too large
Load diff
1791
src/rtext.c
Normal file
1791
src/rtext.c
Normal file
File diff suppressed because it is too large
Load diff
4677
src/rtextures.c
Normal file
4677
src/rtextures.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue