rays 0.1.12 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +171 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +23 -81
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +186 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +74 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +24 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +23 -0
- data/src/ios/bitmap.mm +133 -110
- data/src/ios/camera.mm +510 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +4 -4
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +23 -0
- data/src/osx/bitmap.mm +133 -110
- data/src/osx/camera.mm +451 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/ext/rays/extconf.rb
CHANGED
@@ -14,13 +14,12 @@ require 'rays/module'
|
|
14
14
|
|
15
15
|
Xot::ExtConf.new Xot, Rucy, Rays do
|
16
16
|
setup do
|
17
|
-
headers << '
|
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
|
data/ext/rays/font.cpp
CHANGED
@@ -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
|
-
|
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
|
-
|
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",
|
98
|
-
cFont.define_method("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
|
|
data/ext/rays/image.cpp
CHANGED
@@ -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)
|
35
|
+
if (!bitmap)
|
36
|
+
argument_error(__FILE__, __LINE__);
|
45
37
|
|
46
|
-
|
47
|
-
*THIS = Rays::Image(*bitmap,
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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).
|
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(
|
91
|
+
RUCY_DEF0(pixel_density)
|
105
92
|
{
|
106
93
|
CHECK;
|
107
|
-
return value(THIS->
|
94
|
+
return value(THIS->pixel_density());
|
108
95
|
}
|
109
96
|
RUCY_END
|
110
97
|
|
111
98
|
static
|
112
|
-
RUCY_DEF0(
|
99
|
+
RUCY_DEF0(painter)
|
113
100
|
{
|
114
101
|
CHECK;
|
115
|
-
return value(THIS->
|
102
|
+
return value(THIS->painter());
|
116
103
|
}
|
117
104
|
RUCY_END
|
118
105
|
|
119
106
|
static
|
120
|
-
RUCY_DEF0(
|
107
|
+
RUCY_DEF0(bitmap)
|
121
108
|
{
|
122
109
|
CHECK;
|
123
|
-
return value(THIS->
|
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
|
-
|
125
|
+
RUCY_DEFN(load)
|
139
126
|
{
|
140
|
-
|
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",
|
143
|
+
cImage.define_private_method("initialize", initialize);
|
155
144
|
cImage.define_private_method("initialize_copy", initialize_copy);
|
156
|
-
cImage.define_method("
|
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("
|
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.
|
152
|
+
cImage.define_module_function("load", load);
|
165
153
|
}
|
166
154
|
|
167
155
|
|
data/ext/rays/matrix.cpp
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
#include "rays/ruby/matrix.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include
|
4
|
+
#include "rays/ruby/point.h"
|
5
5
|
#include "defs.h"
|
6
6
|
|
7
7
|
|
8
|
-
|
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
|
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(
|
45
|
+
RUCY_DEFN(reset)
|
63
46
|
{
|
64
47
|
CHECK;
|
65
|
-
check_arg_count(__FILE__, __LINE__, "Matrix#
|
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
|
-
|
53
|
+
THIS->reset();
|
71
54
|
break;
|
72
55
|
|
73
56
|
case 1:
|
74
|
-
|
57
|
+
THIS->reset(to<float>(argv[0]));
|
75
58
|
break;
|
76
59
|
|
77
60
|
case 16:
|
78
|
-
|
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
|
-
|
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",
|
218
|
+
cMatrix.define_private_method("initialize", initialize);
|
109
219
|
cMatrix.define_private_method("initialize_copy", initialize_copy);
|
110
|
-
cMatrix.define_method("
|
111
|
-
cMatrix.define_method("
|
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
|
|