snow-math 1.2.4 → 1.3.0pre0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63148f99dc86916bca148aec7ab5c6d65f239b5e
4
- data.tar.gz: aecbe9ad0a805b85717da26811f8d5aa7c1d45e4
3
+ metadata.gz: e00066f49ddedf7f84e2d892e7231b9d23ee2f47
4
+ data.tar.gz: cac62d08c53fcfa26e412b12dc53f5d1d87fa0b4
5
5
  SHA512:
6
- metadata.gz: 4540efd80dbc5ddf50d0a3b1399d9c9f1c25f3edd165983128531ede3da749b5bc94c89b7ec0f1b2427ae7671f4026af8bdac5fcf23d11fee2fe59c1e3300941
7
- data.tar.gz: e981d3976e87fd1bbc33f025ddee756c30b5e07ef5e590eb83b2ac6b8e2c5794cf0ea16d391e4ca5ab01888d98ef147203c8b816e0bc37eb12ebd46760e65617
6
+ metadata.gz: 12a03e8858753075b0fa744ce6a76c8d69467e5c3d5f6043b69a84ee5cba6b64090804a86dd4e2bb27f8fce2c6e29501fb8a2cbe0802ebd5190c33e98d767ee7
7
+ data.tar.gz: bacebc0520dbebcac508fae8ebcdd8811970fb4ebf6395d30c44c47a988ddba832cc025abc892deb0a84f0356f9e46319e868402b71710e22d18de222acf1190
data/README.md CHANGED
@@ -38,29 +38,63 @@ To include the Fiddle support, you'll also need to `require 'snow-math/ptr'`.
38
38
  This is to avoid dragging the entirety of Fiddle into your code when you're not
39
39
  using it.
40
40
 
41
- Because it's difficult to produce useful documentation for these bindings, this
42
- is a brief outline of the classes and their functions in Ruby, sans function
43
- bodies. Where a description of the functions is missing, the functions do what
44
- they say on the tin.
45
41
 
46
42
  ### Notes
47
43
 
48
44
  #### Outputs
49
45
 
50
- Also, keep in mind that for any function provides an output argument, that
51
- argument is optional. If output is non-nil, the function will must write its
52
- the result of its operation to the output object.
46
+ Keep in mind that for any function provides an output argument, that argument
47
+ is optional. If output is non-nil, the function must write the result of its
48
+ operation to the output object, assuming the object is a compatible output.
53
49
 
54
- When nil, the function will always return a new object. Providing an output
55
- argument can be helpful when you want to avoid some unnecessary allocations.
50
+ When nil, functions will always return a new object. Providing an output
51
+ argument can be helpful when you want to avoid some unnecessary allocations
52
+ and know that's a performance bottleneck (use a profiler before doing this).
56
53
 
57
- Combined with the array types, you can either maintain a pool of 3D math objects
58
- or use it to avoid cache misses (though right now the array objects are not the
59
- most-optimized as they allocate a wrapper object per `fetch` -- something to
60
- keep in mind).
54
+ Combined with the array types, you can either maintain a pool of 3D math
55
+ objects or use it to avoid cache misses.
61
56
 
62
57
  In all cases where an output is provided, output may be the the object the
63
58
  function is called on. So, for example, `vec.negate(vec)` is perfectly valid.
