raylib-bindings 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/raylib.rb CHANGED
@@ -1,154 +1,154 @@
1
- # Yet another raylib wrapper for Ruby
2
- #
3
- # * https://github.com/vaiorabbit/raylib-bindings
4
-
5
- require 'ffi'
6
- require_relative 'raylib_main.rb'
7
- require_relative 'raymath.rb'
8
- require_relative 'rlgl.rb'
9
- require_relative 'raygui.rb'
10
- require_relative 'physac.rb'
11
-
12
- module Raylib
13
-
14
- extend FFI::Library
15
-
16
- @@raylib_import_done = false
17
- def self.load_lib(libpath, raygui_libpath: nil, physac_libpath: nil)
18
-
19
- unless @@raylib_import_done
20
- begin
21
- lib_paths = [libpath, raygui_libpath, physac_libpath].compact
22
-
23
- ffi_lib_flags :now, :global
24
- ffi_lib *lib_paths
25
- setup_symbols()
26
-
27
- setup_raygui_symbols() if raygui_libpath != nil
28
- setup_physac_symbols() if physac_libpath != nil
29
- rescue => error
30
- puts error
31
- end
32
- end
33
-
34
- end
35
-
36
- def self.setup_symbols()
37
- setup_raylib_symbols()
38
- setup_raymath_symbols()
39
- setup_rlgl_symbols()
40
- end
41
-
42
- #
43
- # Color helper
44
- #
45
-
46
- def Color.from_u8(r = 0, g = 0, b = 0, a = 255)
47
- instance = Color.new
48
- instance[:r] = r
49
- instance[:g] = g
50
- instance[:b] = b
51
- instance[:a] = a
52
- return instance
53
- end
54
-
55
- LIGHTGRAY = Color.from_u8(200, 200, 200, 255)
56
- GRAY = Color.from_u8(130, 130, 130, 255)
57
- DARKGRAY = Color.from_u8(80, 80, 80, 255)
58
- YELLOW = Color.from_u8(253, 249, 0, 255)
59
- GOLD = Color.from_u8(255, 203, 0, 255)
60
- ORANGE = Color.from_u8(255, 161, 0, 255)
61
- PINK = Color.from_u8(255, 109, 194, 255)
62
- RED = Color.from_u8(230, 41, 55, 255)
63
- MAROON = Color.from_u8(190, 33, 55, 255)
64
- GREEN = Color.from_u8(0, 228, 48, 255)
65
- LIME = Color.from_u8(0, 158, 47, 255)
66
- DARKGREEN = Color.from_u8(0, 117, 44, 255)
67
- SKYBLUE = Color.from_u8(102, 191, 255, 255)
68
- BLUE = Color.from_u8(0, 121, 241, 255)
69
- DARKBLUE = Color.from_u8(0, 82, 172, 255)
70
- PURPLE = Color.from_u8(200, 122, 255, 255)
71
- VIOLET = Color.from_u8(135, 60, 190, 255)
72
- DARKPURPLE = Color.from_u8(112, 31, 126, 255)
73
- BEIGE = Color.from_u8(211, 176, 131, 255)
74
- BROWN = Color.from_u8(127, 106, 79, 255)
75
- DARKBROWN = Color.from_u8(76, 63, 47, 255)
76
-
77
- WHITE = Color.from_u8(255, 255, 255, 255)
78
- BLACK = Color.from_u8(0, 0, 0, 255)
79
- BLANK = Color.from_u8(0, 0, 0, 0)
80
- MAGENTA = Color.from_u8(255, 0, 255, 255)
81
- RAYWHITE = Color.from_u8(245, 245, 245, 255)
82
-
83
- #
84
- # Math helper
85
- #
86
-
87
- def Vector2.create(x = 0, y = 0)
88
- instance = Vector2.new
89
- instance[:x] = x
90
- instance[:y] = y
91
- return instance
92
- end
93
-
94
- def Vector3.create(x = 0, y = 0, z = 0)
95
- instance = Vector3.new
96
- instance[:x] = x
97
- instance[:y] = y
98
- instance[:z] = z
99
- return instance
100
- end
101
-
102
- def Vector4.create(x = 0, y = 0, z = 0, w = 0)
103
- instance = Vector4.new
104
- instance[:x] = x
105
- instance[:y] = y
106
- instance[:z] = z
107
- instance[:w] = w
108
- return instance
109
- end
110
-
111
- def Quaternion.create(x = 0, y = 0, z = 0, w = 0)
112
- instance = Quaternion.new
113
- instance[:x] = x
114
- instance[:y] = y
115
- instance[:z] = z
116
- instance[:w] = w
117
- return instance
118
- end
119
-
120
- def Rectangle.create(x = 0, y = 0, width = 0, height = 0)
121
- instance = Rectangle.new
122
- instance[:x] = x
123
- instance[:y] = y
124
- instance[:width] = width
125
- instance[:height] = height
126
- return instance
127
- end
128
-
129
- def BoundingBox.create(*args)
130
- case args.size
131
- when 2
132
- instance = BoundingBox.new
133
- instance[:min] = args[0] # min
134
- instance[:max] = args[1] # max
135
- return instance
136
- when 6
137
- instance = BoundingBox.new
138
- instance[:min] = Vector3.create(args[0], args[1], args[2]) # min_x, min_y, min_z
139
- instance[:max] = Vector3.create(args[3], args[4], args[5]) # max_x, max_y, max_z
140
- return instance
141
- else
142
- raise ArgumentError.new "BoundingBox.create : Number of arguments must be 2 or 6"
143
- end
144
- end
145
-
146
- def Vector3ToFloat(v)
147
- return Vector3ToFloatV(mat)[:v].to_a
148
- end
149
-
150
- def MatrixToFloat(mat)
151
- return MatrixToFloatV(mat)[:v].to_a
152
- end
153
-
154
- end
1
+ # Yet another raylib wrapper for Ruby
2
+ #
3
+ # * https://github.com/vaiorabbit/raylib-bindings
4
+
5
+ require 'ffi'
6
+ require_relative 'raylib_main.rb'
7
+ require_relative 'raymath.rb'
8
+ require_relative 'rlgl.rb'
9
+ require_relative 'raygui.rb'
10
+ require_relative 'physac.rb'
11
+
12
+ module Raylib
13
+
14
+ extend FFI::Library
15
+
16
+ @@raylib_import_done = false
17
+ def self.load_lib(libpath, raygui_libpath: nil, physac_libpath: nil)
18
+
19
+ unless @@raylib_import_done
20
+ begin
21
+ lib_paths = [libpath, raygui_libpath, physac_libpath].compact
22
+
23
+ ffi_lib_flags :now, :global
24
+ ffi_lib *lib_paths
25
+ setup_symbols()
26
+
27
+ setup_raygui_symbols() if raygui_libpath != nil
28
+ setup_physac_symbols() if physac_libpath != nil
29
+ rescue => error
30
+ puts error
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ def self.setup_symbols()
37
+ setup_raylib_symbols()
38
+ setup_raymath_symbols()
39
+ setup_rlgl_symbols()
40
+ end
41
+
42
+ #
43
+ # Color helper
44
+ #
45
+
46
+ def Color.from_u8(r = 0, g = 0, b = 0, a = 255)
47
+ instance = Color.new
48
+ instance[:r] = r
49
+ instance[:g] = g
50
+ instance[:b] = b
51
+ instance[:a] = a
52
+ return instance
53
+ end
54
+
55
+ LIGHTGRAY = Color.from_u8(200, 200, 200, 255)
56
+ GRAY = Color.from_u8(130, 130, 130, 255)
57
+ DARKGRAY = Color.from_u8(80, 80, 80, 255)
58
+ YELLOW = Color.from_u8(253, 249, 0, 255)
59
+ GOLD = Color.from_u8(255, 203, 0, 255)
60
+ ORANGE = Color.from_u8(255, 161, 0, 255)
61
+ PINK = Color.from_u8(255, 109, 194, 255)
62
+ RED = Color.from_u8(230, 41, 55, 255)
63
+ MAROON = Color.from_u8(190, 33, 55, 255)
64
+ GREEN = Color.from_u8(0, 228, 48, 255)
65
+ LIME = Color.from_u8(0, 158, 47, 255)
66
+ DARKGREEN = Color.from_u8(0, 117, 44, 255)
67
+ SKYBLUE = Color.from_u8(102, 191, 255, 255)
68
+ BLUE = Color.from_u8(0, 121, 241, 255)
69
+ DARKBLUE = Color.from_u8(0, 82, 172, 255)
70
+ PURPLE = Color.from_u8(200, 122, 255, 255)
71
+ VIOLET = Color.from_u8(135, 60, 190, 255)
72
+ DARKPURPLE = Color.from_u8(112, 31, 126, 255)
73
+ BEIGE = Color.from_u8(211, 176, 131, 255)
74
+ BROWN = Color.from_u8(127, 106, 79, 255)
75
+ DARKBROWN = Color.from_u8(76, 63, 47, 255)
76
+
77
+ WHITE = Color.from_u8(255, 255, 255, 255)
78
+ BLACK = Color.from_u8(0, 0, 0, 255)
79
+ BLANK = Color.from_u8(0, 0, 0, 0)
80
+ MAGENTA = Color.from_u8(255, 0, 255, 255)
81
+ RAYWHITE = Color.from_u8(245, 245, 245, 255)
82
+
83
+ #
84
+ # Math helper
85
+ #
86
+
87
+ def Vector2.create(x = 0, y = 0)
88
+ instance = Vector2.new
89
+ instance[:x] = x
90
+ instance[:y] = y
91
+ return instance
92
+ end
93
+
94
+ def Vector3.create(x = 0, y = 0, z = 0)
95
+ instance = Vector3.new
96
+ instance[:x] = x
97
+ instance[:y] = y
98
+ instance[:z] = z
99
+ return instance
100
+ end
101
+
102
+ def Vector4.create(x = 0, y = 0, z = 0, w = 0)
103
+ instance = Vector4.new
104
+ instance[:x] = x
105
+ instance[:y] = y
106
+ instance[:z] = z
107
+ instance[:w] = w
108
+ return instance
109
+ end
110
+
111
+ def Quaternion.create(x = 0, y = 0, z = 0, w = 0)
112
+ instance = Quaternion.new
113
+ instance[:x] = x
114
+ instance[:y] = y
115
+ instance[:z] = z
116
+ instance[:w] = w
117
+ return instance
118
+ end
119
+
120
+ def Rectangle.create(x = 0, y = 0, width = 0, height = 0)
121
+ instance = Rectangle.new
122
+ instance[:x] = x
123
+ instance[:y] = y
124
+ instance[:width] = width
125
+ instance[:height] = height
126
+ return instance
127
+ end
128
+
129
+ def BoundingBox.create(*args)
130
+ case args.size
131
+ when 2
132
+ instance = BoundingBox.new
133
+ instance[:min] = args[0] # min
134
+ instance[:max] = args[1] # max
135
+ return instance
136
+ when 6
137
+ instance = BoundingBox.new
138
+ instance[:min] = Vector3.create(args[0], args[1], args[2]) # min_x, min_y, min_z
139
+ instance[:max] = Vector3.create(args[3], args[4], args[5]) # max_x, max_y, max_z
140
+ return instance
141
+ else
142
+ raise ArgumentError.new "BoundingBox.create : Number of arguments must be 2 or 6"
143
+ end
144
+ end
145
+
146
+ def Vector3ToFloat(v)
147
+ return Vector3ToFloatV(mat)[:v].to_a
148
+ end
149
+
150
+ def MatrixToFloat(mat)
151
+ return MatrixToFloatV(mat)[:v].to_a
152
+ end
153
+
154
+ end