rays 0.1.11 → 0.1.16

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.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/camera.cpp +88 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +22 -80
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +94 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +49 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +21 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +21 -0
  107. data/src/ios/bitmap.mm +129 -110
  108. data/src/ios/camera.mm +236 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +2 -2
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +21 -0
  119. data/src/osx/bitmap.mm +129 -110
  120. data/src/osx/camera.mm +236 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Polygon
11
+
12
+
13
+ class Line < Polyline
14
+
15
+ def initialize (*points, loop: true, hole: false)
16
+ setup points, loop, hole
17
+ end
18
+
19
+ def transform (matrix = nil, loop: loop?, hole: hole?, &block)
20
+ points = to_a
21
+ points = points.map {|point| matrix * point} if matrix
22
+ points = block.call points if block
23
+ self.class.new *points, loop: loop, hole: hole
24
+ end
25
+
26
+ def inspect ()
27
+ "#<Rays::Polygon::Line #{to_a.join ', '}, loop: #{loop?}, hole: #{hole?}>"
28
+ end
29
+
30
+ end# Line
31
+
32
+
33
+ end# Polygon
34
+
35
+
36
+ end# Rays
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Polyline
11
+
12
+ include Enumerable
13
+
14
+ def initialize (*points, loop: false)
15
+ setup points, loop
16
+ end
17
+
18
+ def transform (matrix = nil, loop: loop?, &block)
19
+ points = to_a
20
+ points = points.map {|point| matrix * point} if matrix
21
+ points = block.call points if block
22
+ self.class.new *points, loop: loop
23
+ end
24
+
25
+ def inspect ()
26
+ "#<Rays::Polyline #{to_a.join ', '}, loop: #{loop?}>"
27
+ end
28
+
29
+ end# Polyline
30
+
31
+
32
+ end# Rays
@@ -1,13 +1,32 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'xot/block_util'
4
5
  require 'rays/ext'
5
6
 
6
7
 
7
8
  module Rays
8
9
 
9
10
 
10
- #class Shader
11
+ class Shader
12
+
13
+ def initialize (source = nil, **uniforms, &block)
14
+ if source
15
+ setup source
16
+ uniform **uniforms unless uniforms.empty?
17
+ end
18
+
19
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
20
+ end
21
+
22
+ def uniform (name = nil, *args, **uniforms)
23
+ set_uniform name, *args if name
24
+ uniforms.each do |key, value|
25
+ set_uniform key, value
26
+ end
27
+ end
28
+
29
+ end# Shader
11
30
 
12
31
 
13
32
  end# Rays
@@ -21,17 +21,15 @@ Gem::Specification.new do |s|
21
21
  s.description = 'This library helps you to develop graphics application with OpenGL.'
22
22
  s.version = mod.version
23
23
 
24
- s.authors = %w[snori]
25
- s.email = 'snori@xord.org'
24
+ s.authors = %w[xordog]
25
+ s.email = 'xordog@gmail.com'
26
26
  s.homepage = "https://github.com/xord/rays"
27
27
 
28
28
  s.platform = Gem::Platform::RUBY
29
- s.required_ruby_version = '>=1.9.0'
29
+ s.required_ruby_version = '~> 2'
30
30
 
31
- s.add_runtime_dependency 'rake'
32
- s.add_runtime_dependency 'xot'
33
- s.add_runtime_dependency 'rucy'
34
- s.add_development_dependency 'gemcutter'
31
+ s.add_runtime_dependency 'xot', '~> 0.1'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1'
35
33
 
36
34
  s.files = `git ls-files`.split $/
37
35
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -0,0 +1,36 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_SRC_BITMAP_H__
4
+ #define __RAYS_SRC_BITMAP_H__
5
+
6
+
7
+ #include <rays/bitmap.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ class Texture;
15
+
16
+ class RawFont;
17
+
18
+
19
+ Bitmap Bitmap_from (const Texture& texture);
20
+
21
+ void Bitmap_draw_string (
22
+ Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y);
23
+
24
+ void Bitmap_set_modified (Bitmap* bitmap, bool modified = true);
25
+
26
+ bool Bitmap_get_modified (const Bitmap& bitmap);
27
+
28
+ void Bitmap_save (const Bitmap& bitmap, const char* path);
29
+
30
+ Bitmap Bitmap_load (const char* path);
31
+
32
+
33
+ }// Rays
34
+
35
+
36
+ #endif//EOH
@@ -1,6 +1,7 @@
1
1
  #include "rays/bounds.h"
2
2
 
3
3
 
4
+ #include <float.h>
4
5
  #include <algorithm>
5
6
  #include "rays/exception.h"
6
7
 
@@ -293,6 +294,22 @@ namespace Rays
293
294
  return z + d - 1;
294
295
  }
295
296
 
