rays 0.1.12 → 0.1.17

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 +171 -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 +23 -81
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +186 -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 +74 -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 +24 -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 +23 -0
  107. data/src/ios/bitmap.mm +133 -110
  108. data/src/ios/camera.mm +510 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +4 -4
  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 +23 -0
  119. data/src/osx/bitmap.mm +133 -110
  120. data/src/osx/camera.mm +451 -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
@@ -14,13 +14,12 @@ require 'rays/module'
14
14
 
15
15
  Xot::ExtConf.new Xot, Rucy, Rays do
16
16
  setup do
17
- headers << 'boost/noncopyable.hpp' << 'ruby.h'
17
+ headers << 'ruby.h'
18
18
  local_libs << 'rucy'
19
19
  libs.unshift 'gdi21', 'opengl32' if win32?
20
- frameworks << 'AppKit' << 'OpenGL' if osx?
20
+ frameworks << 'AppKit' << 'OpenGL' << 'AVFoundation' if osx?
21
21
  $LDFLAGS << ' -Wl,--out-implib=native.dll.a' if cygwin?
22
22
  end
23
23
 
24
- dir_config 'boost'
25
24
  create_makefile 'rays/native'
26
25
  end
@@ -1,16 +1,10 @@
1
1
  #include "rays/ruby/font.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
8
- using namespace Rucy;
9
-
10
- using Rays::coord;
11
-
12
-
13
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Font)
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Font)
14
8
 
15
9
  #define THIS to<Rays::Font*>(self)
16
10
 
@@ -30,20 +24,7 @@ RUCY_DEFN(initialize)
30
24
  RUCY_CHECK_OBJ(Rays::Font, self);
31
25
  check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2);
32
26
 
33
- const char* name = (argc >= 1) ? argv[0].c_str() : NULL;
34
- float size = (argc >= 2) ? to<float>(argv[1]) : 0;
35
- *THIS = Rays::Font(name, size);
36
-
37
- return self;
38
- }
39
- RUCY_END
40
-
41
- static
42
- RUCY_DEF1(initialize_copy, obj)
43
- {
44
- RUCY_CHECK_OBJ(Rays::Font, self);
45
-
46
- *THIS = to<Rays::Font&>(obj).copy();
27
+ *THIS = to<Rays::Font>(argc, argv);
47
28
  return self;
48
29
  }
49
30
  RUCY_END
@@ -80,6 +61,36 @@ RUCY_DEF0(height)
80
61
  }
81
62
  RUCY_END
82
63
 
64
+ static
65
+ RUCY_DEF0(ascent)
66
+ {
67
+ CHECK;
68
+ coord ascent = 0;
69
+ THIS->get_height(&ascent);
70
+ return value(ascent);
71
+ }
72
+ RUCY_END
73
+
74
+ static
75
+ RUCY_DEF0(descent)
76
+ {
77
+ CHECK;
78
+ coord descent = 0;
79
+ THIS->get_height(NULL, &descent);
80
+ return value(descent);
81
+ }
82
+ RUCY_END
83
+
84
+ static
85
+ RUCY_DEF0(leading)
86
+ {
87
+ CHECK;
88
+ coord leading = 0;
89
+ THIS->get_height(NULL, NULL, &leading);
90
+ return value(leading);
91
+ }
92
+ RUCY_END
93
+
83
94
 
84
95
  static Class cFont;
85
96
 
@@ -91,14 +102,53 @@ Init_font ()
91
102
  cFont = mRays.define_class("Font");
92
103
  cFont.define_alloc_func(alloc);
93
104
  cFont.define_private_method("initialize", initialize);
94
- cFont.define_private_method("initialize_copy", initialize_copy);
95
105
  cFont.define_method("name", name);
96
106
  cFont.define_method("size", size);
97
- cFont.define_method("width", width);
98
- cFont.define_method("height", height);
107
+ cFont.define_method("width", width);
108
+ cFont.define_method("height", height);
109
+ cFont.define_method("ascent", ascent);
110
+ cFont.define_method("descent", descent);
111
+ cFont.define_method("leading", leading);
99
112
  }
100
113
 
101
114
 
