raylib-bindings 0.0.10 → 0.1.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.
data/README.md CHANGED
@@ -1,122 +1,143 @@
1
- <!-- -*- mode:markdown; coding:utf-8; -*- -->
2
-
3
- # Yet another raylib wrapper for Ruby #
4
-
5
- * Created : 2021-10-17
6
- * Last modified : 2022-08-12
7
-
8
- Provides Ruby bindings for raylib-related libraries including:
9
-
10
- * [raylib](https://github.com/raysan5/raylib)
11
- * raylib
12
- * raymath
13
- * rlgl
14
- * [raygui](https://github.com/raysan5/raygui)
15
- * [Physac](https://github.com/raysan5/physac)
16
-
17
- ## Features ##
18
-
19
- * Generated semi-automatically
20
- * Based on Ruby/FFI
21
- * No need to build C extension library
22
-
23
- ## Prerequisites ##
24
-
25
- * Ruby interpreter
26
- * Tested on:
27
- * [macOS]
28
- * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
29
- * [Windows] https://rubyinstaller.org/downloads/ Ruby+Devkit
30
- * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
31
-
32
- * Compiler
33
- * Tested on:
34
- * [macOS] clang
35
-
36
- $ clang --version
37
- Apple clang version 13.1.6 (clang-1316.0.21.2.5)
38
- Target: arm64-apple-darwin21.5.0
39
- Thread model: posix
40
- InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
41
-
42
- * [Windows] gcc
43
-
44
- gcc (Rev10, Built by MSYS2 project) 11.2.0
45
-
46
- * CMake https://cmake.org/download/
47
-
48
- <details>
49
- <summary>Older versions</summary>
50
-
51
- * Ruby interpreter
52
- * Tested on:
53
- * [macOS]
54
- * ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin20]
55
- * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]
56
- * [Windows] https://rubyinstaller.org/downloads/ Ruby+Devkit
57
- * ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x64-mingw-ucrt]
58
- * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x64-mingw32]
59
-
60
- * Compiler
61
- * Tested on:
62
- * [macOS] clang
63
-
64
- $ clang --version
65
- Apple clang version 13.1.6 (clang-1316.0.21.2.3)
66
- Target: arm64-apple-darwin21.5.0
67
- Thread model: posix
68
- InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
69
-
70
- Apple clang version 13.0.0 (clang-1300.0.29.3)
71
- Target: arm64-apple-darwin20.6.0
72
- Thread model: posix
73
- InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
74
-
75
- * [Windows] gcc
76
-
77
- gcc (Rev9, Built by MSYS2 project) 11.2.0
78
-
79
- </details>
80
-
81
- ## Limitation ##
82
-
83
- * `SetTraceLogCallback` and `TraceLogCallback` are unusable since Ruby-FFI does not support `:varargs` parameter in callbacks (`Proc`, etc.)
84
- * Ref.: https://ffi.github.io/ruby-ffi-archive/messages/20130214-%5Bruby-ffi%5D%20Re_%20Callback%20Function%20with%20varargs-345.html
85
-
86
- ## License ##
87
-
88
- Shared libraries in `lib` directory are built on top of these products and are available under the terms of these licenses:
89
-
90
- * `libraylib.dylib`, `libraylib.dll`
91
- * raylib ( https://github.com/raysan5/raylib )
92
- * https://github.com/raysan5/raylib/blob/master/LICENSE
93
- * `raygui.dylib`, `raygui.dll`
94
- * raygui ( https://github.com/raysan5/raygui )
95
- * https://github.com/raysan5/raygui/blob/master/LICENSE
96
- * `physac.dylib`, `physac.dll`
97
- * Physac ( https://github.com/raysan5/physac )
98
- * https://github.com/raysan5/physac/blob/4a8e17f263fb8e1150b3fbafc96f880c7d7a4833/src/physac.h#L51-L68
99
-
100
- All ruby codes here are available under the terms of the zlib/libpng License ( http://opensource.org/licenses/Zlib ).
101
-
102
- Ruby-raylib : Yet another raylib wrapper for Ruby
103
- Copyright (c) 2021-2022 vaiorabbit <http://twitter.com/vaiorabbit>
104
-
105
- This software is provided 'as-is', without any express or implied
106
- warranty. In no event will the authors be held liable for any damages
107
- arising from the use of this software.
108
-
109
- Permission is granted to anyone to use this software for any purpose,
110
- including commercial applications, and to alter it and redistribute it
111
- freely, subject to the following restrictions:
112
-
113
- 1. The origin of this software must not be misrepresented; you must not
114
- claim that you wrote the original software. If you use this software
115
- in a product, an acknowledgment in the product documentation would be
116
- appreciated but is not required.
117
-
118
- 2. Altered source versions must be plainly marked as such, and must not be
119
- misrepresented as being the original software.
120
-
121
- 3. This notice may not be removed or altered from any source
122
- distribution.
1
+ <!-- -*- mode:markdown; coding:utf-8; -*- -->
2
+
3
+ # Yet another raylib wrapper for Ruby #
4
+
5
+ * Created : 2021-10-17
6
+ * Last modified : 2022-08-28
7
+
8
+ Provides Ruby bindings for raylib-related libraries including:
9
+
10
+ * [raylib](https://github.com/raysan5/raylib)
11
+ * raylib
12
+ * raymath
13
+ * rlgl
14
+ * [raygui](https://github.com/raysan5/raygui)
15
+ * [Physac](https://github.com/raysan5/physac)
16
+
17
+ ## Features ##
18
+
19
+ * Generated semi-automatically
20
+ * Based on Ruby/FFI
21
+ * No need to build C extension library
22
+
23
+ ## Quick Start ##
24
+
25
+ For Windows and macOS users:
26
+
27
+ ```
28
+ D:\> gem install raylib-bindings
29
+ Fetching raylib-bindings-...
30
+ ...
31
+ 1 gem installed
32
+
33
+ D:\> ruby -r raylib -e 'Raylib.template'
34
+ [Info] Raylib.template : C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/raylib-bindings-0.0.11/examples/template.rb => d://template.rb
35
+ [Info] Raylib.template : Done
36
+
37
+ D:\> ruby template.rb
38
+ ```
39
+
40
+
41
+ <img src="https://raw.githubusercontent.com/vaiorabbit/raylib-bindings/main/doc/template_screenshot.png" width="400">
42
+
43
+ ## Prerequisites ##
44
+
45
+ * Ruby interpreter
46
+ * Tested on:
47
+ * [macOS]
48
+ * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
49
+ * [Windows] https://rubyinstaller.org/downloads/ Ruby+Devkit
50
+ * ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
51
+
52
+ * If you need to build DLLs/shared libralies for your own runtime envrioenment (Linux, etc.):
53
+ * CMake https://cmake.org/download/
54
+ * C Compiler
55
+ * Tested compilers:
56
+ * [macOS] clang
57
+
58
+ $ clang --version
59
+ Apple clang version 13.1.6 (clang-1316.0.21.2.5)
60
+ Target: arm64-apple-darwin21.5.0
61
+ Thread model: posix
62
+ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
63
+
64
+ * [Windows] gcc
65
+
66
+ gcc (Rev10, Built by MSYS2 project) 11.2.0
67
+
68
+
69
+ <details>
70
+ <summary>Older versions</summary>
71
+
72
+ * Ruby interpreter
73
+ * Tested on:
74
+ * [macOS]
75
+ * ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin20]
76
+ * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]
77
+ * [Windows] https://rubyinstaller.org/downloads/ Ruby+Devkit
78
+ * ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x64-mingw-ucrt]
79
+ * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x64-mingw32]
80
+
81
+ * Compiler
82
+ * Tested on:
83
+ * [macOS] clang
84
+
85
+ $ clang --version
86
+ Apple clang version 13.1.6 (clang-1316.0.21.2.3)
87
+ Target: arm64-apple-darwin21.5.0
88
+ Thread model: posix
89
+ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
90
+
91
+ Apple clang version 13.0.0 (clang-1300.0.29.3)
92
+ Target: arm64-apple-darwin20.6.0
93
+ Thread model: posix
94
+ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
95
+
96
+ * [Windows] gcc
97
+
98
+ gcc (Rev9, Built by MSYS2 project) 11.2.0
99
+
100
+ </details>
101
+
102
+ ## Limitation ##
103
+
104
+ * `SetTraceLogCallback` and `TraceLogCallback` are unusable since Ruby-FFI does not support `:varargs` parameter in callbacks (`Proc`, etc.)
105
+ * Ref.: https://ffi.github.io/ruby-ffi-archive/messages/20130214-%5Bruby-ffi%5D%20Re_%20Callback%20Function%20with%20varargs-345.html
106
+
107
+ ## License ##
108
+
109
+ Shared libraries in `lib` directory are built on top of these products and are available under the terms of these licenses:
110
+
111
+ * `libraylib.dylib`, `libraylib.dll`
112
+ * raylib ( https://github.com/raysan5/raylib )
113
+ * https://github.com/raysan5/raylib/blob/master/LICENSE
114
+ * `raygui.dylib`, `raygui.dll`
115
+ * raygui ( https://github.com/raysan5/raygui )
116
+ * https://github.com/raysan5/raygui/blob/master/LICENSE
117
+ * `physac.dylib`, `physac.dll`
118
+ * Physac ( https://github.com/raysan5/physac )
119
+ * https://github.com/raysan5/physac/blob/4a8e17f263fb8e1150b3fbafc96f880c7d7a4833/src/physac.h#L51-L68
120
+
121
+ All ruby codes here are available under the terms of the zlib/libpng License ( http://opensource.org/licenses/Zlib ).
122
+
123
+ Ruby-raylib : Yet another raylib wrapper for Ruby
124
+ Copyright (c) 2021-2022 vaiorabbit <http://twitter.com/vaiorabbit>
125
+
126
+ This software is provided 'as-is', without any express or implied
127
+ warranty. In no event will the authors be held liable for any damages
128
+ arising from the use of this software.
129
+
130
+ Permission is granted to anyone to use this software for any purpose,
131
+ including commercial applications, and to alter it and redistribute it
132
+ freely, subject to the following restrictions:
133
+
134
+ 1. The origin of this software must not be misrepresented; you must not
135
+ claim that you wrote the original software. If you use this software
136
+ in a product, an acknowledgment in the product documentation would be
137
+ appreciated but is not required.
138
+
139
+ 2. Altered source versions must be plainly marked as such, and must not be
140
+ misrepresented as being the original software.
141
+
142
+ 3. This notice may not be removed or altered from any source
143
+ distribution.
@@ -0,0 +1,146 @@
1
+ # Yet another raylib wrapper for Ruby
2
+ #
3
+ # * https://github.com/vaiorabbit/raylib-bindings
4
+ #
5
+ # Demonstrates several key features including:
6
+ # * Core : window management, camera, etc.
7
+ # * Gameplay : fetching player input, collision handling, etc.
8
+ # * Rendering : drawing shapes, texts, etc.
9
+ #
10
+ # To get more information, see:
11
+ # * https://www.raylib.com/cheatsheet/cheatsheet.html for API reference
12
+ # * https://github.com/vaiorabbit/raylib-bindings/tree/main/examples for more actual codes written in Ruby
13
+
14
+ require 'raylib'
15
+
16
+ shared_lib_path = Gem::Specification.find_by_name('raylib-bindings').full_gem_path + '/lib/'
17
+
18
+ case RUBY_PLATFORM
19
+ when /mswin|msys|mingw|cygwin/
20
+ Raylib.load_lib(shared_lib_path + 'libraylib.dll', raygui_libpath: shared_lib_path + 'raygui.dll', physac_libpath: shared_lib_path + 'physac.dll')
21
+ when /darwin/
22
+ Raylib.load_lib(shared_lib_path + 'libraylib.dylib', raygui_libpath: shared_lib_path + 'raygui.dylib', physac_libpath: shared_lib_path + 'physac.dylib')
23
+ else
24
+ raise RuntimeError, "Unknown OS: #{RUBY_PLATFORM}"
25
+ end
26
+
27
+ include Raylib
28
+
29
+ if __FILE__ == $PROGRAM_NAME
30
+ screen_width = 1280
31
+ screen_height = 720
32
+ InitWindow(screen_width, screen_height, "Yet Another Ruby-raylib bindings")
33
+ SetTargetFPS(60)
34
+
35
+ ruby_red = Color.from_u8(155, 17, 30, 255)
36
+
37
+ # Camera
38
+ camera = Camera.new
39
+ 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
45
+ }
46
+ reset_camera.call
47
+ SetCameraMode(camera, CAMERA_FREE)
48
+ auto_rotate = false
49
+
50
+ # Player (red cube) settings
51
+ player_pos = Vector3.create(0.0, 0.0, 0.0)
52
+ player_size = Vector3.create(2.0, 2.0, 2.0)
53
+ speed = 0.25
54
+
55
+ # Obstacle settings
56
+ obstacle_cube_pos = Vector3.create(-4.0, 1.0, 0.0)
57
+ obstacle_cube_size = Vector3.create(2.0, 2.0, 2.0)
58
+ obstacle_sphere_pos = Vector3.create(4.0, 0.0, 0.0)
59
+ obstacle_sphere_size = 1.5
60
+
61
+ until WindowShouldClose()
62
+ ### Update phase
63
+
64
+ # Reset camera settings
65
+ if IsKeyPressed(KEY_F1)
66
+ auto_rotate = !auto_rotate
67
+ reset_camera.call
68
+ SetCameraMode(camera, auto_rotate ? CAMERA_ORBITAL : CAMERA_FREE)
69
+ end
70
+ UpdateCamera(camera)
71
+
72
+ # Calculate move direction
73
+ move = Vector3.create(0, 0, 0)
74
+ move[:x] += speed if IsKeyDown(KEY_RIGHT)
75
+ move[:x] -= speed if IsKeyDown(KEY_LEFT)
76
+ move[:z] += speed if IsKeyDown(KEY_DOWN)
77
+ move[:z] -= speed if IsKeyDown(KEY_UP)
78
+
79
+ to_camera = Vector3Normalize(Vector3.create(camera[:position][:x], 0, camera[:position][:z]))
80
+ rotate_y = QuaternionFromVector3ToVector3(Vector3.create(0, 0, 1), to_camera)
81
+ move = Vector3RotateByQuaternion(move, rotate_y)
82
+
83
+ 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)
85
+
86
+ # Check collision status
87
+ collision = false
88
+
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)
95
+
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)
102
+
103
+ # Check collisions player vs obstacle_cube
104
+ collision = true if CheckCollisionBoxes(player_bbox, obstacle_cube_bbox)
105
+
106
+ # Check collisions player vs obstacle_sphere
107
+ collision = true if CheckCollisionBoxSphere(player_bbox, obstacle_sphere_pos, obstacle_sphere_size)
108
+
109
+ ### Rendering phase
110
+
111
+ BeginDrawing()
112
+
113
+ ClearBackground(RAYWHITE)
114
+
115
+ ## 3D scene
116
+ BeginMode3D(camera)
117
+ # Red cube
118
+ DrawCube(player_pos, 2.0, 2.0, 2.0, collision ? Fade(ruby_red, 0.25) : ruby_red)
119
+ DrawCubeWires(player_pos, 2.0, 2.0, 2.0, MAROON)
120
+ # 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
+ # Obstacle sphere
124
+ DrawSphere(obstacle_sphere_pos, obstacle_sphere_size, GRAY)
125
+ DrawSphereWires(obstacle_sphere_pos, obstacle_sphere_size, 16, 16, DARKGRAY)
126
+ # Floor
127
+ DrawGrid(10, 1)
128
+ EndMode3D()
129
+
130
+ ## HUD
131
+ # 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)
133
+ # Help message
134
+ DrawRectangle(10, screen_height - 100, 300, 80, Fade(MAROON, 0.25))
135
+ DrawRectangleLines(10, screen_height - 100, 300, 80, ruby_red)
136
+ DrawText("Arrow keys : move red cube", 20, screen_height - 90, 20, BLACK)
137
+ DrawText("F1 : camera rotation", 20, screen_height - 70, 20, BLACK)
138
+ DrawText("ESC : exit", 20, screen_height - 50, 20, BLACK)
139
+ # FPS
140
+ DrawFPS(screen_width - 100, 16)
141
+
142
+ EndDrawing()
143
+ end
144
+
145
+ CloseWindow()
146
+ end
data/lib/libraylib.dylib CHANGED
File without changes
data/lib/physac.dylib CHANGED
File without changes