shattered_pack 0.4.0.1 → 0.5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/lib/shattered_model.rb +1 -4
  2. data/lib/shattered_pack/base.rb +1 -1
  3. data/lib/shattered_pack/keyboard_input/key_converter.rb +3 -3
  4. data/lib/shattered_pack/keyboard_input/keyboard_input.rb +3 -1
  5. data/lib/shattered_pack/pre_initialize/pre_initialize.rb +6 -1
  6. data/lib/shattered_pack.rb +2 -5
  7. data/lib/shattered_state/actor/actor.rb +5 -1
  8. data/lib/shattered_state/base.rb +31 -16
  9. data/lib/shattered_state.rb +1 -4
  10. data/lib/shattered_view/base.rb +106 -41
  11. data/lib/shattered_view/camera.rb +7 -7
  12. data/lib/shattered_view/resources.rb +18 -2
  13. data/lib/shattered_view.rb +3 -5
  14. metadata +10 -29
  15. data/lib/mock_objects/shattered_ogre/input.rb +0 -6
  16. data/lib/mock_objects/shattered_ogre/light.rb +0 -4
  17. data/lib/mock_objects/shattered_ogre/mesh.rb +0 -17
  18. data/lib/mock_objects/shattered_ogre/node.rb +0 -17
  19. data/lib/mock_objects/shattered_ogre/renderer.rb +0 -11
  20. data/lib/mock_objects/shattered_ogre/resource_handler.rb +0 -9
  21. data/lib/mock_objects/shattered_ogre/scene.rb +0 -28
  22. data/lib/shattered_model/fuzzy_logic.rb +0 -188
  23. data/lib/shattered_model/linear_interpolator.rb +0 -29
  24. data/lib/shattered_pack/runner.rb +0 -11
  25. data/lib/shattered_state/runner.rb +0 -39
  26. data/lib/shattered_view/extensions.rb +0 -10
  27. data/lib/shattered_view/light.rb +0 -29
  28. data/lib/shattered_view/mesh/animation.rb +0 -20
  29. data/lib/shattered_view/mesh/mesh.rb +0 -152
  30. data/lib/shattered_view/node.rb +0 -105
  31. data/lib/shattered_view/overlay.rb +0 -20
  32. data/lib/shattered_view/rmaterial.rb +0 -43
  33. data/lib/shattered_view/runner.rb +0 -48
  34. data/lib/shattered_view/vector.rb +0 -258
