raylib-bindings 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a24ae09d1d8e13d58febdd5d222b7c219291c49531939bddccdcd89079bb4943
4
- data.tar.gz: 536927a5880fa2ed1a7007951fd505bbe81cb0263011c9ead49912e484938d2d
3
+ metadata.gz: ec140a3aeb14467dddc0851eb6dc9b26f1e189955eda32aede4cdb9068163d2a
4
+ data.tar.gz: 9edeefc3c423bb8436b9d0a3779c86abe584a0c719090a8819dd8489689079db
5
5
  SHA512:
6
- metadata.gz: 3b38f484780698c0ae0ceb9a9f79ae31d5eb86a883df27434f61e96b3e75b50e6d5c285e9e83196852c5b4ca9597a355b7bf1627c66a8d07ddbff3cd44b15328
7
- data.tar.gz: 29fb98821c8a10b45ae37b81aadd1ccba54864ed962990e0ebd424dd6f0d100b06e32057de13775155c3be0607e81f34f620ea71174140bf74d99f8f87ba489b
6
+ metadata.gz: 6f46201e5a1c794a319ccae7008220e092837aa860040710d9ba41ff5836bf81c179d48ba72994cf863ce9dce393134d1218e237b76c4f414de6422ddd19bf19
7
+ data.tar.gz: 349f290348f0fe2ac8690dd2bf712a2d1a41f979f4c95e4ca5a1cf7d85dcdd278714688aa359112a845960549870d0deb4775ef88642c4e567b1999966c515ce
data/ChangeLog CHANGED
@@ -1,3 +1,25 @@
1
+ 2022-12-30 vaiorabbit <http://twitter.com/vaiorabbit>
2
+
3
+ * generator: Now generates binding code for config.h
4
+
5
+ 2022-12-29 vaiorabbit <http://twitter.com/vaiorabbit>
6
+
7
+ * generator: Now generates enum descriptions
8
+ * Fixed several codes according to Rubocop warnings
9
+ * lib/raylib_helper.rb: Added several helper functions/classes
10
+
11
+ 2022-12-25 vaiorabbit <http://twitter.com/vaiorabbit>
12
+
13
+ * Converted DrawModelEx into a wrapper function of rbDrawModelEx to avoid Matrix problem found in models_animation sample
14
+ * Attach functions with an explicit name - Ref.: https://www.rubydoc.info/github/ffi/ffi/FFI%2FLibrary:attach_function
15
+ * setup_xxx_symbols: name, retval and arguments of one function are now packed into one line
16
+ * generator: Now imports descriptions from original API schema
17
+ * Generated with the latest raylib ( https://github.com/raysan5/raylib/commit/03cc540d5f1df71bd7ad8118d0e11b492fa5cc18 )
18
+
19
+ 2022-12-24 vaiorabbit <http://twitter.com/vaiorabbit>
20
+
21
+ * Experimental Linux (Chromebook) support
22
+
1
23
  2022-12-10 vaiorabbit <http://twitter.com/vaiorabbit>
2
24
 
3
25
  * Pulled latest raylib ( https://github.com/raysan5/raylib/commit/2c9d116a5ce835328dc3267313f1b34b2e7ad8c9 ) / and raygui ( https://github.com/raysan5/raygui/commit/64179558e425f6e05054d2a70eb12530e0fec103 )
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Ruby-raylib : Yet another raylib wrapper for Ruby
2
- Copyright (c) 2021-2022 vaiorabbit <http://twitter.com/vaiorabbit>
2
+ Copyright (c) 2021-2023 vaiorabbit <http://twitter.com/vaiorabbit>
3
3
 
4
4
  This software is provided 'as-is', without any express or implied
5
5
  warranty. In no event will the authors be held liable for any damages
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  # Yet another raylib wrapper for Ruby #
4
4
 
5
5
  * Created : 2021-10-17
6
- * Last modified : 2022-12-10
6
+ * Last modified : 2022-12-31
7
7
 
8
8
  Provides Ruby bindings for raylib-related libraries including:
9
9
 
@@ -45,9 +45,9 @@ D:\> ruby template.rb
45
45
  * Ruby interpreter
46
46
  * Tested on:
47
47
  * [macOS]
48
- * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
48
+ * ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21]
49
49
  * [Windows] https://rubyinstaller.org/downloads/ Ruby+Devkit
50
- * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
50
+ * ruby 3.2.0 (2022-12-25 revision a528908271) [x64-mingw-ucrt]
51
51
 
52
52
  * If you need to build DLLs/shared libralies for your own runtime envrioenment (Linux, etc.):
53
53
  * CMake https://cmake.org/download/
@@ -63,7 +63,7 @@ D:\> ruby template.rb
63
63
 
64
64
  * [Windows] gcc
65
65
 
66
- gcc (Rev10, Built by MSYS2 project) 11.2.0
66
+ gcc (Rev7, Built by MSYS2 project) 12.2.0
67
67
 
68
68
 
69
69
  <details>
@@ -72,9 +72,11 @@ D:\> ruby template.rb
72
72
  * Ruby interpreter
73
73
  * Tested on:
74
74
  * [macOS]
75
+ * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
75
76
  * ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin20]