59
+ The SnowPalm code is designed to handle this and will not accidentally trash
60
+ itself because the input and output refer to the same location in memory.
61
+
62
+
63
+ #### Thread Safety
64
+
65
+ Act as though no object is thread-safe. That is, if an object is being modified
66
+ on one thread, it should not be read from or written to on another. One thread
67
+ at a time. If possible, don't share objects between threads. The best case
68
+ scenario is you are passing serializable messages to threads rather than giving
69
+ objects directly to other threads. That said, as long as only one thread is
70
+ interacting with a given object at a time, you should be fine. To reiterate
71
+ that with an example, if you have two threads and they both allocate their own
72
+ Vec3 object, you're fine. If you have two threads and they're both using the
73
+ same Vec3 object, you are playing with fire.
74
+
75
+ Typed arrays, like Vec3Array and so on, require a little more explanation. When
76
+ accessing elements of a typed array, the array returns an object that accesses
77
+ the array's memory. The object does not have its own buffer to play with. As
78
+ such, arrays and the elements of arrays are both not thread-safe and you should
79
+ not modify an array or its elements from multiple threads at the same time.
80
+ Also, never attempt to fetch an element from an array on multiple threads at a
81
+ time, as the underlying object cache of the array is being modified even if you
82
+ aren't altering any array elements.
83
+
84
+ If you need to pass an array's element to another thread but don't care about
85
+ it modifying the underlying array data, simply #copy, #clone, or #dup the
86
+ fetched object and pass ownership of the copy to the other thread -- or pass
87
+ the object via a deserializable message so that you're not even trying to pass
88
+ objects directly to threads.
89
+
90
+ When in doubt, don't use threads. When you have to use threads and are still in
91
+ doubt, use a messaging system to pass data between threads, like [ZeroMQ],
92
+ rather than passing objects directly to threads. Safety first.
93
+
94
+ (Further note: all snow-math types work with Marshal.load and Marshal.dump, so
95
+ make use of that where it's practical and smart to do so.)
96
+
97
+ [ZeroMQ]: http://www.zeromq.org
64
98
 
65
99
 
66
100
  #### Shared by All Types
@@ -131,562 +165,6 @@ obvious but are as follows:
131
165
  Swizzling four components returns a Quat.
132
166
 
133
167
 
134
- ### Types
135
-
136
- #### Snow::Vec3
137
-
138
- class Snow::Vec3
139
-
140
- def self.new() -> Vec3[0, 0, 0]
141
- def self.new(x, y, z) -> Vec3[x, y, z]
142
- def self.new(other: Vec3 | Vec4 | Quat) -> Vec3[other.x, other.y, other.z]
143
- Aliased as :[], so you can use Vec3[0, 1, 2] to call Vec3.new(0, 1, 2).
144
-
145
- self == rhs
146
- Compares whether two Vec3s are equivalent. rhs may also be a Quat or Vec4,
147
- in which case the first three components of either will be compared with
148
- self.
149
-
150
- def set() -> self [no-op]
151
- def set(x, y, z) -> self
152
- def set(other) -> self
153
- Set takes the same arguments as self.new(...) and will call the same initialize
154
- function as new(). If no arguments are provided to set, it does nothing.
155
-
156
- def copy(output = nil) -> new vec3 or output
157
- If output is nil, this is equivalent to calling o.dup or o.class.new(o).
158
- With an output, the method copies self's components to other. For the most
159
- part, you probably only want to use this with an output.
160
-
161
- def inverse(output = nil) -> new vec3 or output
162
- def inverse! -> self
163
- ~vec3 -> new vec3
164
- Returns a vector whose components are the multiplicative inverse of the
165
- vector's components.
166
-
167
- def negate(output = nil) -> new vec3 or output
168
- def negate! -> self
169
- -vec3 -> new vec3
170
- Returns a vector whose components are the negated form of the vector's
171
- components. Beware of -0.0 here.
172
-
173
- def normalize(output = nil) -> new vec3 or output
174
- def normalize!() -> self
175
-
176
- def multiply_vec3(rhs, output = nil) -> new vec3 or output
177
- Multiplies both vector's components together and returns the result.
178
-
179
- def multiply(vec3, output = nil) -> same as multiply_vec3
180
- def multiply(scalar, output = nil) -> same as scale
181
- def multiply!(rhs) -> same as multiply(rhs, self)
182
- vec3 * rhs -> vec3.multiply(rhs)
183
-
184
- def add(rhs, output = nil) -> new vec3 or output
185
- def add!(rhs)
186
- vec3 + vec3
187
-
188
- def subtract(rhs, output = nil) -> new vec3 or output
189
- def subtract!(rhs) -> self
190
- vec3 - vec3
191
-
192
- def project(normal, output = nil) -> new vec4 or output
193
- def reflect(normal, output = nil) -> new vec4 or output
194
- Returns either the projected or reflected vector, respectively. These
195
- methods expect the 'normal' argument to be normalized -- that is, they
196
- will not normalize their input for you.
197
-
198
- def cross_product(rhs, output = nil) -> new vec3 or output
199
- def cross_product!(rhs) -> self
200
- vec3 ^ vec3 -> new vec3
201
-
202
- def dot_product(rhs) -> Float
203
- vec3 ** vec3 -> float
204
-
205
- def magnitude_squared -> Float
206
- def magnitude -> Float
207
- Returns the squared magnitude and the magnitude, respectively. To give you
208
- an idea of the difference, magnitude == Math.sqrt(magnitude_squared). So
209
- if you don't need the exact magnitude and only want to compare the magnitude
210
- of two things, you can skip a call to sqrt and use the squared magnitude.
211
-
212
- def scale(scalar, output = nil) -> new vec3 or output
213
- vec3 * scalar
214
- def divide(scalar, output = nil) -> new vec3 or output
215
- vec3 / scalar
216
- Multiplies or divides all components of the vector by a scalar. In the case
217
- of divide, a scalar of 0 is undefined behaviour.
218
-
219
- def size -> size in bytes
220
- def length -> length in floats
221
- size is either 24 or 12, depending on whether the gem was built to use
222
- floats or doubles. length is always 3.
223
-
224
- def x
225
- def x=(new_x)
226
- Same as fetch(0) and store(0, new_x) respectively
227
-
228
- def y
229
- def y=(new_y)
230
- Same as fetch(1) and store(1, new_y) respectively
231
-
232
- def z
233
- def z=(new_z)
234
- Same as fetch(2) and store(2, new_z) respectively
235
-
236
- end
237
-
238
-
239
-
240
- #### Snow::Vec4
241
-
242
- Vec4 is fundamentally the same as Vec3, except it lacks a `cross_product`
243
- function, has four components, and provides a `w` accessor for the fourth
244
- component. In addition, it is at times interchangeable with Quat.
245
-
246
- class Snow::Vec4
247
-
248
- def self.new() -> Vec4[0, 0, 0, 1]
249
- def self.new(x, y, z, w = 1) -> Vec4[x, y, z, w]
250
- def self.new(other: Vec3 | Vec4 | Quat) -> Vec4[other.x, other.y, other.z, other.w | 1]
251
- Aliased as :[], so you can use Vec4[0, 1, 2, 3] to call Vec4.new(0, 1, 2, 3).
252
- When calling Vec4.new and supplying a Vec3 to copy from, the fourth component,
253
- w, will be set to 1.
254
-
255
- self == rhs
256
- Compares whether two Vec4s are equivalent. rhs may also be a Quat.
257
-
258
- def set() -> self [no-op]
259
- def set(x, y, z, w = 1) -> self
260
- def set(other) -> self
261
- Set takes the same arguments as self.new(...) and will call the same initialize
262
- function as new(). If no arguments are provided to set, it does nothing.
263
-
264
- def copy(output = nil) -> new vec4 or output
265
- If output is nil, this is equivalent to calling o.dup or o.class.new(o).
266
- With an output, the method copies self's components to other. For the most
267
- part, you probably only want to use this with an output.
268
-
269
- def inverse(output = nil) -> new vec4 or output
270
- def inverse! -> self
271
- ~vec4 -> new vec4
272
- Returns a vector whose components are the multiplicative inverse of the
273
- vector's components.
274
-
275
- def negate(output = nil) -> new vec4 or output
276
- def negate! -> self
277
- -vec4 -> new vec4
278
- Returns a vector whose components are the negated form of the vector's
279
- components. Beware of -0.0 here.
280
-
281
- def normalize(output = nil) -> new vec4 or output
282
- def normalize!() -> self
283
-
284
- def multiply_vec4(rhs, output = nil) -> new vec4 or output
285
- def multiply_vec4!(rhs) -> self
286
- vec4 * vec4 -> new vec4
287
- Multiplies both vector's components together and returns the result.
288
-
289
- def multiply(vec4, output = nil) -> same as multiply_vec4
290
- def multiply(numeric, output = nil) -> same as scale
291
- def multiply!(rhs) -> same as multiply(rhs, self)
292
- vec4 * rhs -> vec4.multiply(rhs)
293
-
294
- def add(rhs, output = nil) -> new vec4 or output
295
- def add!(rhs) -> self
296
- vec4 + vec4 -> new vec4
297
-
298
- def subtract(rhs, output = nil) -> new vec4 or output
299
- def subtract!(rhs) -> self
300
- vec4 - vec4 -> new vec4
301
-
302
- def project(normal, output = nil) -> new vec4 or output
303
- def reflect(normal, output = nil) -> new vec4 or output
304
- Returns either the projected or reflected vector, respectively. These
305
- methods expect the 'normal' argument to be normalized -- that is, they
306
- will not normalize their input for you.
307
-
308
- def dot_product(rhs) -> Float
309
- vec4 ** vec4 -> Float
310
-
311
- def magnitude_squared -> Float
312
- def magnitude -> Float
313
- Returns the squared magnitude and the magnitude, respectively. To give you
314
- an idea of the difference, magnitude == Math.sqrt(magnitude_squared). So
315
- if you don't need the exact magnitude and only want to compare the magnitude
316
- of two things, you can skip a call to sqrt and use the squared magnitude.
317
-
318
- def scale(scalar, output = nil) -> new vec4 or output
319
- vec4 * scalar -> new vec4
320
- def divide(scalar, output = nil) -> new vec4 or output
321
- vec4 / scalar -> new vec4
322
- Multiplies or divides all components of the vector by a scalar. In the case
323
- of divide, a scalar of 0 is undefined behaviour.
324
-
325
- def size -> size in bytes
326
- def length -> length in floats
327
- size is either 32 or 16. depending on whether the gem was built to use
328
- floats or doubles. length is always 4.
329
-
330
- def x
331
- def x=(new_x)
332
- Same as fetch(0) and store(0, new_x) respectively
333
-
334
- def y
335
- def y=(new_y)
336
- Same as fetch(1) and store(1, new_y) respectively
337
-
338
- def z
339
- def z=(new_z)
340
- Same as fetch(2) and store(2, new_z) respectively
341
-
342
- def w
343
- def w=(new_w)
344
- Same as fetch(3) and store(3, new_w) respectively
345
-
346
- end
347
-
348
-
349
-
350
- #### Snow::Quat
351
-
352
- Quat is functionally similar to Vec4, except it provides some functions specific
353
- to quaternions. Why these aren't just part of Vec4 is a mystery for the ages
354
- and an attempt to make code more readable.
355
-
356
- class Snow::Quat
357
-
358
- def self.new() -> Quat[0, 0, 0, 1]
359
- def self.new(x, y, z, w = 1) -> Quat[x, y, z, w]
360
- def self.new(Mat4) -> Quat from Mat4
361
- def self.new(other: Vec3 | Quat | Quat) -> Quat[other.x, other.y, other.z, other.w | 1]
362
- Aliased as :[], so you can use Quat[0, 1, 2, 3] to call Quat.new(0, 1, 2, 3).
363
- When calling Quat.new and supplying a Vec3 to copy from, the fourth component,
364
- w, will be set to 1. If provided a Mat4, it will be converted to a Quat. Without
365
- arguments, Quat.new will return an identity quaternion.
366
-
367
- self == rhs
368
- Compares whether two Quats are equivalent. rhs may be either a Quat or
369
- Vec4.
370
-
371
- def set() -> self [no-op]
372
- def set(x, y, z, w = 1) -> self
373
- def set(Mat4) -> self
374
- def set(other) -> self
375
- This takes the same arguments as self.new and in fact just calls the Quat's
376
- initializer with the new arguments. The only difference is that calling set()
377
- without arguments will not set this quaternion to the identity quaternion,
378
- because the allocator is the one responsible for that. (To do that, use
379
- load_identity)
380
-
381
- load_identity() -> self
382
- Resets self to the identity quaternion.
383
-
384
- def copy(output = nil) -> new quat or output
385
- If output is nil, this is equivalent to calling o.dup or o.class.new(o).
386
- With an output, the method copies self's components to other. For the most
387
- part, you probably only want to use this with an output.
388
-
389
- def inverse(output = nil) -> new quat or output
390
- def inverse! -> self
391
- ~quat -> new quat
392
- Returns the inverse of this quaternion (or writes the inverse to an output
393
- or itself). This is not the same as a vector's inverse -- keep that in mind.
394
-
395
- def negate(output = nil) -> new quat or output
396
- def negate! -> self
397
- -quat -> new quat
398
- Returns a quaternion whose components are the negated form of the vector's
399
- components. Beware of -0.0 here. This is the same as negating a vector.
400
-
401
- def normalize(output = nil) -> new quat or output
402
- def normalize!() -> self
403
-
404
- def multiply_quat(rhs: Quat, output = nil) -> new quat or output
405
- def multiply!(rhs: Quat) -> self
406
- quat * quat -> new quat
407
- The first form, multiply_quat, multiplies two quaternions and returns the
408
- resulting quaternion. The second form, multiply!, is the same as calling
409
- multiply_quat(rhs, self).
410
-
411
- def mutliply_vec3(rhs: Vec3, output = nil) -> new vec3 or output
412
- quat * vec3 -> new vec3
413
- Multiplies a vec3 by a quat and returns the resulting vec3.
414
-
415
- def multiply(vec3, output = nil) -> new vec3 or output
416
- def multiply(quat, output = nil) -> new quat or output
417
- def multiply(numeric, output = nil) -> new quat or output
418
- quat * rhs -> quat.multiply(rhs)
419
- In its first form, it's the same as #multiply_vec3. In its second, it's the
420
- same as #multiply_quat. In its third, it's the same as #scale.
421
-
422
- def add(rhs, output = nil) -> new quat or output
423
- def add!(rhs)
424
- quat + quat -> new quat
425
- Same as Vec4#add and Vec4#add!.
426
-
427
- def subtract(rhs, output = nil) -> new quat or output
428
- def subtract!(rhs) -> self
429
- quat - quat -> new quat
430
- Same as Vec4#subtract and Vec4#subtract!.
431
-
432
- def dot_product(rhs) -> Float
433
- quat ** quat -> new quat
434
- Same as Vec4#dot_product.
435
-
436
- def magnitude_squared -> Float
437
- def magnitude -> Float
438
- Returns the squared magnitude and the magnitude, respectively. To give you
439
- an idea of the difference, magnitude == Math.sqrt(magnitude_squared). So
440
- if you don't need the exact magnitude and only want to compare the magnitude
441
- of two things, you can skip a call to sqrt and use the squared magnitude.
442
-
443
- def scale(scalar, output = nil) -> new quat or output
444
- quat * scalar -> new quat
445
- def divide(scalar, output = nil) -> new quat or output
446
- quat / scalar -> new quat
447
- Multiplies or divides all components of the quaternion by a scalar. In the
448
- case of divide, a scalar of 0 is undefined behaviour.
449
-
450
- def size -> size in bytes
451
- def length -> length in floats
452
- size is either 32 or 16. depending on whether the gem was built to use
453
- floats or doubles. length is always 4.
454
-
455
- def x
456
- def x=(new_x)
457
- Same as fetch(0) and store(0, new_x) respectively
458
-
459
- def y
460
- def y=(new_y)
461
- Same as fetch(1) and store(1, new_y) respectively
462
-
463
- def z
464
- def z=(new_z)
465
- Same as fetch(2) and store(2, new_z) respectively
466
-
467
- def w
468
- def w=(new_w)
469
- Same as fetch(3) and store(3, new_w) respectively
470
-
471
- end
472
-
473
-
474
-
475
- #### Snow::Mat3
476
-
477
- class Snow::Mat3
478
-
479
- def self.new() -> identity mat3
480
- def self.new(m1, m2, m3, ..., m9) -> mat3 with the given components
481
- def self.new([Vec3, Vec3, Vec3]) -> mat3 with rows defined by the given Vec3s
482
- def self.new(Quat) -> Mat3 from Quat
483
- def self.new(Mat3) -> copy of the given Mat3
484
- def self.new(Mat4) -> copy of the given Mat4 as a Mat3
485
- Aliased as `[]`, so you can use Mat3[...] to create a new Mat3.
486
-
487
- def self.angle_axis(angle_degrees, axis: Vec3, output = nil) -> new mat3 or output
488
- Returns a new rotation matrix for the given angle and axis. The angle is in
489
- degrees.
490
-
491
- def set(...) -> self
492
- Same variations and arguments as self.new(...)
493
-
494
- def load_identity() -> self
495
- Resets self to the identity matrix.
496
-
497
- def to_mat4(output = nil) -> new mat4 or output
498
-
499
- def copy(output = nil) -> new mat3 or output
500
- Copies self to the given output matrix.
501
-
502
- def transpose(output = nil) -> new mat3 or output
503
- def transpose!() -> self
504
-
505
- def inverse(output = nil) -> new mat3 or output
506
- def inverse!() -> self on success, nil on failure
507
-
508
- def multiply_mat3(rhs, output = nil) -> new mat3 or output
509
- def multiply_mat3!(rhs) -> self
510
- Multiplies this and the rhs matrix and returns the result.
511
-
512
- def rotate_vec3(rhs, output = nil) -> new vec3 or output
513
- Rotates a vec3 by the matrix and returns the result.
514
-
515
- def inverse_rotate_vec3(vec3, output = nil) -> new vec3 or output
516
- Essentially just a convenience function.
517
-
518
- def multiply(mat3, output = nil) -> same as mutliply_mat3
519
- def multiply(vec3, output = nil) -> same as mutliply_vec3
520
- def multiply(numeric, output = nil) -> same as scale(N, N, N, output)
521
- def multiply!(rhs) -> same as multiply(rhs, self)
522
- The fourth form, multiply!, will fail if attempting to multiply a vec3.
523
-
524
- def adjoint(output = nil) -> new mat3 or output
525
- def adjoint!() -> new mat3 or output
526
-
527
- def cofactor(output = nil) -> new mat3 or output
528
- def cofactor!() -> new mat3 or output
529
-
530
- def determinant -> Float
531
-
532
- def scale(x, y, z, output = nil) -> new mat3 or output
533
- def scale!(x, y, z) -> new mat3 or output
534
- Returns a matrix with its columns scaled by the given components.
535
-
536
- def set_row3, set_column3(index, V) -> self
537
- V is a vector with the number of components in the function name. Sets the
538
- Mat3's row or column to the components of the given Vec3.
539
-
540
- def get_row3, get_column3(index, output = nil) -> new vec3 for row/column
541
- Returns a Vec3 for the given row or column in the Mat3.
542
-
543
- end
544
-
545
-
546
-
547
- #### Snow::Mat4
548
-
549
- class Snow::Mat4
550
-
551
- def self.new() -> identity mat4
552
- def self.new(m1, m2, m3, ..., m16) -> mat4 with the given components
553
- def self.new([Vec4, Vec4, Vec4, Vec4]) -> mat4 with rows defined by the given Vec4s
554
- def self.new(Quat) -> Mat4 from Quat
555
- def self.new(Mat3) -> copy of the given Mat3 as a Mat4
556
- def self.new(Mat4) -> copy of the given Mat4
557
- Aliased as `[]`, so you can use Mat4[...] to create a new Mat4.
558
-
559
- def self.translation(x, y, z, output = nil) -> new mat4 or output
560
- def self.translation(Vec3, output = nil) -> new mat4 or output
561
- Returns a translation matrix.
562
-
563
- def self.angle_axis(angle_degrees, axis: Vec3, output = nil) -> new mat4 or output
564
- Returns a new rotation matrix for the given angle and axis. The angle is in
565
- degrees. This might offend some people, but I assure you, your sanity will
566
- be preserved by doing this.
567
-
568
- def self.frustum(left, right, bottom, top, z_near, z_far, output = nil) -> new mat4 or output
569
- def self.orthographic(left, right, bottom, top, z_near, z_far, output = nil) -> new mat4 or output
570
- def self.perspective(fov_y, aspect, z_near, z_far, output = nil) -> new mat4 or output
571
- Returns the given kinds of projection matrices. In the case of perspective,
572
- fov_y is specified in degrees. Again, your sanity will thank you.
573
-
574
- def self.look_at(eye: Vec3, center: Vec3, up: Vec3, output = nil) -> new mat4 or output
575
- Returns a look-at matrix.
576
-
577
- def set(...)
578
- Same variations and arguments as self.new(...)
579
-
580
- def load_identity() -> self
581
- Resets self to the identity matrix.
582
-
583
- def to_mat3(output = nil) -> new mat3 or output
584
-
585
- def copy(output = nil) -> new mat4 or output
586
- Copies self to the given output matrix.
587
-
588
- def transpose(output = nil) -> new mat4 or output
589
- def transpose!() -> self
590
-
591
- def inverse_orthogonal(output = nil) -> new mat4 or output
592
- def inverse_affine(output = nil) -> new mat4 or output on success, nil on failure
593
- def inverse_general(output = nil) -> new mat4 or output on success, nil on failure
594
- def inverse_orthogonal!() -> self
595
- def inverse_affine!() -> self on success, nil on failure
596
- def inverse_general!() -> self on success, nil on failure
597
-
598
- def translate(x, y, z, output = nil) -> new mat4 or output
599
- def translate(vec3, output = nil) -> new mat4 or output
600
- def translate!(x, y, z) -> self
601
- def translate!(vec3) -> self
602
- Essentially multiplies this matrix by a translation matrix with the given
603
- translation and returns it.
604
-
605
- def multiply_mat4(rhs, output = nil) -> new mat4 or output
606
- def multiply_mat4!(rhs) -> self
607
- Multiplies this and the rhs matrix and returns the result.
608
-
609
- def multiply_vec4(rhs, output = nil) -> new vec4 or output
610
- Transforms a vec4 by the matrix and returns the result.
611
-
612
- def multiply_vec3(rhs, output = nil) -> new vec3 or output
613
- def rotate_vec3(rhs, output = nil) -> new vec3 or output
614
- In the first form, transforms a vec3 by the matrix and returns the result.
615
- In the second form, rotates a vec3 by the matrix, ignoring any translation,
616
- and returns the result.
617
-
618
- def inverse_rotate_vec3(vec3, output = nil) -> new vec3 or output
619
- Essentially just a convenience function.
620
-
621
- def multiply(mat4, output = nil) -> same as mutliply_mat4
622
- def multiply(vec3, output = nil) -> same as mutliply_vec3
623
- def multiply(numeric, output = nil) -> same as scale(N, N, N, output)
624
- def multiply!(rhs) -> same as multiply(rhs, self)
625
- The fourth form, multiply!, will fail if attempting to multiply a vec3.
626
- Aliased as `*`
627
-
628
- def adjoint(output = nil) -> new mat4 or output
629
- def adjoint!() -> new mat4 or output
630
-
631
- def determinant -> Float
632
-
633
- def scale(x, y, z, output = nil) -> new mat4 or output
634
- def scale!(x, y, z) -> new mat4 or output
635
- Returns a matrix with its inner 3x3 matrix's columns scaled by the given
636
- components.
637
-
638
- def set_row3, set_column3, set_row4, set_column4(index, V) -> self
639
- Sets the Mat4's row or column to the components of the given vec3 or vec4.
640
- V must be a vector with the number of components specified by the function
641
- name.
642
-
643
- def get_row3, get_column3, get_row4, get_column4(index, output = nil) -> new vec3 or vec4 for row/column
644
- Returns a vector with the number of components as specified by the name for
645
- the given row or column in the Mat4.
646
-
647
- end
648
-
649
-
650
-
651
- #### Snow::Vec3Array, Snow::Vec4Array, Snow::QuatArray, Snow::Mat3Array, Snow::Mat4Array
652
-
653
- All typed arrays have the same interface and differ only in the kind of object
654
- they contain. As such, this applies to all typed arrays.
655
-
656
- class Snow::Vec3Array, Snow::Vec4Array, Snow::QuatArray, Snow::Mat3Array, Snow::Mat4Array
657
-
658
- def self.new(length) -> new array
659
- def self.new(array) -> copy of array
660
- Aliased as `[]`, so you can create an array, for example, by writing
661
- `Vec3Array[16]`. The length provided must be greater than zero, otherwise
662
- the returned array is nil.
663
-
664
- Array elements are always uninitialized on allocation, so they will often
665
- contain garbage values. It is your responsibility to initialize them as
666
- needed.
667
-
668
- def fetch(index) -> object of array element type
669
- Returns an object that references the array's internal data. Manipulating
670
- this object manipulates the data in the array -- it is not simply a copy of
671
- the array's data. The returned object is cached, so subsequent calls to
672
- fetch will return the same object (unless resized, in which case the cache
673
- is destroyed and objects previously bound to the array are invalid -- use
674
- of those objects following a resize is considered undefined behaviour).
675
-
676
- def store(index, value) -> value
677
- Copies a value object's data into the array's data. If the value object is
678
- already part of the array -- that is, it was created using the array's
679
- fetch function, this is a no-op.
680
-
681
- def resize!(new_length) -> self
682
- def resize(new_length) -> new array
683
- Resizes the array and returns the value. In the first form, the underlying
684
- buffer for the array is resized. In the second form, a new array is
685
- allocated and returned.
686
-
687
- end
688
-
689
-
690
168
 
691
169
  ## License
692
170