297
+ void
298
+ Bounds::set_position (coord x, coord y, coord z)
299
+ {
300
+ this->x = x;
301
+ this->y = y;
302
+ this->z = z;
303
+ }
304
+
305
+ void
306
+ Bounds::set_position (const Point& position)
307
+ {
308
+ x = position.x;
309
+ y = position.y;
310
+ z = position.z;
311
+ }
312
+
296
313
  Point&
297
314
  Bounds::position ()
298
315
  {
@@ -305,6 +322,20 @@ namespace Rays
305
322
  return const_cast<This*>(this)->position();
306
323
  }
307
324
 
325
+ void
326
+ Bounds::set_size (coord width, coord height, coord depth)
327
+ {
328
+ w = width;
329
+ h = height;
330
+ d = depth;
331
+ }
332
+
333
+ void
334
+ Bounds::set_size (const Point& size)
335
+ {
336
+ set_size(size.x, size.y, size.z);
337
+ }
338
+
308
339
  Point&
309
340
  Bounds::size ()
310
341
  {
@@ -326,9 +357,9 @@ namespace Rays
326
357
  }
327
358
 
328
359
  void
329
- Bounds::set_center (const Point& point)
360
+ Bounds::set_center (const Point& center)
330
361
  {
331
- set_center(point.x, point.y, point.z);
362
+ set_center(center.x, center.y, center.z);
332
363
  }
333
364
 
334
365
  Point
@@ -372,12 +403,15 @@ namespace Rays
372
403
  Bounds&
373
404
  Bounds::operator &= (const Bounds& rhs)
374
405
  {
375
- if (!*this || !rhs)
406
+ if (!rhs)
376
407
  argument_error(__FILE__, __LINE__);
377
408
 
378
- coord x = std::max(this->x, rhs.x);
379
- coord y = std::max(this->y, rhs.y);
380
- coord z = std::max(this->z, rhs.z);
409
+ if (!*this)
410
+ invalid_state_error(__FILE__, __LINE__);
411
+
412
+ coord x = std::max(this->x, rhs.x);
413
+ coord y = std::max(this->y, rhs.y);
414
+ coord z = std::max(this->z, rhs.z);
381
415
  coord w = std::min(this->x + this->w, rhs.x + rhs.w) - x;
382
416
  coord h = std::min(this->y + this->h, rhs.y + rhs.h) - y;
383
417
  coord d = std::min(this->z + this->d, rhs.z + rhs.d) - z;
@@ -392,12 +426,11 @@ namespace Rays
392
426
  Bounds&
393
427
  Bounds::operator |= (const Bounds& rhs)
394
428
  {
395
- if (!*this || !rhs)
396
- argument_error(__FILE__, __LINE__);
429
+ if (!rhs) return *this;
397
430
 
398
- coord x = std::min(this->x, rhs.x);
399
- coord y = std::min(this->y, rhs.y);
400
- coord z = std::min(this->z, rhs.z);
431
+ coord x = std::min(this->x, rhs.x);
432
+ coord y = std::min(this->y, rhs.y);
433
+ coord z = std::min(this->z, rhs.z);
401
434
  coord w = std::max(this->x + this->w, rhs.x + rhs.w) - x;
402
435
  coord h = std::max(this->y + this->h, rhs.y + rhs.h) - y;
403
436
  coord d = std::max(this->z + this->d, rhs.z + rhs.d) - z;
@@ -405,6 +438,19 @@ namespace Rays
405
438
  return reset(x, y, z, w, h, d);
406
439
  }
407
440
 
441
+ Bounds&
442
+ Bounds::operator |= (const Point& rhs)
443
+ {
444
+ coord x = std::min(this->x, rhs.x);
445
+ coord y = std::min(this->y, rhs.y);
446
+ coord z = std::min(this->z, rhs.z);
447
+ coord w = std::max(this->x + this->w, rhs.x) - x;
448
+ coord h = std::max(this->y + this->h, rhs.y) - y;
449
+ coord d = std::max(this->z + this->d, rhs.z) - z;
450
+
451
+ return reset(x, y, z, w, h, d);
452
+ }
453
+
408
454
  bool
409
455
  operator == (const Bounds& lhs, const Bounds& rhs)
410
456
  {
@@ -439,5 +485,22 @@ namespace Rays
439
485
  return t;
440
486
  }
441
487
 
488
+ Bounds
489
+ operator | (const Bounds& lhs, const Point& rhs)
490
+ {
491
+ Bounds t = lhs;
492
+ t |= rhs;
493
+ return t;
494
+ }
495
+
496
+
497
+ Bounds
498
+ invalid_bounds ()
499
+ {
500
+ coord max = FLT_MAX / 2;
501
+ coord size = -FLT_MAX;
502
+ return Bounds(max, max, max, size, size, size);
503
+ }
504
+
442
505
 
443
506
  }// Rays