115
+ namespace Rucy
116
+ {
117
+
118
+
119
+ template <> Rays::Font
120
+ value_to<Rays::Font> (int argc, const Value* argv, bool convert)
121
+ {
122
+ if (argc == 1 && argv->is_array())
123
+ {
124
+ argc = argv->size();
125
+ argv = argv->as_array();
126
+ }
127
+
128
+ assert(argc == 0 || (argc > 0 && argv));
129
+
130
+ if (convert)
131
+ {
132
+ if (argc == 0)
133
+ return Rays::default_font();
134
+
135
+ coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
136
+ if (argv->is_nil())
137
+ return Rays::Font(NULL, size);
138
+ else if (argv->is_s() || argv->is_sym())
139
+ return Rays::Font(argv[0].c_str(), size);
140
+ }
141
+
142
+ if (argc != 1)
143
+ argument_error(__FILE__, __LINE__);
144
+
145
+ return value_to<Rays::Font&>(*argv, convert);
146
+ }
147
+
148
+
149
+ }// Rucy
150
+
151
+
102
152
  namespace Rays
103
153
  {
104
154
 
@@ -1,19 +1,12 @@
1
1
  #include "rays/ruby/image.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "rays/ruby/color_space.h"
6
5
  #include "rays/ruby/bitmap.h"
7
- #include "rays/ruby/texture.h"
8
6
  #include "rays/ruby/painter.h"
9
7
  #include "defs.h"
10
8
 
11
9
 
12
- using namespace Rucy;
13
-
14
- using Rays::coord;
15
-
16
-
17
10
  RUCY_DEFINE_VALUE_FROM_TO(Rays::Image)
18
11
 
19
12
  #define THIS to<Rays::Image*>(self)
@@ -32,26 +25,28 @@ static
32
25
  RUCY_DEFN(initialize)
33
26
  {
34
27
  RUCY_CHECK_OBJ(Rays::Image, self);
35
- check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3);
36
-
37
- if (argc == 0) return self;
28
+ check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3, 4);
38
29
 
39
30
  if (argv[0].is_kind_of(Rays::bitmap_class()))
40
31
  {
41
32
  check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2);
42
33
 
43
34
  const Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]);
44
- if (!bitmap) argument_error(__FILE__, __LINE__);
35
+ if (!bitmap)
36
+ argument_error(__FILE__, __LINE__);
45
37
 
46
- bool alpha_only = (argc == 2) ? to<bool>(argv[1]) : false;
47
- *THIS = Rays::Image(*bitmap, alpha_only);
38
+ float pixel_density = (argc >= 2) ? to<float>(argv[1]) : 1;
39
+ *THIS = Rays::Image(*bitmap, pixel_density);
48
40
  }
49
41
  else
50
42
  {
51
- int width = to<int>(argv[0]);
52
- int height = to<int>(argv[1]);
53
- uint colorspace = (argc == 3) ? to<uint>(argv[2]) : (uint) Rays::RGBA;
54
- *THIS = Rays::Image(width, height, (Rays::ColorSpaceType) colorspace);
43
+ check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 2, 3, 4);
44
+
45
+ int width = to<int>(argv[0]);
46
+ int height = to<int>(argv[1]);
47
+ Rays::ColorSpace cs = (argc >= 3) ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA;
48
+ float pixel_density = (argc >= 4) ? to<float>(argv[3]) : 1;
49
+ *THIS = Rays::Image(width, height, cs, pixel_density);
55
50
  }
56
51
 
57
52
  return self;
@@ -63,19 +58,11 @@ RUCY_DEF1(initialize_copy, obj)
63
58
  {
64
59
  RUCY_CHECK_OBJ(Rays::Image, self);
65
60
 
66
- *THIS = to<Rays::Image&>(obj).copy();
61
+ *THIS = to<Rays::Image&>(obj).dup();
67
62
  return self;
68
63
  }
69
64
  RUCY_END
70
65
 
71
- static
72
- RUCY_DEF0(painter)
73
- {
74
- CHECK;
75
- return value(THIS->painter());
76
- }
77
- RUCY_END
78
-
79
66
  static
80
67
  RUCY_DEF0(width)
