cglm 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1b055efd84ea5f04fd2db0580fbc15df485b59c45afe73c41aa8e0eff9701d1
4
- data.tar.gz: 5a65edbb6ee9a569fa87459f630e40c6b98d94c705658b9c365accdcc0c304b2
3
+ metadata.gz: 89c806f5a00ef690cfead8c0c384f4a7c0cc5c1734129a43313f952e4c96b04f
4
+ data.tar.gz: 3609604cbbee1cc090c70ed9e21cde21f77be10a20cdfd1c3964c955a53bb47a
5
5
  SHA512:
6
- metadata.gz: 66ad4516dc605c3fe302ce923ad2a54f027b7ee7d2601b4b65d2e1bf6f4ca681fd344a137baed3c12ea5c01f4124cf3bd6d6d0d5c89c3b4b46fd15690a9d1ed5
7
- data.tar.gz: 975f418d0f8c3a9e74f726bd8423bd078a43f268d6263edb5198c06c45471d1215f4c78057c7d5fd0930158916606d1538de7838741d4794f89ce56be008b54f
6
+ metadata.gz: 65337d472039a5ad4e8a613b760f6de059d5461f19ad8410a6fe6e87e218a5303de8396dad3ba7311e5c41bc9caedf0274cb633fb08d091ef7b54b092169bb45
7
+ data.tar.gz: 6fa21d54b27454acda36f4bcb73bd0f99e17707448627d9ed50071076da60b0d3c8544ab8c000379efe5c04c2cabbd5f5f5cdf2a02aeee71e5093739c48ecf79
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cglm (0.1.3)
4
+ cglm (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/ext/cglm/rb_cglm.c CHANGED
@@ -5,6 +5,7 @@ VALUE rb_cFiddle = Qnil,
5
5
  rb_mCGLM = Qnil,
6
6
  rb_cCGLMBase = Qnil,
7
7
  rb_cVectorType = Qnil,
8
+ rb_cMatrixType = Qnil,
8
9
  rb_cMat3 = Qnil,
9
10
  rb_cMat4 = Qnil,
10
11
  rb_cVec3 = Qnil,
@@ -33,9 +34,9 @@ void Init_cglm(void) {
33
34
  rb_mCGLM = rb_define_module("CGLM");
34
35
  rb_mEuler = rb_define_module_under(rb_mCGLM, "Euler");
35
36
  rb_cCGLMBase = rb_define_class_under(rb_mCGLM, "Base", rb_cObject);
36
- rb_cMat3 = rb_define_class_under(rb_mCGLM, "Mat3", rb_cCGLMBase);
37
- rb_cMat4 = rb_define_class_under(rb_mCGLM, "Mat4", rb_cCGLMBase);
38
- rb_cCGLMBase = rb_define_class_under(rb_mCGLM, "Base", rb_cObject);
37
+ rb_cMatrixType = rb_define_class_under(rb_mCGLM, "MatrixType", rb_cCGLMBase);
38
+ rb_cMat3 = rb_define_class_under(rb_mCGLM, "Mat3", rb_cMatrixType);
39
+ rb_cMat4 = rb_define_class_under(rb_mCGLM, "Mat4", rb_cMatrixType);
39
40
  rb_cVectorType = rb_define_class_under(rb_mCGLM, "VectorType", rb_cCGLMBase);
40
41
  rb_cAABB = rb_define_class_under(rb_mCGLM, "AABB", rb_cCGLMBase);
41
42
  rb_cVec3 = rb_define_class_under(rb_mCGLM, "Vec3", rb_cVectorType);
@@ -130,22 +130,30 @@ VALUE rb_cglm_translate_z_self(VALUE self, VALUE flt) {
130
130
  }
131
131
 
132
132
  /* call-seq: translate(vec3) => new Mat4 */
133
- VALUE rb_cglm_translate_new(VALUE klass, VALUE vec_v) {
134
- VALUE dest = MAT4_NEW(ALLOC_MAT4);
133
+ VALUE rb_cglm_translate_new(int argc, VALUE *argv, VALUE klass) {
134
+ VALUE vec_v, dest;
135
+ rb_scan_args(argc, argv, "11", &vec_v, &dest);
136
+ if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
135
137
  glm_translate_make(VAL2MAT4(dest), VAL2VEC3(vec_v));
136
138
  return dest;
137
139
  }
138
140
 
139
141
  /* call-seq: scale(vec3) => new Mat4 */
140
- VALUE rb_cglm_scale_new(VALUE klass, VALUE vec_v) {
141
- VALUE dest = MAT4_NEW(ALLOC_MAT4);
142
+ VALUE rb_cglm_scale_new(int argc, VALUE *argv, VALUE klass) {
143
+ VALUE vec_v, dest;
144
+ rb_scan_args(argc, argv, "11", &vec_v, &dest);
145
+ if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
142
146
  glm_scale_make(VAL2MAT4(dest), VAL2VEC3(vec_v));
143
147
  return dest;
144
148
  }
145
149
 
146
- /* call-seq: rotate(axis, angle) => new Mat4 */
147
- VALUE rb_cglm_rotate_new(VALUE klass, VALUE axis, VALUE angle) {
148
- VALUE dest = MAT4_NEW(ALLOC_MAT4);
150
+ /*
151
+ * call-seq: rotate(axis, angle[, dest]) => dest | new Mat4
152
+ */
153
+ VALUE rb_cglm_rotate_new(int argc, VALUE *argv, VALUE klass) {
154
+ VALUE axis, angle, dest;
155
+ rb_scan_args(argc, argv, "21", &axis, &angle, &dest);
156
+ if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
149
157
  glm_rotate_make(VAL2MAT4(dest), (float) NUM2DBL(angle), VAL2VEC3(axis));
150
158
  return dest;
151
159
  }
@@ -318,8 +326,8 @@ void Init_cglm_affine() {
318
326
  rb_define_method(rb_cMat4, "decompose_rs", rb_cglm_decompose_rs, 2);
319
327
  rb_define_method(rb_cMat4, "decompose", rb_cglm_decompose, 3);
320
328
 
321
- rb_define_singleton_method(rb_cMat4, "translate", rb_cglm_translate_new, 1);
322
- rb_define_singleton_method(rb_cMat4, "scale", rb_cglm_scale_new, 1);
323
- rb_define_singleton_method(rb_cMat4, "rotate", rb_cglm_rotate_new, 2);
329
+ rb_define_singleton_method(rb_cMat4, "translate", rb_cglm_translate_new,-1);
330
+ rb_define_singleton_method(rb_cMat4, "scale", rb_cglm_scale_new, -1);
331
+ rb_define_singleton_method(rb_cMat4, "rotate", rb_cglm_rotate_new, -1);
324
332
  rb_define_singleton_method(rb_cMat4, "axis_angle_rotate_at", rb_cglm_rotate_at_new, 3);
325
333
  }
@@ -9,7 +9,9 @@ VALUE rb_cglm_quat_new_identity(int argc, VALUE *argv, VALUE self) {
9
9
  return dest;
10
10
  }
11
11
 
12
- /* call-seq: axis_angle(axis, angle[, dest]) => dest | new Quat */
12
+ /*
13
+ * call-seq: axis_angle(axis, angle[, dest]) => dest | new Quat
14
+ */
13
15
  VALUE rb_cglm_quat_new_axis_angle(int argc, VALUE *argv, VALUE self) {
14
16
  VALUE axis, angle, dest;
15
17
  rb_scan_args(argc, argv, "21", &axis, &angle, &dest);
data/lib/cglm/base.rb CHANGED
@@ -18,7 +18,8 @@ module CGLM
18
18
 
19
19
  def copy_to(other)
20
20
  size = addr.size > other.addr.size ? other.addr.size : addr.size
21
- other.addr[0, size] = addr[0, size]
21
+ other.addr[0, size] = addr
22
+ other
22
23
  end
23
24
 
24
25
  def dup(other = nil)
data/lib/cglm/mat3.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module CGLM
2
- class Mat3 < Base
2
+ class Mat3 < MatrixType
3
3
  # Performs multiplication with `other` and returns the result.
4
4
  #
5
5
  # * `other` is a Mat3 or Vec3.
@@ -23,5 +23,12 @@ module CGLM
23
23
  left = "#<#{self.class}@#{addr.to_i.to_s(16)} ["
24
24
  left + vals.join(",\n" + (" " * left.size)) + "]>"
25
25
  end
26
+
27
+ # Returns a flat array of floats, rather than the 2D array returned by
28
+ # #to_a. Equivalent to `to_a.flatten`, but more efficient.
29
+ def to_flat_a
30
+ addr = self.addr
31
+ addr[0, addr.size].unpack("F*")
32
+ end
26
33
  end
27
34
  end
data/lib/cglm/mat4.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module CGLM
2
- class Mat4 < Base
2
+ class Mat4 < MatrixType
3
3
  def initialize(initial_values = nil, **args)
4
4
  super(**args)
5
5
  case initial_values
@@ -0,0 +1,10 @@
1
+ module CGLM
2
+ class MatrixType < Base
3
+ # Returns a flat array of floats, rather than the 2D array returned by
4
+ # #to_a. Equivalent to `to_a.flatten`, but more efficient.
5
+ def to_flat_a
6
+ addr = self.addr
7
+ addr[0, addr.size].unpack("F*")
8
+ end
9
+ end
10
+ end
data/lib/cglm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CGLM
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/cglm.rb CHANGED
@@ -13,6 +13,7 @@ end
13
13
  module CGLM
14
14
  require 'cglm/base'
15
15
  require 'cglm/vector_type'
16
+ require 'cglm/matrix_type'
16
17
  require 'cglm/aabb'
17
18
  require 'cglm/vec3'
18
19
  require 'cglm/vec4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cglm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin MacKenzie IV
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -241,6 +241,7 @@ files:
241
241
  - lib/cglm/frustum.rb
242
242
  - lib/cglm/mat3.rb
243
243
  - lib/cglm/mat4.rb
244
+ - lib/cglm/matrix_type.rb
244
245
  - lib/cglm/plane.rb
245
246
  - lib/cglm/quat.rb
246
247
  - lib/cglm/sphere.rb