@@ -1,258 +0,0 @@
1
- class Object
2
- # This is a shorthand to define vector object coordinates.
3
- #
4
- # Creates a vector object at coordinates x,y,z
5
- def v(x, y, z)
6
- Vector.new(x, y, z)
7
- end
8
- end
9
-
10
- class SymbolToVectorError < StandardError #:nodoc:
11
- end
12
-
13
- class Symbol #:nodoc:
14
- # Vectors in symbol form can be any of the following:
15
- # :x => v(1,0,0)
16
- # :y => v(0,1,0)
17
- # :z => v(0,0,1),
18
- # :up => v(0,1,0)
19
- # :down => v(0,-1,0)
20
- # :left => v(-1,0,0)
21
- # :right => v(1,0,0)
22
- # :forward => v(0,0,1)
23
- # :backward => v(0,0,-1)
24
- # :zero => v(0,0,0)
25
- def to_v
26
- @definitions ||= {:x => v(1,0,0),:y => v(0,1,0),:z => v(0,0,1),
27
- :up => v(0,1,0),:down => v(0,-1,0),
28
- :left => v(-1,0,0),:right => v(1,0,0),
29
- :forward => v(0,0,1),:backward => v(0,0,-1),
30
- :zero => v(0,0,0)}
31
- return @definitions[self] unless @definitions[self].nil?
32
- raise SymbolToVectorError, "Undefined vector for symbol #{self}"
33
- end
34
-
35
- # Multiplication defined for vectors carries over to their symbolic equivalence.
36
- def *(number)
37
- return to_v * number
38
- end
39
-
40
- # Addition for vectors
41
- def +(number)
42
- return to_v + number
43
- end
44
- end
45
-
46
- class Array #:nodoc:
47
- # Vector extensions for array. Allows for coersion of a 3 element Array into a vector.
48
-
49
- # Randomize the order of an array
50
- #
51
- # [1, 2, 3].shuffle #=> [2, 3, 1]
52
- #
53
- def shuffle
54
- sort_by {rand}
55
- end
56
-
57
- # Create a vector from an array.
58
- #
59
- # [1, 2, 3].to_v #=> same as Vector.new(1, 2, 3)
60
- #
61
- def to_v
62
- raise StandardError, "vector #{self.inspect} does not have 3 elements" if self.length < 3
63
- Vector.new self[0], self[1] ,self[2]
64
- end
65
-
66
- # Returns this Array as an Ogre vector object: Vector3. Should only be used internally by
67
- # Shattered to communicate with the Ogre engine.
68
- def to_v3
69
- self.to_v.to_v3
70
- end
71
- end
72
-
73
- # Vector is a three dimensional array, that allows for various operations on itself.
74
- # To create a vector, use the shorthand:
75
- # v(0,0,0) # Creates a zero vector
76
- class Vector
77
-
78
- attr_reader :x, :y, :z
79
-
80
- # Create a new Vector object. It requires exactly 3 arguments: x, y and z. Any value that
81
- # can be converted to a float is acceptable.
82
- #
83
- # *NOTE:* The recomended way to create Vector objects is to use the <tt>v(1,2,3)</tt> shorthand.
84
- def initialize(x_val, y_val, z_val)
85
- @x, @y, @z = [x_val, y_val, z_val].collect{ |x| x.to_f }
86
- end
87
-
88
- # Iterate through x, y and z with a block. The passed value is the value of each component of
89
- # the vector.
90
- def each(&block)
91
- self.to_a.each do |component|
92
- yield component
93
- end
94
- end
95
-
96
- # Returns this Vector as an Ogre vector object: Vector3. Should only be used internally by
97
- # Shattered to communicate with the Ogre engine.
98
- def to_v3 # :nodoc:
99
- ShatteredOgre::Vector3.new @x, @y, @z
100
- end
101
-
102
- # Returns self
103
- def to_v
104
- self
105
- end
106
-
107
- # Returns an array with x, y and z dumped into its elements.
108
- # v(1, 2, 3).to_a #=> [1.0, 2.0, 3.0]
109
- def to_a
110
- [@x, @y, @z]
111
- end
112
-
113
- # Add 2 Vectors together.
114
- # v(1,1,1) + v(1,2,3) #=> v(2,3,4)
115
- def +(*args)
116
- vector = convert_args_to_vector(args)
117
- Vector.new(
118
- self.x + vector.x,
119
- self.y + vector.y,
120
- self.z + vector.z
121
- )
122
- end
123
-
124
- # Subtract one Vector from another.
125
- # v(1,2,3) - v(1,1,1) #=> v(0,1,2)
126
- def -(args)
127
- vector = convert_args_to_vector(args)
128
- Vector.new(
129
- self.x - vector.x,
130
- self.y - vector.y,
131
- self.z - vector.z
132
- )
133
- end
134
-
135
- # Multiply all components of a vector by a scalar amount.
136
- # v(1,2,3) * 3 #=> v(3,6,9)
137
- def *(value)
138
- result = []
139
- each do |i|
140
- result << i * value
141
- end
142
- result.to_v
143
- end
144
-
145
- # Divide all components of a vector by a scalar amount
146
- # v(5,10,15) / 5 #=> v(1,2,3)
147
- def /(value)
148
- result = Array.new
149
- self.each do |i|
150
- result << i/value.to_f
151
- end
152
- result.to_v
153
- end
154
-
155
- # Returns this Vector but normalized to a length of 1.
156
- # v(9, 0, 0).normalize #=> v(1,0,0)
157
- def normalize
158
- self * (1 / length)
159
- end
160
- alias_method :normalise, :normalize
161
-
162
- # Same as #normalize but modifies the receiver in place.
163
- def normalize!
164
- @x, @y, @z = normalize.to_a
165
- end
166
- alias_method :normalise!, :normalize!
167
-
168
- # Return the value specified by bracket notation. Integers, Symbols or Strings
169
- # are accepted as keys.
170
- #
171
- # vector = v(1,2,3)
172
- # vector[:x] #=> 1
173
- # vector['y'] #=> 2
174
- # vector[2] #=> 3
175
- def [](index)
176
- case
177
- when index == 0 || index == :x || index == 'x'
178
- @x
179
- when index == 1 || index == :y || index == 'y'
180
- @y
181
- when index == 2 || index == :z || index == 'z'
182
- @z
183
- end
184
- end
185
-
186
- # Set the value specified by bracket notation. Accepts the same keys as the #[]
187
- # method.
188
- def []=(index, value)
189
- case
190
- when index == 0 || index == :x || index == 'x'
191
- @x = value.to_f
192
- when index == 1 || index == :y || index == 'y'
193
- @y = value.to_f
194
- when index == 2 || index == :z || index == 'z'
195
- @z = value.to_f
196
- end
197
- end
198
-
199
- # Set the value of the X component.
200
- def x=(value)
201
- @x = value.to_f
202
- end
203
-
204
- # Set the value of the Y component.
205
- def y=(value)
206
- @y = value.to_f
207
- end
208
-
209
- # Set the value of the Z component.
210
- def z=(value)
211
- @z = value.to_f
212
- end
213
-
214
-
215
- # Returns the length of this vector.
216
- # v(0,0,7).length #=> 7
217
- def length
218
- Math.sqrt(x**2 + y**2 + z**2)
219
- end
220
-
221
- # Converts the vector into an easily identifiable form. Mostly used for debugging
222
- # and console output.
223
- # v(1,2,3).to_s #=> "#<Vector [1.0, 2.0, 3.0]>"
224
- def to_s
225
- "#<Vector [#@x, #@y, #@z]>"
226
- end
227
-
228
- # Equality test. This method will return true if all components of both vectors are
229
- # indentical.
230
- def ==(vector)
231
- vector = vector.to_v if vector.is_a?(Symbol)
232
- vector.kind_of?(Vector) &&
233
- x == vector.x &&
234
- y == vector.y &&
235
- z == vector.z
236
- end
237
-
238
- # Create a unique identifier based on x, y and z.
239
- def hash
240
- return self.to_a.hash
241
- end
242
-
243
- # Equality test for hash indexes.
244
- def eql?(other)
245
- return self.to_a.eql?(other.to_a)
246
- end
247
-
248
- private
249
-
250
- def convert_args_to_vector(*args)
251
- args.flatten!
252
- if(args.first.is_a?(Vector) || args.first.is_a?(Symbol))
253
- args.first.to_v
254
- else
255
- args.to_v
256
- end
257
- end
258
- end