@@ -2,44 +2,69 @@
2
2
 
3
3
 
4
4
  #include <limits.h>
5
+ #include <glm/gtx/color_space.hpp>
5
6
  #include <xot/util.h>
6
7
  #include "rays/exception.h"
7
8
  #include "rays/color_space.h"
9
+ #include "coord.h"
8
10
 
9
11
 
10
12
  namespace Rays
11
13
  {
12
14
 
13
15
 
14
- Color::Color (float gray, float alpha)
16
+ Color
17
+ gray (float gray, float alpha)
15
18
  {
16
- reset(gray, alpha);
19
+ return Color(gray, alpha);
17
20
  }
18
21
 
19
- Color::Color (float red, float green, float blue, float alpha)
22
+ Color
23
+ gray8 (int gray, int alpha)
20
24
  {
21
- reset(red, green, blue, alpha);
25
+ Color c;
26
+ c.reset8(gray, alpha);
27
+ return c;
22
28
  }
23
29
 
24
- Color::Color (void* pixel, const ColorSpace& cs)
30
+ Color
31
+ rgb (float red, float green, float blue, float alpha)
25
32
  {
26
- reset(pixel, cs);
33
+ return Color(red, green, blue, alpha);
27
34
  }
28
35
 
29
36
  Color
30
- Color8 (uchar gray, uchar alpha)
37
+ rgb8 (int red, int green, int blue, int alpha)
31
38
  {
32
39
  Color c;
33
- c.reset8(gray, alpha);
40
+ c.reset8(red, green, blue, alpha);
34
41
  return c;
35
42
  }
36
43
 
37
44
  Color
38
- Color8 (uchar red, uchar green, uchar blue, uchar alpha)
45
+ hsv (float hue, float saturation, float value, float alpha)
39
46
  {
40
- Color c;
41
- c.reset8(red, green, blue, alpha);
42
- return c;
47
+ hue = fmod(hue, 1.f);
48
+ if (hue < 0) hue += 1.f;
49
+
50
+ auto c = glm::rgbColor(Vec3(hue * 360.f, saturation, value));
51
+ return Color(c[0], c[1], c[2], alpha);
52
+ }
53
+
54
+
55
+ Color::Color (float gray, float alpha)
56
+ {
57
+ reset(gray, alpha);
58
+ }
59
+
60
+ Color::Color (float red, float green, float blue, float alpha)
61
+ {
62
+ reset(red, green, blue, alpha);
63
+ }
64
+
65
+ Color::Color (void* pixel, const ColorSpace& cs)
66
+ {
67
+ reset(pixel, cs);
43
68
  }
44
69
 
45
70
  Color
@@ -57,15 +82,12 @@ namespace Rays
57
82
  Color&
58
83
  Color::reset (float red, float green, float blue, float alpha)
59
84
  {
60
- this->red = red;
61
- this->green = green;
62
- this->blue = blue;
63
- this->alpha = alpha;
85
+ Super::reset(red, green, blue, alpha);
64
86
  return *this;
65
87
  }
66
88
 
67
89
  Color&
68
- Color::reset8 (uchar gray, uchar alpha)
90
+ Color::reset8 (int gray, int alpha)
69
91
  {
70
92
  float g = uchar2float(gray);
71
93
  float a = uchar2float(alpha);
@@ -73,12 +95,13 @@ namespace Rays
73
95
  }
74
96
 
75
97
  Color&
76
- Color::reset8 (uchar red, uchar green, uchar blue, uchar alpha)
98
+ Color::reset8 (int red, int green, int blue, int alpha)
77
99
  {
78
- this->red = uchar2float(red);
79
- this->green = uchar2float(green);
80
- this->blue = uchar2float(blue);
81
- this->alpha = uchar2float(alpha);
100
+ Super::reset(
101
+ uchar2float(red),
102
+ uchar2float(green),
103
+ uchar2float(blue),
104
+ uchar2float(alpha));
82
105
  return *this;
83
106
  }
84
107
 
@@ -211,7 +234,7 @@ namespace Rays
211
234
 
212
235
  Color::operator bool () const
213
236
  {
214
- return red >= 0 && green >= 0 && blue >= 0 && alpha >= 0;
237
+ return alpha > 0;
215
238
  }
216
239
 
217
240
  bool
@@ -220,5 +243,17 @@ namespace Rays
220
243
  return !operator bool();
221
244
  }
222
245
 
246
+ bool
247
+ operator == (const Color& lhs, const Color& rhs)
248
+ {
249
+ return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
250
+ }
251
+
252
+ bool
253
+ operator != (const Color& lhs, const Color& rhs)
254
+ {
255
+ return !operator==(lhs, rhs);
256
+ }
257
+
223
258
 
224
259
  }// Rays