rubygl 0.1.0 → 0.2.1
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 +13 -5
- data/.travis/push-rdoc-to-gh-pages.sh +22 -0
- data/.travis.yml +18 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +12 -0
- data/LICENSE +21 -21
- data/README.md +40 -0
- data/Rakefile +98 -83
- data/bin/ffi_code_gen.rb +166 -166
- data/bin/gl_code_gen.rb +458 -458
- data/examples/faceted_example.rb +71 -64
- data/examples/instanced_example.rb +135 -127
- data/examples/phong_example.rb +80 -71
- data/ext/windows/RubyGL.so +0 -0
- data/lib/rubygl/event.rb +64 -0
- data/lib/{RubyGL → rubygl}/geometry.rb +216 -211
- data/lib/{RubyGL → rubygl}/math.rb +300 -300
- data/lib/{RubyGL → rubygl}/memory.rb +125 -121
- data/lib/rubygl/native/all_enums.rb +641 -0
- data/lib/{RubyGL/Native → rubygl/native}/glcontext.rb +23 -47
- data/lib/{RubyGL/Native → rubygl/native}/include/GLContext.h +36 -36
- data/lib/{RubyGL/Native → rubygl/native}/include/Input.h +15 -15
- data/lib/{RubyGL/Native → rubygl/native}/include/Window.h +27 -27
- data/lib/rubygl/native/input.rb +247 -0
- data/lib/{RubyGL/Native → rubygl/native}/opengl.rb +2808 -2032
- data/lib/{RubyGL/Native → rubygl/native}/src/GLContext.c +72 -72
- data/lib/{RubyGL/Native → rubygl/native}/src/Input.c +25 -25
- data/lib/{RubyGL/Native → rubygl/native}/src/Window.c +57 -57
- data/lib/{RubyGL/Native → rubygl/native}/window.rb +24 -24
- data/lib/{RubyGL → rubygl}/setup.rb +50 -50
- data/lib/{RubyGL → rubygl}/shader.rb +203 -203
- data/lib/{RubyGL → rubygl}/util.rb +77 -77
- data/lib/rubygl.rb +49 -48
- data/{RubyGL.gemspec → rubygl.gemspec} +20 -23
- data/test/test_util.rb +19 -0
- metadata +36 -33
- data/lib/RubyGL/Native/input.rb +0 -13
- data/lib/RubyGL/callback.rb +0 -10
@@ -1,212 +1,217 @@
|
|
1
|
-
require_relative './math'
|
2
|
-
require_relative './util'
|
3
|
-
|
4
|
-
module RubyGL
|
5
|
-
|
6
|
-
# All Point Operations Return New Points
|
7
|
-
class Point
|
8
|
-
attr_accessor :x, :y, :z
|
9
|
-
|
10
|
-
def initialize(x, y, z = 0)
|
11
|
-
@x = x
|
12
|
-
@y = y
|
13
|
-
@z = z
|
14
|
-
end
|
15
|
-
|
16
|
-
def +(point)
|
17
|
-
Point.new(@x + point.x, @y + point.y, @z + point.z)
|
18
|
-
end
|
19
|
-
|
20
|
-
def -(point)
|
21
|
-
Point.new(@x - point.x, @y - point.y, @z - point.z)
|
22
|
-
end
|
23
|
-
|
24
|
-
def
|
25
|
-
Point.new(@x *
|
26
|
-
end
|
27
|
-
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
previous_points
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
vertex_array.push([
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
vertex_array.push([lower_gird_center.to_a,
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
vertex_array.push([
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
1
|
+
require_relative './math'
|
2
|
+
require_relative './util'
|
3
|
+
|
4
|
+
module RubyGL
|
5
|
+
|
6
|
+
# All Point Operations Return New Points
|
7
|
+
class Point
|
8
|
+
attr_accessor :x, :y, :z
|
9
|
+
|
10
|
+
def initialize(x, y, z = 0)
|
11
|
+
@x = x
|
12
|
+
@y = y
|
13
|
+
@z = z
|
14
|
+
end
|
15
|
+
|
16
|
+
def +(point)
|
17
|
+
Point.new(@x + point.x, @y + point.y, @z + point.z)
|
18
|
+
end
|
19
|
+
|
20
|
+
def -(point)
|
21
|
+
Point.new(@x - point.x, @y - point.y, @z - point.z)
|
22
|
+
end
|
23
|
+
|
24
|
+
def *(point)
|
25
|
+
Point.new(@x * point.x, @y * point.y, @z * point.z)
|
26
|
+
end
|
27
|
+
|
28
|
+
def scale(value)
|
29
|
+
Point.new(@x * value, @y * value, @z * value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def distance(point)
|
33
|
+
temp = self - point
|
34
|
+
|
35
|
+
Math::sqrt(temp.x * temp.x + temp.y * temp.y + temp.z * temp.z)
|
36
|
+
end
|
37
|
+
|
38
|
+
def midpoint(point)
|
39
|
+
Point.new((@x + point.x) * 0.5, (@y + point.y) * 0.5, (@z + point.z) * 0.5)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_ary
|
43
|
+
[@x, @y, @z]
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_a
|
47
|
+
self.to_ary
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Class For Generating 2-D Shapes
|
52
|
+
class SimpleShape
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# Class For Generating 3-D Shapes
|
57
|
+
class ComplexShape
|
58
|
+
# Generates an array of 3 component vertices in counter-clockwise triangle
|
59
|
+
# configuration. This is the vertex data for a 3 dimensional sphere. The
|
60
|
+
# num_rings parameter should always be 0 or a positive even number.
|
61
|
+
def self.gen_sphere(radius, num_rings)
|
62
|
+
points_per_ring = num_rings * 2 + 4
|
63
|
+
rings_per_half = num_rings / 2 + 1 # Count The Center Ring For Both Sides
|
64
|
+
|
65
|
+
# Generate Points From Bottom Of Sphere To The Top
|
66
|
+
points = []
|
67
|
+
for i in 1..num_rings + 1
|
68
|
+
ring_y_factor = (i - rings_per_half).to_f / rings_per_half
|
69
|
+
ring_y_value = ring_y_factor * radius
|
70
|
+
ring_radius = Math::cos(Math::asin(ring_y_value / radius)) * radius
|
71
|
+
|
72
|
+
for i in 0..points_per_ring
|
73
|
+
radians = Conversion.deg_to_rad(i.to_f / points_per_ring * 360)
|
74
|
+
|
75
|
+
x = Math::cos(radians) * ring_radius
|
76
|
+
z = Math::sin(radians) * ring_radius
|
77
|
+
|
78
|
+
points.push(Point.new(x, ring_y_value, z))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
vertex_array, previous_points = [], []
|
83
|
+
|
84
|
+
# Build Bottom End-Cap
|
85
|
+
bottom_point = [0, -radius, 0]
|
86
|
+
for i in 0...points_per_ring
|
87
|
+
curr_vert = points[i]
|
88
|
+
next_vert = Util.overflow_wrap(points, i + 1)
|
89
|
+
|
90
|
+
vertex_array.push([curr_vert.to_a, next_vert.to_a, bottom_point])
|
91
|
+
previous_points.push(curr_vert)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Build Intermediate Mesh
|
95
|
+
for i in points_per_ring...points.size
|
96
|
+
curr_vert = points[i]
|
97
|
+
next_vert = Util.overflow_wrap(points, i + 1)
|
98
|
+
|
99
|
+
last_curr_vert = previous_points[i % points_per_ring]
|
100
|
+
last_next_vert = Util.overflow_wrap(previous_points, (i % points_per_ring) + 1)
|
101
|
+
|
102
|
+
vertex_array.push([curr_vert.to_a, next_vert.to_a, last_curr_vert.to_a])
|
103
|
+
vertex_array.push([next_vert.to_a, last_next_vert.to_a, last_curr_vert.to_a])
|
104
|
+
|
105
|
+
previous_points[i % points_per_ring] = curr_vert
|
106
|
+
end
|
107
|
+
|
108
|
+
# Build Top End-Cap
|
109
|
+
top_point = [0, radius, 0]
|
110
|
+
for i in 0...previous_points.size()
|
111
|
+
curr_vert = previous_points[i]
|
112
|
+
next_vert = Util.overflow_wrap(previous_points, i + 1)
|
113
|
+
|
114
|
+
vertex_array.push([next_vert.to_a, curr_vert.to_a, top_point.to_a])
|
115
|
+
end
|
116
|
+
|
117
|
+
vertex_array.flatten!
|
118
|
+
|
119
|
+
vertex_array
|
120
|
+
end
|
121
|
+
|
122
|
+
# Generates an array of 3 component vertices in counter-clockwise triangle
|
123
|
+
# configuration. This is the vertex data for a 3 dimensional diamond. The
|
124
|
+
# girdle_facets parameters should always be an even number.
|
125
|
+
def self.gen_diamond(diamond_height, girdle_radius, girdle_facets)
|
126
|
+
# Table Y Value Is Equal To diamond_height
|
127
|
+
girdle_y_value = diamond_height * 2.5 / 3.0 # Girdle Upper Ring
|
128
|
+
crown_y_midpoint = 2.0 / 3.0
|
129
|
+
|
130
|
+
girdle_thickness = diamond_height / 10.0
|
131
|
+
|
132
|
+
table_radius = girdle_radius / 1.8
|
133
|
+
table_facets = girdle_facets / 2.0
|
134
|
+
|
135
|
+
girdle_points = []
|
136
|
+
girdle_point_factor = 360.0 / girdle_facets # Multiply With Point Index To Get Degree
|
137
|
+
# Generate x And z Values For Diamond Girdle
|
138
|
+
for i in 0...girdle_facets
|
139
|
+
curr_degree = i.to_f * girdle_point_factor
|
140
|
+
curr_rad = Conversion::deg_to_rad(curr_degree)
|
141
|
+
|
142
|
+
x = Math::cos(curr_rad) * girdle_radius
|
143
|
+
z = Math::sin(curr_rad) * girdle_radius
|
144
|
+
|
145
|
+
girdle_points.push(Point.new(x, girdle_y_value, z))
|
146
|
+
end
|
147
|
+
|
148
|
+
table_points = []
|
149
|
+
table_point_factor = 360.0 / table_facets # Multiply With Point Index To Get Degree
|
150
|
+
# Generate x And z Values For Diamond Table
|
151
|
+
for i in 0...table_facets
|
152
|
+
curr_degree = i.to_f * table_point_factor
|
153
|
+
curr_rad = Conversion::deg_to_rad(curr_degree)
|
154
|
+
|
155
|
+
x = Math::cos(curr_rad) * table_radius
|
156
|
+
z = Math::sin(curr_rad) * table_radius
|
157
|
+
|
158
|
+
table_points.push(Point.new(x, diamond_height, z))
|
159
|
+
end
|
160
|
+
|
161
|
+
vertex_array = []
|
162
|
+
# Traverse Every Other Point On The Girdle
|
163
|
+
for i in 0...girdle_points.size / 2
|
164
|
+
center_girdle_index = (i * 2) + 1
|
165
|
+
left_girdle_index = center_girdle_index - 1
|
166
|
+
right_girdle_index = center_girdle_index + 1
|
167
|
+
|
168
|
+
gird_center = girdle_points[center_girdle_index]
|
169
|
+
gird_left = girdle_points[left_girdle_index]
|
170
|
+
gird_right = Util.overflow_wrap(girdle_points, right_girdle_index)
|
171
|
+
|
172
|
+
tab_left = table_points[left_girdle_index / 2]
|
173
|
+
tab_right = Util.overflow_wrap(table_points, right_girdle_index / 2)
|
174
|
+
|
175
|
+
# Crown Triangles
|
176
|
+
# Using 3D Equation Of A Line To Get Central Connection Point For Crown
|
177
|
+
slope = tab_left.midpoint(tab_right) - gird_center
|
178
|
+
crown_midpoint = slope.scale(crown_y_midpoint) + gird_center
|
179
|
+
|
180
|
+
vertex_array.push([gird_left.to_a, crown_midpoint.to_a, gird_center.to_a])
|
181
|
+
vertex_array.push([gird_center.to_a, crown_midpoint.to_a, gird_right.to_a])
|
182
|
+
|
183
|
+
vertex_array.push([tab_left.to_a, crown_midpoint.to_a, gird_left.to_a])
|
184
|
+
vertex_array.push([gird_right.to_a, crown_midpoint.to_a, tab_right.to_a])
|
185
|
+
|
186
|
+
vertex_array.push([tab_right.to_a, crown_midpoint.to_a, tab_left.to_a])
|
187
|
+
|
188
|
+
# Girdle Triangles
|
189
|
+
lower_gird_center = Point.new(gird_center.x, gird_center.y - girdle_thickness, gird_center.z)
|
190
|
+
lower_gird_left = Point.new(gird_left.x, gird_left.y - girdle_thickness, gird_left.z)
|
191
|
+
lower_gird_right = Point.new(gird_right.x, gird_right.y - girdle_thickness, gird_right.z)
|
192
|
+
|
193
|
+
vertex_array.push([gird_left.to_a, gird_center.to_a, lower_gird_left.to_a])
|
194
|
+
vertex_array.push([lower_gird_left.to_a, gird_center.to_a, lower_gird_center.to_a])
|
195
|
+
|
196
|
+
vertex_array.push([lower_gird_center.to_a, gird_center.to_a, gird_right.to_a])
|
197
|
+
vertex_array.push([lower_gird_center.to_a, gird_right.to_a, lower_gird_right.to_a])
|
198
|
+
|
199
|
+
# Pavilion Triangles
|
200
|
+
pavil_bottom = Point.new(0, 0, 0)
|
201
|
+
|
202
|
+
vertex_array.push([lower_gird_left.to_a, lower_gird_center.to_a, pavil_bottom.to_a])
|
203
|
+
vertex_array.push([pavil_bottom.to_a, lower_gird_center.to_a, lower_gird_right.to_a])
|
204
|
+
|
205
|
+
# Table Triangles
|
206
|
+
table_mid = Point.new(0, diamond_height, 0)
|
207
|
+
|
208
|
+
vertex_array.push([tab_left.to_a, table_mid.to_a, tab_right.to_a])
|
209
|
+
end
|
210
|
+
|
211
|
+
vertex_array.flatten!
|
212
|
+
|
213
|
+
vertex_array
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
212
217
|
end
|