81
68
  {
@@ -101,26 +88,26 @@ RUCY_DEF0(color_space)
101
88
  RUCY_END
102
89
 
103
90
  static
104
- RUCY_DEF0(alpha_only)
91
+ RUCY_DEF0(pixel_density)
105
92
  {
106
93
  CHECK;
107
- return value(THIS->alpha_only());
94
+ return value(THIS->pixel_density());
108
95
  }
109
96
  RUCY_END
110
97
 
111
98
  static
112
- RUCY_DEF0(bitmap)
99
+ RUCY_DEF0(painter)
113
100
  {
114
101
  CHECK;
115
- return value(THIS->bitmap());
102
+ return value(THIS->painter());
116
103
  }
117
104
  RUCY_END
118
105
 
119
106
  static
120
- RUCY_DEF0(texture)
107
+ RUCY_DEF0(bitmap)
121
108
  {
122
109
  CHECK;
123
- return value(THIS->texture());
110
+ return value(THIS->bitmap());
124
111
  }
125
112
  RUCY_END
126
113
 
@@ -135,9 +122,11 @@ RUCY_END
135
122
 
136
123
 
137
124
  static
138
- RUCY_DEF2(load, path, alpha_only)
125
+ RUCY_DEFN(load)
139
126
  {
140
- return value(Rays::load_image(path.c_str(), to<bool>(alpha_only)));
127
+ check_arg_count(__FILE__, __LINE__, "Image.load", argc, 1);
128
+
129
+ return value(Rays::load_image(argv[0].c_str()));
141
130
  }
142
131
  RUCY_END
143
132
 
@@ -151,17 +140,16 @@ Init_image ()
151
140
 
152
141
  cImage = mRays.define_class("Image");
153
142
  cImage.define_alloc_func(alloc);
154
- cImage.define_private_method("initialize", initialize);
143
+ cImage.define_private_method("initialize", initialize);
155
144
  cImage.define_private_method("initialize_copy", initialize_copy);
156
- cImage.define_method("painter", painter);
157
- cImage.define_method("width", width);
145
+ cImage.define_method("width", width);
158
146
  cImage.define_method("height", height);
159
147
  cImage.define_method("color_space", color_space);
160
- cImage.define_method("alpha_only", alpha_only);
148
+ cImage.define_method("pixel_density", pixel_density);
149
+ cImage.define_method("painter", painter);
161
150
  cImage.define_method("bitmap", bitmap);
162
- cImage.define_method("texture", texture);
163
151
  cImage.define_method("save", save);
164
- cImage.define_function("load_image", load);
152
+ cImage.define_module_function("load", load);
165
153
  }
166
154
 
167
155
 
@@ -1,14 +1,11 @@
1
1
  #include "rays/ruby/matrix.h"
2
2
 
3
3
 
4
- #include <rucy.h>
4
+ #include "rays/ruby/point.h"
5
5
  #include "defs.h"
6
6
 
7
7
 
8
- using namespace Rucy;
9
-
10
-
11
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix)
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Matrix)
12
9
 
13
10
  #define THIS to<Rays::Matrix*>(self)
14
11
 
@@ -28,22 +25,8 @@ RUCY_DEFN(initialize)
28
25
  CHECK;
29
26
  check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
30
27
 
31
- if (argc == 0) return self;
32
-
33
- switch (argc)
34
- {
35
- case 1:
36
- *THIS = Rays::Matrix(to<float>(argv[0]));
37
- break;
38
-
39
- case 16:
40
- *THIS = Rays::Matrix(
41
- to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]), to<float>(argv[3]),
42
- to<float>(argv[4]), to<float>(argv[5]), to<float>(argv[6]), to<float>(argv[7]),
43
- to<float>(argv[8]), to<float>(argv[9]), to<float>(argv[10]), to<float>(argv[11]),
44
- to<float>(argv[12]), to<float>(argv[13]), to<float>(argv[14]), to<float>(argv[15]));
45
- break;
46
- }
28
+ if (argc > 0)
29
+ *THIS = to<Rays::Matrix>(argc, argv);
47
30
 
48
31
  return self;
49
32
  }
@@ -59,23 +42,23 @@ RUCY_DEF1(initialize_copy, obj)
59
42
  RUCY_END
60
43
 
61
44
  static
