cyberarm_engine 0.12.1 → 0.13.0
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 +4 -4
- data/.gitignore +8 -8
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +43 -43
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine.rb +47 -46
- data/lib/cyberarm_engine/animator.rb +54 -0
- data/lib/cyberarm_engine/background.rb +175 -175
- data/lib/cyberarm_engine/bounding_box.rb +149 -149
- data/lib/cyberarm_engine/common.rb +96 -96
- data/lib/cyberarm_engine/engine.rb +101 -101
- data/lib/cyberarm_engine/game_object.rb +256 -256
- data/lib/cyberarm_engine/game_state.rb +88 -88
- data/lib/cyberarm_engine/gosu_ext/circle.rb +8 -8
- data/lib/cyberarm_engine/ray.rb +55 -55
- data/lib/cyberarm_engine/shader.rb +262 -205
- data/lib/cyberarm_engine/text.rb +146 -146
- data/lib/cyberarm_engine/timer.rb +22 -22
- data/lib/cyberarm_engine/transform.rb +272 -83
- data/lib/cyberarm_engine/ui/border_canvas.rb +100 -100
- data/lib/cyberarm_engine/ui/dsl.rb +98 -101
- data/lib/cyberarm_engine/ui/element.rb +275 -259
- data/lib/cyberarm_engine/ui/elements/button.rb +66 -66
- data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -58
- data/lib/cyberarm_engine/ui/elements/container.rb +176 -162
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +171 -102
- data/lib/cyberarm_engine/ui/elements/flow.rb +16 -16
- data/lib/cyberarm_engine/ui/elements/image.rb +51 -51
- data/lib/cyberarm_engine/ui/elements/label.rb +49 -49
- data/lib/cyberarm_engine/ui/elements/progress.rb +49 -49
- data/lib/cyberarm_engine/ui/elements/stack.rb +12 -12
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +55 -55
- data/lib/cyberarm_engine/ui/event.rb +46 -45
- data/lib/cyberarm_engine/ui/gui_state.rb +134 -134
- data/lib/cyberarm_engine/ui/style.rb +36 -36
- data/lib/cyberarm_engine/ui/theme.rb +120 -119
- data/lib/cyberarm_engine/vector.rb +202 -198
- data/lib/cyberarm_engine/version.rb +4 -4
- metadata +6 -5
@@ -1,37 +1,37 @@
|
|
1
|
-
module Gosu
|
2
|
-
class Color
|
3
|
-
def _dump(level)
|
4
|
-
[
|
5
|
-
"%02X" % self.alpha,
|
6
|
-
"%02X" % self.red,
|
7
|
-
"%02X" % self.green,
|
8
|
-
"%02X" % self.blue
|
9
|
-
].join
|
10
|
-
end
|
11
|
-
|
12
|
-
def self._load(hex)
|
13
|
-
argb(hex.to_i(16))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module CyberarmEngine
|
19
|
-
class Style
|
20
|
-
def initialize(hash = {})
|
21
|
-
@hash = Marshal.load(Marshal.dump(hash))
|
22
|
-
end
|
23
|
-
|
24
|
-
def method_missing(method, *args, &block)
|
25
|
-
if method.to_s.end_with?("=")
|
26
|
-
raise "Did not expect more than 1 argument" if args.size > 1
|
27
|
-
return @hash[method.to_s.sub("=", "").to_sym] = args.first
|
28
|
-
|
29
|
-
elsif args.size == 0
|
30
|
-
return @hash[method]
|
31
|
-
|
32
|
-
else
|
33
|
-
raise ArgumentError, "Did not expect arguments"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
module Gosu
|
2
|
+
class Color
|
3
|
+
def _dump(level)
|
4
|
+
[
|
5
|
+
"%02X" % self.alpha,
|
6
|
+
"%02X" % self.red,
|
7
|
+
"%02X" % self.green,
|
8
|
+
"%02X" % self.blue
|
9
|
+
].join
|
10
|
+
end
|
11
|
+
|
12
|
+
def self._load(hex)
|
13
|
+
argb(hex.to_i(16))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module CyberarmEngine
|
19
|
+
class Style
|
20
|
+
def initialize(hash = {})
|
21
|
+
@hash = Marshal.load(Marshal.dump(hash))
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(method, *args, &block)
|
25
|
+
if method.to_s.end_with?("=")
|
26
|
+
raise "Did not expect more than 1 argument" if args.size > 1
|
27
|
+
return @hash[method.to_s.sub("=", "").to_sym] = args.first
|
28
|
+
|
29
|
+
elsif args.size == 0
|
30
|
+
return @hash[method]
|
31
|
+
|
32
|
+
else
|
33
|
+
raise ArgumentError, "Did not expect arguments"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
37
|
end
|
@@ -1,119 +1,120 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
module Theme
|
3
|
-
def default(*args)
|
4
|
-
value = @options
|
5
|
-
args.each do |arg|
|
6
|
-
value = value.dig(arg)
|
7
|
-
end
|
8
|
-
|
9
|
-
value
|
10
|
-
end
|
11
|
-
|
12
|
-
def theme_defaults(options)
|
13
|
-
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
14
|
-
_theme = THEME
|
15
|
-
_theme = _theme.merge(options[:theme]) if options[:theme]
|
16
|
-
_theme.delete(:theme) if options[:theme]
|
17
|
-
|
18
|
-
hash = {}
|
19
|
-
class_names = self.class.ancestors
|
20
|
-
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse!
|
21
|
-
|
22
|
-
class_names.each do |klass|
|
23
|
-
next unless data = _theme.dig(klass)
|
24
|
-
data.each do |key, value|
|
25
|
-
hash.merge!(data)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
deep_merge(hash, options)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Derived from Rails Hash#deep_merge!
|
33
|
-
# Enables passing partial themes through Element options without issue
|
34
|
-
def deep_merge(original, intergrate, &block)
|
35
|
-
hash = original.merge(intergrate) do |key, this_val, other_val|
|
36
|
-
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
37
|
-
deep_merge(this_val, other_val, &block)
|
38
|
-
elsif block_given?
|
39
|
-
block.call(key, this_val, other_val)
|
40
|
-
else
|
41
|
-
other_val
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
return hash
|
46
|
-
end
|
47
|
-
|
48
|
-
THEME = {
|
49
|
-
Element: {
|
50
|
-
x: 0,
|
51
|
-
y: 0,
|
52
|
-
z: 30,
|
53
|
-
|
54
|
-
width: nil,
|
55
|
-
height: nil,
|
56
|
-
color: Gosu::Color::WHITE,
|
57
|
-
background: Gosu::Color::NONE,
|
58
|
-
margin: 0,
|
59
|
-
padding: 0,
|
60
|
-
border_thickness: 0,
|
61
|
-
border_color: Gosu::Color::NONE,
|
62
|
-
border_radius: 0,
|
63
|
-
},
|
64
|
-
|
65
|
-
Button: { # < Label
|
66
|
-
margin: 1,
|
67
|
-
padding: 4,
|
68
|
-
border_thickness: 1,
|
69
|
-
border_color: ["ffd59674".hex, "ffff8746".hex],
|
70
|
-
border_radius: 0,
|
71
|
-
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
72
|
-
|
73
|
-
hover: {
|
74
|
-
color: Gosu::Color.rgb(200,200,200),
|
75
|
-
background: ["ffB23E41".to_i(16), "ffFF7C00".to_i(16)],
|
76
|
-
},
|
77
|
-
|
78
|
-
active: {
|
79
|
-
color: Gosu::Color::BLACK,
|
80
|
-
background: ["ffB23E41".to_i(16)]
|
81
|
-
}
|
82
|
-
},
|
83
|
-
|
84
|
-
EditLine: { # < Button
|
85
|
-
type: :text,
|
86
|
-
width: 200,
|
87
|
-
password_character: "•",
|
88
|
-
caret_width: 2,
|
89
|
-
caret_color: Gosu::Color::WHITE,
|
90
|
-
caret_interval: 500,
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
module Theme
|
3
|
+
def default(*args)
|
4
|
+
value = @options
|
5
|
+
args.each do |arg|
|
6
|
+
value = value.dig(arg)
|
7
|
+
end
|
8
|
+
|
9
|
+
value
|
10
|
+
end
|
11
|
+
|
12
|
+
def theme_defaults(options)
|
13
|
+
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
14
|
+
_theme = THEME
|
15
|
+
_theme = _theme.merge(options[:theme]) if options[:theme]
|
16
|
+
_theme.delete(:theme) if options[:theme]
|
17
|
+
|
18
|
+
hash = {}
|
19
|
+
class_names = self.class.ancestors
|
20
|
+
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse!
|
21
|
+
|
22
|
+
class_names.each do |klass|
|
23
|
+
next unless data = _theme.dig(klass)
|
24
|
+
data.each do |key, value|
|
25
|
+
hash.merge!(data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
deep_merge(hash, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Derived from Rails Hash#deep_merge!
|
33
|
+
# Enables passing partial themes through Element options without issue
|
34
|
+
def deep_merge(original, intergrate, &block)
|
35
|
+
hash = original.merge(intergrate) do |key, this_val, other_val|
|
36
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
37
|
+
deep_merge(this_val, other_val, &block)
|
38
|
+
elsif block_given?
|
39
|
+
block.call(key, this_val, other_val)
|
40
|
+
else
|
41
|
+
other_val
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return hash
|
46
|
+
end
|
47
|
+
|
48
|
+
THEME = {
|
49
|
+
Element: {
|
50
|
+
x: 0,
|
51
|
+
y: 0,
|
52
|
+
z: 30,
|
53
|
+
|
54
|
+
width: nil,
|
55
|
+
height: nil,
|
56
|
+
color: Gosu::Color::WHITE,
|
57
|
+
background: Gosu::Color::NONE,
|
58
|
+
margin: 0,
|
59
|
+
padding: 0,
|
60
|
+
border_thickness: 0,
|
61
|
+
border_color: Gosu::Color::NONE,
|
62
|
+
border_radius: 0,
|
63
|
+
},
|
64
|
+
|
65
|
+
Button: { # < Label
|
66
|
+
margin: 1,
|
67
|
+
padding: 4,
|
68
|
+
border_thickness: 1,
|
69
|
+
border_color: ["ffd59674".hex, "ffff8746".hex],
|
70
|
+
border_radius: 0,
|
71
|
+
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
72
|
+
|
73
|
+
hover: {
|
74
|
+
color: Gosu::Color.rgb(200,200,200),
|
75
|
+
background: ["ffB23E41".to_i(16), "ffFF7C00".to_i(16)],
|
76
|
+
},
|
77
|
+
|
78
|
+
active: {
|
79
|
+
color: Gosu::Color::BLACK,
|
80
|
+
background: ["ffB23E41".to_i(16)]
|
81
|
+
}
|
82
|
+
},
|
83
|
+
|
84
|
+
EditLine: { # < Button
|
85
|
+
type: :text,
|
86
|
+
width: 200,
|
87
|
+
password_character: "•",
|
88
|
+
caret_width: 2,
|
89
|
+
caret_color: Gosu::Color::WHITE,
|
90
|
+
caret_interval: 500,
|
91
|
+
selection_color: Gosu::Color::GREEN,
|
92
|
+
},
|
93
|
+
|
94
|
+
Image: { # < Element
|
95
|
+
retro: false
|
96
|
+
},
|
97
|
+
|
98
|
+
Label: { # < Element
|
99
|
+
text_size: 28,
|
100
|
+
text_shadow: false,
|
101
|
+
font: "Arial",
|
102
|
+
margin: 0,
|
103
|
+
padding: 2
|
104
|
+
},
|
105
|
+
|
106
|
+
ToggleButton: { # < Button
|
107
|
+
checkmark: "√"
|
108
|
+
},
|
109
|
+
|
110
|
+
Progress: { # < Element
|
111
|
+
width: 250,
|
112
|
+
height: 36,
|
113
|
+
background: 0xff111111,
|
114
|
+
fraction_background: [0xffc75e61, 0xffe26623],
|
115
|
+
border_thickness: 1,
|
116
|
+
border_color: [0xffd59674, 0xffff8746]
|
117
|
+
}
|
118
|
+
}.freeze
|
119
|
+
end
|
120
|
+
end
|
@@ -1,199 +1,203 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Vector
|
3
|
-
def self.up
|
4
|
-
Vector.new(0, 1, 0)
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.down
|
8
|
-
Vector.new(0, -1, 0)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.left
|
12
|
-
Vector.new(-1, 0, 0)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.right
|
16
|
-
Vector.new(1, 0, 0)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.forward
|
20
|
-
Vector.new(0, 0, 1)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.backward
|
24
|
-
Vector.new(0, 0, -1)
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
28
|
-
@x, @y, @z, @weight = x, y, z, weight
|
29
|
-
end
|
30
|
-
|
31
|
-
def x; @x; end
|
32
|
-
def x=(n); @x = n; end
|
33
|
-
|
34
|
-
def y; @y; end
|
35
|
-
def y=(n); @y = n; end
|
36
|
-
|
37
|
-
def z; @z; end
|
38
|
-
def z=(n); @z = n; end
|
39
|
-
|
40
|
-
def weight; @weight; end
|
41
|
-
def weight=(n); @weight = n; end
|
42
|
-
|
43
|
-
alias w weight
|
44
|
-
alias w= weight=
|
45
|
-
|
46
|
-
def ==(other)
|
47
|
-
if other.is_a?(Numeric)
|
48
|
-
@x == other &&
|
49
|
-
@y == other &&
|
50
|
-
@z == other &&
|
51
|
-
@weight == other
|
52
|
-
else
|
53
|
-
@x == other.x &&
|
54
|
-
@y == other.y &&
|
55
|
-
@z == other.z &&
|
56
|
-
@weight == other.weight
|
57
|
-
end
|
58
|
-
end
|
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
|
-
|
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
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
Vector.new(
|
162
|
-
end
|
163
|
-
|
164
|
-
def
|
165
|
-
@x
|
166
|
-
end
|
167
|
-
|
168
|
-
def
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
def
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
def
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
def
|
196
|
-
|
197
|
-
end
|
198
|
-
|
1
|
+
module CyberarmEngine
|
2
|
+
class Vector
|
3
|
+
def self.up
|
4
|
+
Vector.new(0, 1, 0)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
Vector.new(0, -1, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.left
|
12
|
+
Vector.new(-1, 0, 0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.right
|
16
|
+
Vector.new(1, 0, 0)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.forward
|
20
|
+
Vector.new(0, 0, 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.backward
|
24
|
+
Vector.new(0, 0, -1)
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
28
|
+
@x, @y, @z, @weight = x, y, z, weight
|
29
|
+
end
|
30
|
+
|
31
|
+
def x; @x; end
|
32
|
+
def x=(n); @x = n; end
|
33
|
+
|
34
|
+
def y; @y; end
|
35
|
+
def y=(n); @y = n; end
|
36
|
+
|
37
|
+
def z; @z; end
|
38
|
+
def z=(n); @z = n; end
|
39
|
+
|
40
|
+
def weight; @weight; end
|
41
|
+
def weight=(n); @weight = n; end
|
42
|
+
|
43
|
+
alias w weight
|
44
|
+
alias w= weight=
|
45
|
+
|
46
|
+
def ==(other)
|
47
|
+
if other.is_a?(Numeric)
|
48
|
+
@x == other &&
|
49
|
+
@y == other &&
|
50
|
+
@z == other &&
|
51
|
+
@weight == other
|
52
|
+
else
|
53
|
+
@x == other.x &&
|
54
|
+
@y == other.y &&
|
55
|
+
@z == other.z &&
|
56
|
+
@weight == other.weight
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def xy
|
61
|
+
Vector.new(@x, @y)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Performs math operation, excluding @weight
|
65
|
+
private def operator(function, other)
|
66
|
+
if other.is_a?(Numeric)
|
67
|
+
Vector.new(
|
68
|
+
@x.send(:"#{function}", other),
|
69
|
+
@y.send(:"#{function}", other),
|
70
|
+
@z.send(:"#{function}", other)
|
71
|
+
)
|
72
|
+
else
|
73
|
+
Vector.new(
|
74
|
+
@x.send(:"#{function}", other.x),
|
75
|
+
@y.send(:"#{function}", other.y),
|
76
|
+
@z.send(:"#{function}", other.z)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Adds Vector and Numberic or Vector and Vector, excluding @weight
|
82
|
+
def +(other)
|
83
|
+
operator("+", other)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Subtracts Vector and Numberic or Vector and Vector, excluding @weight
|
87
|
+
def -(other)
|
88
|
+
operator("-", other)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Multiplies Vector and Numberic or Vector and Vector, excluding @weight
|
92
|
+
def *(other)
|
93
|
+
operator("*", other)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Divides Vector and Numberic or Vector and Vector, excluding @weight
|
97
|
+
def /(other)
|
98
|
+
# Duplicated to protect from DivideByZero
|
99
|
+
if other.is_a?(Numeric)
|
100
|
+
Vector.new(
|
101
|
+
(@x == 0 ? 0 : @x / other),
|
102
|
+
(@y == 0 ? 0 : @y / other),
|
103
|
+
(@z == 0 ? 0 : @z / other)
|
104
|
+
)
|
105
|
+
else
|
106
|
+
Vector.new(
|
107
|
+
(@x == 0 ? 0 : @x / other.x),
|
108
|
+
(@y == 0 ? 0 : @y / other.y),
|
109
|
+
(@z == 0 ? 0 : @z / other.z)
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def dot(other)
|
115
|
+
product = 0
|
116
|
+
|
117
|
+
a = self.to_a
|
118
|
+
b = other.to_a
|
119
|
+
|
120
|
+
3.times do |i|
|
121
|
+
product = product + (a[i] * b[i])
|
122
|
+
end
|
123
|
+
|
124
|
+
return product
|
125
|
+
end
|
126
|
+
|
127
|
+
def cross(other)
|
128
|
+
a = self.to_a
|
129
|
+
b = other.to_a
|
130
|
+
|
131
|
+
Vector.new(
|
132
|
+
b[2] * a[1] - b[1] * a[2],
|
133
|
+
b[0] * a[2] - b[2] * a[0],
|
134
|
+
b[1] * a[0] - b[0] * a[1]
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
# returns degrees
|
139
|
+
def angle(other)
|
140
|
+
Math.acos( self.normalized.dot(other.normalized) ) * 180 / Math::PI
|
141
|
+
end
|
142
|
+
|
143
|
+
# returns magnitude of Vector, ignoring #weight
|
144
|
+
def magnitude
|
145
|
+
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
146
|
+
end
|
147
|
+
|
148
|
+
def normalized
|
149
|
+
mag = magnitude
|
150
|
+
self / Vector.new(mag, mag, mag)
|
151
|
+
end
|
152
|
+
|
153
|
+
def direction
|
154
|
+
# z is pitch
|
155
|
+
# y is yaw
|
156
|
+
# x is roll
|
157
|
+
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
158
|
+
_y = Math.sin(@z.degrees_to_radians)
|
159
|
+
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
160
|
+
|
161
|
+
Vector.new(_x, _y, _z)
|
162
|
+
end
|
163
|
+
|
164
|
+
def inverse
|
165
|
+
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
166
|
+
end
|
167
|
+
|
168
|
+
def sum
|
169
|
+
@x + @y + @z
|
170
|
+
end
|
171
|
+
|
172
|
+
def lerp(other, factor)
|
173
|
+
(self - other) * factor.clamp(0.0, 1.0)
|
174
|
+
end
|
175
|
+
|
176
|
+
# 2D distance using X and Y
|
177
|
+
def distance(other)
|
178
|
+
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2)
|
179
|
+
end
|
180
|
+
|
181
|
+
# 2D distance using X and Z
|
182
|
+
def gl_distance2d(other)
|
183
|
+
Math.sqrt((@x-other.x)**2 + (@z-other.z)**2)
|
184
|
+
end
|
185
|
+
|
186
|
+
# 3D distance using X, Y, and Z
|
187
|
+
def distance3d(other)
|
188
|
+
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2 + (@z-other.z)**2)
|
189
|
+
end
|
190
|
+
|
191
|
+
def to_a
|
192
|
+
[@x, @y, @z, @weight]
|
193
|
+
end
|
194
|
+
|
195
|
+
def to_s
|
196
|
+
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
197
|
+
end
|
198
|
+
|
199
|
+
def to_h
|
200
|
+
{x: @x, y: @y, z: @z, weight: @weight}
|
201
|
+
end
|
202
|
+
end
|
199
203
|
end
|