76
77
  * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]
77
78
  * [Windows] https://rubyinstaller.org/downloads/ Ruby+Devkit
79
+ * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
78
80
  * ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x64-mingw-ucrt]
79
81
  * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x64-mingw32]
80
82
 
@@ -96,9 +98,18 @@ D:\> ruby template.rb
96
98
  * [Windows] gcc
97
99
 
98
100
  gcc (Rev9, Built by MSYS2 project) 11.2.0
101
+ gcc (Rev10, Built by MSYS2 project) 11.2.0
99
102
 
100
103
  </details>
101
104
 
105
+ ## Project ##
106
+
107
+ See the project below to learn how to use this library:
108
+
109
+ * Whac-a-Mole! : Ruby raylib bindings demo
110
+ * <img src="https://raw.githubusercontent.com/vaiorabbit/raylib-bindings-whacamole/main/doc/screenshot_00.png" width="300"> <img src="https://raw.githubusercontent.com/vaiorabbit/raylib-bindings-whacamole/main/doc/screenshot_01.png" width="300">
111
+ * <https://github.com/vaiorabbit/raylib-bindings-whacamole>
112
+
102
113
  ## Limitation ##
103
114
 
104
115
  * `SetTraceLogCallback` and `TraceLogCallback` are unusable since Ruby-FFI does not support `:varargs` parameter in callbacks (`Proc`, etc.)