62
- RUCY_DEFN(set)
45
+ RUCY_DEFN(reset)
63
46
  {
64
47
  CHECK;
65
- check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
48
+ check_arg_count(__FILE__, __LINE__, "Matrix#reset", argc, 0, 1, 16);
66
49
 
67
50
  switch (argc)
68
51
  {
69
52
  case 0:
70
- *THIS = Rays::Matrix();
53
+ THIS->reset();
71
54
  break;
72
55
 
73
56
  case 1:
74
- *THIS = Rays::Matrix(to<float>(argv[0]));
57
+ THIS->reset(to<float>(argv[0]));
75
58
  break;
76
59
 
77
60
  case 16:
78
- *THIS = Rays::Matrix(
61
+ THIS->reset(
79
62
  to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]), to<float>(argv[3]),
80
63
  to<float>(argv[4]), to<float>(argv[5]), to<float>(argv[6]), to<float>(argv[7]),
81
64
  to<float>(argv[8]), to<float>(argv[9]), to<float>(argv[10]), to<float>(argv[11]),
@@ -88,13 +71,140 @@ RUCY_DEFN(set)
88
71
  RUCY_END
89
72
 
90
73
  static
91
- RUCY_DEF2(at, row, column)
74
+ RUCY_DEFN(translate)
75
+ {
76
+ CHECK;
77
+ check_arg_count(__FILE__, __LINE__, "Matrix#translate", argc, 1, 2, 3);
78
+
79
+ THIS->translate(to<Rays::Point>(argc, argv));
80
+ return self;
81
+ }
82
+ RUCY_END
83
+
84
+ static
85
+ RUCY_DEFN(scale)
86
+ {
87
+ CHECK;
88
+ check_arg_count(__FILE__, __LINE__, "Matrix#scale", argc, 1, 2, 3);
89
+
90
+ THIS->scale(to<Rays::Point>(argc, argv));
91
+ return self;
92
+ }
93
+ RUCY_END
94
+
95
+ static
96
+ RUCY_DEFN(rotate)
97
+ {
98
+ CHECK;
99
+ check_arg_count(__FILE__, __LINE__, "Matrix#rotate", argc, 1, 2, 4);
100
+
101
+ float degree = to<float>(argv[0]);
102
+
103
+ if (argc == 1)
104
+ THIS->rotate(degree);
105
+ else
106
+ THIS->rotate(degree, to<Rays::Point>(argc - 1, argv + 1));
107
+
108
+ return self;
109
+ }
110
+ RUCY_END
111
+
112
+ static
113
+ RUCY_DEF0(to_a)
114
+ {
115
+ CHECK;
116
+ return array(
117
+ THIS->x0, THIS->y0, THIS->z0, THIS->w0,
118
+ THIS->x1, THIS->y1, THIS->z1, THIS->w1,
119
+ THIS->x2, THIS->y2, THIS->z2, THIS->w2,
120
+ THIS->x3, THIS->y3, THIS->z3, THIS->w3);
121
+ }
122
+ RUCY_END
123
+
124
+ static
125
+ RUCY_DEF1(mult, val)
126
+ {
127
+ CHECK;
128
+
129
+ if (val.is_kind_of(Rays::matrix_class()))
130
+ return value(*THIS * to<Rays::Matrix&>(val));
131
+
132
+ if (val.is_kind_of(Rays::point_class()))
133
+ return value(*THIS * to<Rays::Point&>(val));
134
+
135
+ if (val.is_array())
136
+ {
137
+ if (val.size() == 16)
138
+ return value(*THIS * to<Rays::Matrix>(val));
139
+ else
140
+ return value(*THIS * to<Rays::Point>(val));
141
+ }
142
+
143
+ argument_error(__FILE__, __LINE__);
144
+ }
145
+ RUCY_END
146
+
147
+ static
148
+ RUCY_DEF3(set_at, row, column, val)
149
+ {
150
+ CHECK;
151
+ return value(THIS->at(row.as_i(), column.as_i()) = to<float>(val));
152
+ }
153
+ RUCY_END
154
+
155
+ static
156
+ RUCY_DEF2(get_at, row, column)
92
157
  {
93
158
  CHECK;
94
159
  return value(THIS->at(row.as_i(), column.as_i()));
95
160
  }
96
161
  RUCY_END
97
162
 
163
+ static
164
+ RUCY_DEF1(compare, other)
165
+ {
166
+ CHECK;
167
+
168
+ const Rays::Matrix& a = *THIS;
169
+ const Rays::Matrix& b = to<const Rays::Matrix&>(other);
170
+ for (int i = 0; i < Rays::Matrix::NELEM; ++i)
171
+ {
172
+ if (a[i] == b[i]) continue;
173
+ return value(a[i] < b[i] ? -1 : +1);
174
+ }
175
+ return value(0);
176
+ }
177
+ RUCY_END
178
+
179
+ static
180
+ RUCY_DEF0(inspect)
181
+ {
182
+ CHECK;
183
+ return value(Xot::stringf("#<Rays::Matrix %s>", THIS->inspect().c_str()));
184
+ }
185
+ RUCY_END
186
+
187
+ static
188
+ RUCY_DEFN(s_translate)
189
+ {
190
+ return translate(argc, argv, value(Rays::Matrix()));
191
+ }
192
+ RUCY_END
193
+
194
+ static
195
+ RUCY_DEFN(s_scale)
196
+ {
197
+ return scale(argc, argv, value(Rays::Matrix()));
198
+ }
199
+ RUCY_END
200
+
201
+ static
202
+ RUCY_DEFN(s_rotate)
203
+ {
204
+ return rotate(argc, argv, value(Rays::Matrix()));
205
+ }
206
+ RUCY_END
207
+
98
208
 
99
209
  static Class cMatrix;
100
210
 
@@ -105,13 +215,71 @@ Init_matrix ()
105
215
 
106
216
  cMatrix = mRays.define_class("Matrix");
107
217
  cMatrix.define_alloc_func(alloc);
108
- cMatrix.define_private_method("initialize", initialize);
218
+ cMatrix.define_private_method("initialize", initialize);
109
219
  cMatrix.define_private_method("initialize_copy", initialize_copy);
110
- cMatrix.define_method("set", set);
111
- cMatrix.define_method("at", at);
220
+ cMatrix.define_method("reset", reset);
221
+ cMatrix.define_method("translate", translate);
222
+ cMatrix.define_method("scale", scale);
223
+ cMatrix.define_method("rotate", rotate);
224
+ cMatrix.define_method("to_a", to_a);
225
+ cMatrix.define_method("*", mult);
226
+ cMatrix.define_method("[]=", set_at);
227
+ cMatrix.define_method("[]", get_at);
228
+ cMatrix.define_method("<=>", compare);
229
+ cMatrix.define_method("inspect", inspect);
230
+
231
+ cMatrix.define_singleton_method("translate", s_translate);
232
+ cMatrix.define_singleton_method("scale", s_scale);
233
+ cMatrix.define_singleton_method("rotate", s_rotate);
112
234
  }
113
235
 
114
236
 
237
+ namespace Rucy
238
+ {
239
+
240
+
241
+ template <> Rays::Matrix
242
+ value_to<Rays::Matrix> (int argc, const Value* argv, bool convert)
243
+ {
244
+ if (argc == 1 && argv->is_array())
245
+ {
246
+ argc = argv->size();
247
+ argv = argv->as_array();
248
+ }
249
+
250
+ assert(argc == 0 || (argc > 0 && argv));
251
+
252
+ if (convert)
253
+ {
254
+ if (argc == 0)
255
+ return Rays::Matrix();
256
+ else if (argv->is_num())
257
+ {
258
+ switch (argc)
259
+ {
260
+ #define V(i) argv[i].as_f(true)
261
+ case 1: return Rays::Matrix(V(0));
262
+ case 16: return Rays::Matrix(
263
+ V(0), V(1), V(2), V(3),
264
+ V(4), V(5), V(6), V(7),
265
+ V(8), V(9), V(10), V(11),
266
+ V(12), V(13), V(14), V(15));
267
+ #undef V
268
+ default: argument_error(__FILE__, __LINE__);
269
+ }
270
+ }
271
+ }
272
+
273
+ if (argc != 1)
274
+ argument_error(__FILE__, __LINE__);
275
+
276
+ return value_to<Rays::Matrix&>(*argv, convert);
277
+ }
278
+
279
+
280
+ }// Rucy
281
+
282
+
115
283
  namespace Rays
116
284
  {
117
285