@@ -121,7 +132,7 @@ Shared libraries in `lib` directory are built on top of these products and are a
121
132
  All ruby codes here are available under the terms of the zlib/libpng License ( http://opensource.org/licenses/Zlib ).
122
133
 
123
134
  Ruby-raylib : Yet another raylib wrapper for Ruby
124
- Copyright (c) 2021-2022 vaiorabbit <http://twitter.com/vaiorabbit>
135
+ Copyright (c) 2021-2023 vaiorabbit <http://twitter.com/vaiorabbit>
125
136
 
126
137
  This software is provided 'as-is', without any express or implied
127
138
  warranty. In no event will the authors be held liable for any damages
data/examples/template.rb CHANGED
@@ -20,6 +20,8 @@ when /mswin|msys|mingw|cygwin/
20
20
  Raylib.load_lib(shared_lib_path + 'libraylib.dll', raygui_libpath: shared_lib_path + 'raygui.dll', physac_libpath: shared_lib_path + 'physac.dll')
21
21
  when /darwin/
22
22
  Raylib.load_lib(shared_lib_path + 'libraylib.dylib', raygui_libpath: shared_lib_path + 'raygui.dylib', physac_libpath: shared_lib_path + 'physac.dylib')
23
+ when /linux/
24
+ Raylib.load_lib(shared_lib_path + 'libraylib.so', raygui_libpath: shared_lib_path + 'raygui.so', physac_libpath: shared_lib_path + 'physac.so')
23
25
  else
24
26
  raise RuntimeError, "Unknown OS: #{RUBY_PLATFORM}"
25
27
  end
@@ -37,11 +39,11 @@ if __FILE__ == $PROGRAM_NAME
37
39
  # Camera
38
40
  camera = Camera.new
39
41
  reset_camera = lambda {
40
- camera[:position] = Vector3.create(0.0, 10.0, 10.0)
41
- camera[:target] = Vector3.create(0.0, 0.0, 0.0)
42
- camera[:up] = Vector3.create(0.0, 1.0, 0.0)
43
- camera[:fovy] = 45.0
44
- camera[:projection] = CAMERA_PERSPECTIVE
42
+ camera.position.set(0.0, 10.0, 10.0)
43
+ camera.target.set(0.0, 0.0, 0.0)
44
+ camera.up.set(0.0, 1.0, 0.0)
45
+ camera.fovy = 45.0
46
+ camera.projection = CAMERA_PERSPECTIVE
45
47
  }
46
48
  reset_camera.call
47
49
  SetCameraMode(camera, CAMERA_FREE)
@@ -76,29 +78,29 @@ if __FILE__ == $PROGRAM_NAME
76
78
  move[:z] += speed if IsKeyDown(KEY_DOWN)
77
79
  move[:z] -= speed if IsKeyDown(KEY_UP)
78
80
 
79
- to_camera = Vector3Normalize(Vector3.create(camera[:position][:x], 0, camera[:position][:z]))
81
+ to_camera = Vector3Normalize(Vector3.create(camera.position.x, 0, camera.position.z))
80
82
  rotate_y = QuaternionFromVector3ToVector3(Vector3.create(0, 0, 1), to_camera)
81
83
  move = Vector3RotateByQuaternion(move, rotate_y)
82
84
 
83
85
  player_pos = Vector3Add(player_pos, move)
84
- player_screen_pos = GetWorldToScreen(Vector3.create(player_pos[:x], player_pos[:y] + 2.5, player_pos[:z]), camera)
86
+ player_screen_pos = GetWorldToScreen(Vector3.create(player_pos.x, player_pos.y + 2.5, player_pos.z), camera)
85
87
 
86
88
  # Check collision status
87
89
  collision = false
88
90
 
89
- player_bbox = BoundingBox.create(player_pos[:x] - player_size[:x]/2,
90
- player_pos[:y] - player_size[:y]/2,
91
- player_pos[:z] - player_size[:z]/2,
92
- player_pos[:x] + player_size[:x]/2,
93
- player_pos[:y] + player_size[:y]/2,
94
- player_pos[:z] + player_size[:z]/2)
91
+ player_bbox = BoundingBox.create(player_pos.x - player_size.x/2,
92
+ player_pos.y - player_size.y/2,
93
+ player_pos.z - player_size.z/2,
94
+ player_pos.x + player_size.x/2,
95
+ player_pos.y + player_size.y/2,
96
+ player_pos.z + player_size.z/2)
95
97
 
96
- obstacle_cube_bbox = BoundingBox.create(obstacle_cube_pos[:x] - obstacle_cube_size[:x]/2,
97
- obstacle_cube_pos[:y] - obstacle_cube_size[:y]/2,
98
- obstacle_cube_pos[:z] - obstacle_cube_size[:z]/2,
99
- obstacle_cube_pos[:x] + obstacle_cube_size[:x]/2,
100
- obstacle_cube_pos[:y] + obstacle_cube_size[:y]/2,
101
- obstacle_cube_pos[:z] + obstacle_cube_size[:z]/2)
98
+ obstacle_cube_bbox = BoundingBox.create(obstacle_cube_pos.x - obstacle_cube_size.x/2,
99
+ obstacle_cube_pos.y - obstacle_cube_size.y/2,
100
+ obstacle_cube_pos.z - obstacle_cube_size.z/2,
101
+ obstacle_cube_pos.x + obstacle_cube_size.x/2,
102
+ obstacle_cube_pos.y + obstacle_cube_size.y/2,
103
+ obstacle_cube_pos.z + obstacle_cube_size.z/2)
102
104
 
103
105
  # Check collisions player vs obstacle_cube
104
106
  collision = true if CheckCollisionBoxes(player_bbox, obstacle_cube_bbox)
@@ -118,8 +120,8 @@ if __FILE__ == $PROGRAM_NAME
118
120
  DrawCube(player_pos, 2.0, 2.0, 2.0, collision ? Fade(ruby_red, 0.25) : ruby_red)
119
121
  DrawCubeWires(player_pos, 2.0, 2.0, 2.0, MAROON)
120
122
  # Obstacle cube
121
- DrawCube(obstacle_cube_pos, obstacle_cube_size[:x], obstacle_cube_size[:y], obstacle_cube_size[:z], GRAY)
122
- DrawCubeWires(obstacle_cube_pos, obstacle_cube_size[:x], obstacle_cube_size[:y], obstacle_cube_size[:z], DARKGRAY)
123
+ DrawCube(obstacle_cube_pos, obstacle_cube_size.x, obstacle_cube_size.y, obstacle_cube_size.z, GRAY)
124
+ DrawCubeWires(obstacle_cube_pos, obstacle_cube_size.x, obstacle_cube_size.y, obstacle_cube_size.z, DARKGRAY)
123
125
  # Obstacle sphere
124
126
  DrawSphere(obstacle_sphere_pos, obstacle_sphere_size, GRAY)
125
127
  DrawSphereWires(obstacle_sphere_pos, obstacle_sphere_size, 16, 16, DARKGRAY)
@@ -129,7 +131,7 @@ if __FILE__ == $PROGRAM_NAME
129
131
 
130
132
  ## HUD
131
133
  # Text over the red cube
132
- DrawText("Player HP: 100 / 100", player_screen_pos[:x] - MeasureText("Player HP: 100/100", 20)/2, player_screen_pos[:y], 20, BLACK)
134
+ DrawText("Player HP: 100 / 100", player_screen_pos.x - MeasureText("Player HP: 100/100", 20)/2, player_screen_pos.y, 20, BLACK)
133
135
  # Help message
134
136
  DrawRectangle(10, screen_height - 100, 300, 80, Fade(MAROON, 0.25))
135
137
  DrawRectangleLines(10, screen_height - 100, 300, 80, ruby_red)
data/lib/config.rb ADDED
@@ -0,0 +1,98 @@
1
+ # Yet another raylib wrapper for Ruby
2
+ #
3
+ # * https://github.com/vaiorabbit/raylib-bindings
4
+ #
5
+ # [NOTICE] Autogenerated. Do not edit.
6
+
7
+ require 'ffi'
8
+
9
+ module Raylib
10
+ extend FFI::Library
11
+
12
+ # Define/Macro
13
+
14
+ SUPPORT_MODULE_RSHAPES = 1
15
+ SUPPORT_MODULE_RTEXTURES = 1
16
+ SUPPORT_MODULE_RTEXT = 1 # WARNING: It requires SUPPORT_MODULE_RTEXTURES to load sprite font textures
17
+ SUPPORT_MODULE_RMODELS = 1
18
+ SUPPORT_MODULE_RAUDIO = 1
19
+ SUPPORT_CAMERA_SYSTEM = 1
20
+ SUPPORT_GESTURES_SYSTEM = 1
21
+ SUPPORT_MOUSE_GESTURES = 1
22
+ SUPPORT_SSH_KEYBOARD_RPI = 1
23
+ SUPPORT_WINMM_HIGHRES_TIMER = 1
24
+ SUPPORT_PARTIALBUSY_WAIT_LOOP = 1
25
+ SUPPORT_SCREEN_CAPTURE = 1
26
+ SUPPORT_GIF_RECORDING = 1
27
+ SUPPORT_COMPRESSION_API = 1
28
+ MAX_FILEPATH_CAPACITY = 8192 # Maximum file paths capacity
29
+ MAX_FILEPATH_LENGTH = 4096 # Maximum length for filepaths (Linux PATH_MAX default value)
30
+ MAX_KEYBOARD_KEYS = 512 # Maximum number of keyboard keys supported
31
+ MAX_MOUSE_BUTTONS = 8 # Maximum number of mouse buttons supported
32
+ MAX_GAMEPADS = 4 # Maximum number of gamepads supported
33
+ MAX_GAMEPAD_AXIS = 8 # Maximum number of axis supported (per gamepad)
34
+ MAX_GAMEPAD_BUTTONS = 32 # Maximum number of buttons supported (per gamepad)
35
+ MAX_TOUCH_POINTS = 8 # Maximum number of touch points supported
36
+ MAX_KEY_PRESSED_QUEUE = 16 # Maximum number of keys in the key input queue
37
+ MAX_CHAR_PRESSED_QUEUE = 16 # Maximum number of characters in the char input queue
38
+ MAX_DECOMPRESSION_SIZE = 64 # Max size allocated for decompression in MB
39
+ RL_DEFAULT_BATCH_BUFFERS = 1 # Default number of batch buffers (multi-buffering)
40
+ RL_DEFAULT_BATCH_DRAWCALLS = 256 # Default number of batch draw calls (by state changes: mode, texture)
41
+ RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS = 4 # Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
42
+ RL_MAX_MATRIX_STACK_SIZE = 32 # Maximum size of internal Matrix stack
43
+ RL_MAX_SHADER_LOCATIONS = 32 # Maximum number of shader locations supported
44
+ RL_CULL_DISTANCE_NEAR = 0.01 # Default projection matrix near cull distance
45
+ RL_CULL_DISTANCE_FAR = 1000.0 # Default projection matrix far cull distance
46
+ RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION = "vertexPosition" # Binded by default to shader location: 0
47
+ RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD = "vertexTexCoord" # Binded by default to shader location: 1
48
+ RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL = "vertexNormal" # Binded by default to shader location: 2
49
+ RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR = "vertexColor" # Binded by default to shader location: 3
50
+ RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT = "vertexTangent" # Binded by default to shader location: 4
51
+ RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 = "vertexTexCoord2" # Binded by default to shader location: 5
52
+ RL_DEFAULT_SHADER_UNIFORM_NAME_MVP = "mvp" # model-view-projection matrix
53
+ RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW = "matView" # view matrix
54
+ RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION = "matProjection" # projection matrix
55
+ RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL = "matModel" # model matrix
56
+ RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL = "matNormal" # normal matrix (transpose(inverse(matModelView))
57
+ RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR = "colDiffuse" # color diffuse (base tint color, multiplied by texture color)
58
+ RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 = "texture0" # texture0 (texture slot active 0)
59
+ RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 = "texture1" # texture1 (texture slot active 1)
60
+ RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 = "texture2" # texture2 (texture slot active 2)
61
+ SUPPORT_QUADS_DRAW_MODE = 1
62
+ SUPPORT_FILEFORMAT_PNG = 1
63
+ SUPPORT_FILEFORMAT_GIF = 1
64
+ SUPPORT_FILEFORMAT_QOI = 1
65
+ SUPPORT_FILEFORMAT_DDS = 1
66
+ SUPPORT_FILEFORMAT_HDR = 1
67
+ SUPPORT_IMAGE_EXPORT = 1
68
+ SUPPORT_IMAGE_GENERATION = 1
69
+ SUPPORT_IMAGE_MANIPULATION = 1
70
+ SUPPORT_DEFAULT_FONT = 1
71
+ SUPPORT_FILEFORMAT_FNT = 1
72
+ SUPPORT_FILEFORMAT_TTF = 1
73
+ SUPPORT_TEXT_MANIPULATION = 1
74
+ MAX_TEXT_BUFFER_LENGTH = 1024 # Size of internal static buffers used on some functions:
75
+ MAX_TEXTSPLIT_COUNT = 128 # Maximum number of substrings to split: TextSplit()
76
+ SUPPORT_FILEFORMAT_OBJ = 1
77
+ SUPPORT_FILEFORMAT_MTL = 1
78
+ SUPPORT_FILEFORMAT_IQM = 1
79
+ SUPPORT_FILEFORMAT_GLTF = 1
80
+ SUPPORT_FILEFORMAT_VOX = 1
81
+ SUPPORT_FILEFORMAT_M3D = 1
82
+ SUPPORT_MESH_GENERATION = 1
83
+ MAX_MATERIAL_MAPS = 12 # Maximum number of shader maps supported
84
+ MAX_MESH_VERTEX_BUFFERS = 7 # Maximum vertex buffers (VBO) per mesh
85
+ SUPPORT_FILEFORMAT_WAV = 1
86
+ SUPPORT_FILEFORMAT_OGG = 1
87
+ SUPPORT_FILEFORMAT_XM = 1
88
+ SUPPORT_FILEFORMAT_MOD = 1
89
+ SUPPORT_FILEFORMAT_MP3 = 1
90
+ AUDIO_DEVICE_FORMAT = "ma_format_f32" # Device output format (miniaudio: float-32bit)
91
+ AUDIO_DEVICE_CHANNELS = 2 # Device output channels: stereo
92
+ AUDIO_DEVICE_SAMPLE_RATE = 0 # Device sample rate (device default)
93
+ MAX_AUDIO_BUFFER_POOL_CHANNELS = 16 # Maximum number of audio pool channels
94
+ SUPPORT_STANDARD_FILEIO = 1
95
+ SUPPORT_TRACELOG = 1
96
+ MAX_TRACELOG_MSG_LENGTH = 128 # Max length of one trace-log message
97
+
98
+ end
data/lib/libraylib.dll CHANGED
Binary file
data/lib/libraylib.dylib CHANGED
Binary file
data/lib/physac.dll CHANGED
Binary file
data/lib/physac.rb CHANGED
@@ -2,18 +2,19 @@
2
2
  #
3
3
  # * https://github.com/vaiorabbit/raylib-bindings
4
4
  #
5
- # [NOTICE] This is an automatically generated file.
5
+ # [NOTICE] Autogenerated. Do not edit.
6
6
 
7
7
  require 'ffi'
8
8
 
9
9
  module Raylib
10
10
  extend FFI::Library
11
+
11
12
  # Define/Macro
12
13
 
13
- PHYSAC_MAX_BODIES = 64
14
- PHYSAC_MAX_MANIFOLDS = 4096
15
- PHYSAC_MAX_VERTICES = 24
16
- PHYSAC_DEFAULT_CIRCLE_VERTICES = 24
14
+ PHYSAC_MAX_BODIES = 64 # Maximum number of physic bodies supported
15
+ PHYSAC_MAX_MANIFOLDS = 4096 # Maximum number of physic bodies interactions (64x64)
16
+ PHYSAC_MAX_VERTICES = 24 # Maximum number of vertex for polygons shapes
17
+ PHYSAC_DEFAULT_CIRCLE_VERTICES = 24 # Default number of vertices for circle shapes
17
18
  PHYSAC_COLLISION_ITERATIONS = 100
18
19
  PHYSAC_PENETRATION_ALLOWANCE = 0.05
19
20
  PHYSAC_PENETRATION_CORRECTION = 0.4
@@ -21,9 +22,11 @@ module Raylib
21
22
 
22
23
  # Enum
23
24
 
25
+ # enum PhysicsShapeType
24
26
  PHYSICS_CIRCLE = 0
25
27
  PHYSICS_POLYGON = 1
26
28
 
29
+
27
30
  # Typedef
28
31
 
29
32
  typedef :int, :PhysicsShapeType
@@ -32,6 +35,7 @@ module Raylib
32
35
 
33
36
  # Struct
34
37
 
38
+ # Matrix2x2 type (used for polygon shape rotation matrix)
35
39
  class Matrix2x2 < FFI::Struct
36
40
  layout(
37
41
  :m00, :float,
@@ -43,136 +47,176 @@ module Raylib
43
47
 
44
48
  class PhysicsVertexData < FFI::Struct
45
49
  layout(
46
- :vertexCount, :uint,
47
- :positions, [Vector2, 24],
48
- :normals, [Vector2, 24],
50
+ :vertexCount, :uint, # Vertex count (positions and normals)
51
+ :positions, [Vector2, 24], # Vertex positions vectors
52
+ :normals, [Vector2, 24], # Vertex normals vectors
49
53
  )
50
54
  end
51
55
 
52
56
  class PhysicsShape < FFI::Struct
53
57
  layout(
54
- :type, :int,
55
- :body, :pointer,
56
- :vertexData, PhysicsVertexData,
57
- :radius, :float,
58
- :transform, Matrix2x2,
58
+ :type, :int, # Shape type (circle or polygon)
59
+ :body, :pointer, # Shape physics body data pointer
60
+ :vertexData, PhysicsVertexData, # Shape vertices data (used for polygon shapes)
61
+ :radius, :float, # Shape radius (used for circle shapes)
62
+ :transform, Matrix2x2, # Vertices transform matrix 2x2
59
63
  )
60
64
  end
61
65
 
62
66
  class PhysicsBodyData < FFI::Struct
63
67
  layout(
64
- :id, :uint,
65
- :enabled, :bool,
66
- :position, Vector2,
67
- :velocity, Vector2,
68
- :force, Vector2,
69
- :angularVelocity, :float,
70
- :torque, :float,
71
- :orient, :float,
72
- :inertia, :float,
73
- :inverseInertia, :float,
74
- :mass, :float,
75
- :inverseMass, :float,
76
- :staticFriction, :float,
77
- :dynamicFriction, :float,
78
- :restitution, :float,
79
- :useGravity, :bool,
80
- :isGrounded, :bool,
81
- :freezeOrient, :bool,
82
- :shape, PhysicsShape,
68
+ :id, :uint, # Unique identifier
69
+ :enabled, :bool, # Enabled dynamics state (collisions are calculated anyway)
70
+ :position, Vector2, # Physics body shape pivot
71
+ :velocity, Vector2, # Current linear velocity applied to position
72
+ :force, Vector2, # Current linear force (reset to 0 every step)
73
+ :angularVelocity, :float, # Current angular velocity applied to orient
74
+ :torque, :float, # Current angular force (reset to 0 every step)
75
+ :orient, :float, # Rotation in radians
76
+ :inertia, :float, # Moment of inertia
77
+ :inverseInertia, :float, # Inverse value of inertia
78
+ :mass, :float, # Physics body mass
79
+ :inverseMass, :float, # Inverse value of mass
80
+ :staticFriction, :float, # Friction when the body has not movement (0 to 1)
81
+ :dynamicFriction, :float, # Friction when the body has movement (0 to 1)
82
+ :restitution, :float, # Restitution coefficient of the body (0 to 1)
83
+ :useGravity, :bool, # Apply gravity force to dynamics
84
+ :isGrounded, :bool, # Physics grounded on other body state
85
+ :freezeOrient, :bool, # Physics rotation constraint
86
+ :shape, PhysicsShape, # Physics body shape information (type, radius, vertices, transform)
83
87
  )
84
88
  end
85
89
 
86
90
  class PhysicsManifoldData < FFI::Struct
87
91
  layout(
88
- :id, :uint,
89
- :bodyA, :pointer,
90
- :bodyB, :pointer,
91
- :penetration, :float,
92
- :normal, Vector2,
93
- :contacts, [Vector2, 2],
94
- :contactsCount, :uint,
95
- :restitution, :float,
96
- :dynamicFriction, :float,
97
- :staticFriction, :float,
92
+ :id, :uint, # Unique identifier
93
+ :bodyA, :pointer, # Manifold first physics body reference
94
+ :bodyB, :pointer, # Manifold second physics body reference
95
+ :penetration, :float, # Depth of penetration from collision
96
+ :normal, Vector2, # Normal direction vector from 'a' to 'b'
97
+ :contacts, [Vector2, 2], # Points of contact during collision
98
+ :contactsCount, :uint, # Current collision number of contacts
99
+ :restitution, :float, # Mixed restitution during collision
100
+ :dynamicFriction, :float, # Mixed dynamic friction during collision
101
+ :staticFriction, :float, # Mixed static friction during collision
98
102
  )
99
103
  end
100
104
 
101
105
 
102
106
  # Function
103
107
 
104
- def self.setup_physac_symbols()
105
- symbols = [
106
- :InitPhysics,
107
- :UpdatePhysics,
108
- :ResetPhysics,
109
- :ClosePhysics,
110
- :SetPhysicsTimeStep,
111
- :SetPhysicsGravity,
112
- :CreatePhysicsBodyCircle,
113
- :CreatePhysicsBodyRectangle,
114
- :CreatePhysicsBodyPolygon,
115
- :DestroyPhysicsBody,
116
- :PhysicsAddForce,
117
- :PhysicsAddTorque,
118
- :PhysicsShatter,
119
- :SetPhysicsBodyRotation,
120
- :GetPhysicsBody,
121
- :GetPhysicsBodiesCount,
122
- :GetPhysicsShapeType,
123
- :GetPhysicsShapeVerticesCount,
124
- :GetPhysicsShapeVertex,
108
+ def self.setup_physac_symbols
109
+ entries = [
110
+
111
+ # InitPhysics : Initializes physics system
112
+ # @return [void]
113
+ [:InitPhysics, :InitPhysics, [], :void],
114
+
115
+ # UpdatePhysics : Update physics system
116
+ # @return [void]
117
+ [:UpdatePhysics, :UpdatePhysics, [], :void],
118
+
119
+ # ResetPhysics : Reset physics system (global variables)
120
+ # @return [void]
121
+ [:ResetPhysics, :ResetPhysics, [], :void],
122
+
123
+ # ClosePhysics : Close physics system and unload used memory
124
+ # @return [void]
125
+ [:ClosePhysics, :ClosePhysics, [], :void],
126
+
127
+ # SetPhysicsTimeStep : Sets physics fixed time step in milliseconds. 1.666666 by default
128
+ # @param delta [double]
129
+ # @return [void]
130
+ [:SetPhysicsTimeStep, :SetPhysicsTimeStep, [:double], :void],
131
+
132
+ # SetPhysicsGravity : Sets physics global gravity force
133
+ # @param x [float]
134
+ # @param y [float]
135
+ # @return [void]
136
+ [:SetPhysicsGravity, :SetPhysicsGravity, [:float, :float], :void],
137
+
138
+ # CreatePhysicsBodyCircle : Creates a new circle physics body with generic parameters
139
+ # @param pos [Vector2]
140
+ # @param radius [float]
141
+ # @param density [float]
142
+ # @return [PhysicsBody]
143
+ [:CreatePhysicsBodyCircle, :CreatePhysicsBodyCircle, [Vector2.by_value, :float, :float], :pointer],
144
+
145
+ # CreatePhysicsBodyRectangle : Creates a new rectangle physics body with generic parameters
146
+ # @param pos [Vector2]
147
+ # @param width [float]
148
+ # @param height [float]
149
+ # @param density [float]
150
+ # @return [PhysicsBody]
151
+ [:CreatePhysicsBodyRectangle, :CreatePhysicsBodyRectangle, [Vector2.by_value, :float, :float, :float], :pointer],
152
+
153
+ # CreatePhysicsBodyPolygon : Creates a new polygon physics body with generic parameters
154
+ # @param pos [Vector2]
155
+ # @param radius [float]
156
+ # @param sides [int]
157
+ # @param density [float]
158
+ # @return [PhysicsBody]
159
+ [:CreatePhysicsBodyPolygon, :CreatePhysicsBodyPolygon, [Vector2.by_value, :float, :int, :float], :pointer],
160
+
161
+ # DestroyPhysicsBody : Destroy a physics body
162
+ # @param body [PhysicsBody]
163
+ # @return [void]
164
+ [:DestroyPhysicsBody, :DestroyPhysicsBody, [:pointer], :void],
165
+
166
+ # PhysicsAddForce : Adds a force to a physics body
167
+ # @param body [PhysicsBody]
168
+ # @param force [Vector2]
169
+ # @return [void]
170
+ [:PhysicsAddForce, :PhysicsAddForce, [:pointer, Vector2.by_value], :void],
171
+
172
+ # PhysicsAddTorque : Adds an angular force to a physics body
173
+ # @param body [PhysicsBody]
174
+ # @param amount [float]
175
+ # @return [void]
176
+ [:PhysicsAddTorque, :PhysicsAddTorque, [:pointer, :float], :void],
177
+
178
+ # PhysicsShatter : Shatters a polygon shape physics body to little physics bodies with explosion force
179
+ # @param body [PhysicsBody]
180
+ # @param position [Vector2]
181
+ # @param force [float]
182
+ # @return [void]
183
+ [:PhysicsShatter, :PhysicsShatter, [:pointer, Vector2.by_value, :float], :void],
184
+
185
+ # SetPhysicsBodyRotation : Sets physics body shape transform based on radians parameter
186
+ # @param body [PhysicsBody]
187
+ # @param radians [float]
188
+ # @return [void]
189
+ [:SetPhysicsBodyRotation, :SetPhysicsBodyRotation, [:pointer, :float], :void],
190
+
191
+ # GetPhysicsBody : Returns a physics body of the bodies pool at a specific index
192
+ # @param index [int]
193
+ # @return [PhysicsBody]
194
+ [:GetPhysicsBody, :GetPhysicsBody, [:int], :pointer],
195
+
196
+ # GetPhysicsBodiesCount : Returns the current amount of created physics bodies
197
+ # @return [int]
198
+ [:GetPhysicsBodiesCount, :GetPhysicsBodiesCount, [], :int],
199
+
200
+ # GetPhysicsShapeType : Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
201
+ # @param index [int]
202
+ # @return [int]
203
+ [:GetPhysicsShapeType, :GetPhysicsShapeType, [:int], :int],
204
+
205
+ # GetPhysicsShapeVerticesCount : Returns the amount of vertices of a physics body shape
206
+ # @param index [int]
207
+ # @return [int]
208
+ [:GetPhysicsShapeVerticesCount, :GetPhysicsShapeVerticesCount, [:int], :int],
209
+
210
+ # GetPhysicsShapeVertex : Returns transformed position of a body shape (body position + vertex transformed position)
211
+ # @param body [PhysicsBody]
212
+ # @param vertex [int]
213
+ # @return [Vector2]
214
+ [:GetPhysicsShapeVertex, :GetPhysicsShapeVertex, [:pointer, :int], Vector2.by_value],
125
215
  ]
126
- args = {
127
- :InitPhysics => [],
128
- :UpdatePhysics => [],
129
- :ResetPhysics => [],
130
- :ClosePhysics => [],
131
- :SetPhysicsTimeStep => [:double],
132
- :SetPhysicsGravity => [:float, :float],
133
- :CreatePhysicsBodyCircle => [Vector2.by_value, :float, :float],
134
- :CreatePhysicsBodyRectangle => [Vector2.by_value, :float, :float, :float],
135
- :CreatePhysicsBodyPolygon => [Vector2.by_value, :float, :int, :float],
136
- :DestroyPhysicsBody => [:pointer],
137
- :PhysicsAddForce => [:pointer, Vector2.by_value],
138
- :PhysicsAddTorque => [:pointer, :float],
139
- :PhysicsShatter => [:pointer, Vector2.by_value, :float],
140
- :SetPhysicsBodyRotation => [:pointer, :float],
141
- :GetPhysicsBody => [:int],
142
- :GetPhysicsBodiesCount => [],
143
- :GetPhysicsShapeType => [:int],
144
- :GetPhysicsShapeVerticesCount => [:int],
145
- :GetPhysicsShapeVertex => [:pointer, :int],
146
- }
147
- retvals = {
148
- :InitPhysics => :void,
149
- :UpdatePhysics => :void,
150
- :ResetPhysics => :void,
151
- :ClosePhysics => :void,
152
- :SetPhysicsTimeStep => :void,
153
- :SetPhysicsGravity => :void,
154
- :CreatePhysicsBodyCircle => :pointer,
155
- :CreatePhysicsBodyRectangle => :pointer,
156
- :CreatePhysicsBodyPolygon => :pointer,
157
- :DestroyPhysicsBody => :void,
158
- :PhysicsAddForce => :void,
159
- :PhysicsAddTorque => :void,
160
- :PhysicsShatter => :void,
161
- :SetPhysicsBodyRotation => :void,
162
- :GetPhysicsBody => :pointer,
163
- :GetPhysicsBodiesCount => :int,
164
- :GetPhysicsShapeType => :int,
165
- :GetPhysicsShapeVerticesCount => :int,
166
- :GetPhysicsShapeVertex => Vector2.by_value,
167
- }
168
- symbols.each do |sym|
169
- begin
170
- attach_function sym, args[sym], retvals[sym]
171
- rescue FFI::NotFoundError => error
172
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
173
- end
216
+ entries.each do |entry|
217
+ attach_function entry[0], entry[1], entry[2], entry[3]
218
+ rescue FFI::NotFoundError => e
219
+ warn "[Warning] Failed to import #{entry[0]} (#{e})."
174
220
  end
175
221
  end
176
-
177
222
  end
178
-
data/lib/raygui.dll CHANGED
Binary file