Class: CGLM::Vec4

Inherits:
VectorType show all
Defined in:
lib/cglm/vec4.rb,
ext/cglm/rb_cglm.c

Direct Known Subclasses

Plane, Quat, Sphere

Instance Attribute Summary

Attributes inherited from Base

#addr

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VectorType

#each, #initialize, #to_a, #to_enum

Methods inherited from Base

#dup, #initialize, #initialize_dup

Constructor Details

This class inherits a constructor from CGLM::VectorType

Class Method Details

.alignmentObject



16
# File 'ext/cglm/rb_cglm_vec4.c', line 16

VALUE rb_cglm_vec4_alignment_bytes(VALUE klass) { return SIZET2NUM(VEC4_ALIGNMENT); }

.blackObject



34
35
36
37
38
39
# File 'ext/cglm/rb_cglm_vec4.c', line 34

VALUE rb_cglm_vec4_black(VALUE self) {
  VALUE dest = VEC4_NEW(ALLOC_VEC4);
  vec4 black = GLM_VEC4_BLACK;
  memcpy(&VAL2VEC4(dest), &black, sizeof(vec4));
  return dest;
}

.oneObject



27
28
29
30
31
32
# File 'ext/cglm/rb_cglm_vec4.c', line 27

VALUE rb_cglm_vec4_one(VALUE self) {
  VALUE dest = VEC4_NEW(ALLOC_VEC4);
  vec4 one = GLM_VEC4_ONE;
  memcpy(&VAL2VEC4(dest), &one, sizeof(vec4));
  return dest;
}

.random([dest]) ⇒ dest | new Vec4

Fills dest or a new Vec4 with random values, and returns it.

Returns:



624
625
626
627
628
629
630
631
632
633
634
635
# File 'ext/cglm/rb_cglm_vec4.c', line 624

VALUE rb_cglm_vec4_new_random(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);

  VAL2VEC4(dest)[0] = drand48();
  VAL2VEC4(dest)[1] = drand48();
  VAL2VEC4(dest)[2] = drand48();
  VAL2VEC4(dest)[3] = drand48();

  return dest;
}

.random([dest]) ⇒ dest | new Vec4

Fills dest or a new Vec4 with random values, and returns it.

Returns:



624
625
626
627
628
629
630
631
632
633
634
635
# File 'ext/cglm/rb_cglm_vec4.c', line 624

VALUE rb_cglm_vec4_new_random(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);

  VAL2VEC4(dest)[0] = drand48();
  VAL2VEC4(dest)[1] = drand48();
  VAL2VEC4(dest)[2] = drand48();
  VAL2VEC4(dest)[3] = drand48();

  return dest;
}

.sizeObject



14
# File 'ext/cglm/rb_cglm_vec4.c', line 14

VALUE rb_cglm_vec4_size_bytes(VALUE klass) { return SIZET2NUM(vec4_size()); }

.zeroObject



41
42
43
44
45
46
# File 'ext/cglm/rb_cglm_vec4.c', line 41

VALUE rb_cglm_vec4_zero(VALUE self) {
  VALUE dest = VEC4_NEW(ALLOC_VEC4);
  vec4 zero = GLM_VEC4_ZERO;
  memcpy(&VAL2VEC4(dest), &zero, sizeof(vec4));
  return dest;
}

Instance Method Details

#*(other) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/cglm/vec4.rb', line 48

def *(other)
  case other
  when VectorType then mul_vec4(other)
  when Numeric    then mul_scalar(other)
  else false
  end
end

#+(other) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/cglm/vec4.rb', line 32

def +(other)
  case other
  when VectorType then add_vec4(other)
  when Numeric    then add_scalar(other)
  else false
  end
end

#-(other) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/cglm/vec4.rb', line 40

def -(other)
  case other
  when VectorType then sub_vec4(other)
  when Numeric    then sub_scalar(other)
  else false
  end
end

#/(other) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/cglm/vec4.rb', line 56

def /(other)
  case other
  when VectorType then div_vec4(other)
  when Numeric    then div_scalar(other)
  else false
  end
end

#==(other) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/cglm/vec4.rb', line 11

def ==(other)
  case other
  when VectorType then equals_vec4(other)
  when Numeric    then equals_scalar(other)
  else false
  end
end

#=~(other) ⇒ Object

Returns true if the given value is very close to this Vec4. If other is a scalar (number), each component in this vector must be very close to the scalar. If it's a vector, it must be a Vec4 and each component of this Vec4 must be very close to the corresponding component of other. See #equalish_vec4 and #equalish_scalar.



24
25
26
27
28
29
30
# File 'lib/cglm/vec4.rb', line 24

def =~(other)
  case other
  when VectorType then equalish_vec4(other)
  when Numeric    then equalish_scalar(other)
  else false
  end
end

#[](index) ⇒ Object



3
4
5
6
# File 'ext/cglm/rb_cglm_vec4.c', line 3

VALUE rb_cglm_vec4_aref(VALUE self, VALUE index) {
  CHECK_RANGE(index, 0, 3);
  return DBL2NUM(VAL2VEC4(self)[NUM2INT(index)]);
}

#[]=(index, val) ⇒ Object



8
9
10
11
12
# File 'ext/cglm/rb_cglm_vec4.c', line 8

VALUE rb_cglm_vec4_aset(VALUE self, VALUE index, VALUE val) {
  CHECK_RANGE(index, 0, 3);
  VAL2VEC4(self)[NUM2INT(index)] = NUM2DBL(val);
  return self;
}

#add_scalar(b[, dest]) ⇒ dest | new Vec4

Adds the Numeric b to each component of self, placing the result in dest. If dest is omitted, a new Vec4 is created and returned.

Returns:



110
111
112
113
114
115
116
# File 'ext/cglm/rb_cglm_vec4.c', line 110

VALUE rb_cglm_vec4_add_scalar(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_adds(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(dest));
  return dest;
}

#add_scalar!(b) ⇒ self

Adds the Numeric b to each component of self, modifying self in-place and returning it.

Returns:

  • (self)


158
159
160
161
# File 'ext/cglm/rb_cglm_vec4.c', line 158

VALUE rb_cglm_vec4_add_scalar_self(VALUE self, VALUE b) {
  glm_vec4_adds(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(self));
  return self;
}

#add_vec4(b[, dest]) ⇒ dest | new Vec4

Adds self and b together, placing the result in dest. If dest is omitted, a new Vec4 is created and returned.

Returns:



97
98
99
100
101
102
103
# File 'ext/cglm/rb_cglm_vec4.c', line 97

VALUE rb_cglm_vec4_add_vec4(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_add(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(dest));
  return dest;
}

#add_vec4!(b) ⇒ self

Adds self and b together, modifying self in-place and returning it.

Returns:

  • (self)


148
149
150
151
# File 'ext/cglm/rb_cglm_vec4.c', line 148

VALUE rb_cglm_vec4_add_vec4_self(VALUE self, VALUE b) {
  glm_vec4_add(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(self));
  return self;
}

#addadd(other, dest) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/cglm/vec4.rb', line 64

def addadd(other, dest)
  case other
  when VectorType then addadd_vec4(other, dest)
  when Numeric    then addadd_scalar(other, dest)
  else false
  end
end

#addadd_vec4(other, dest) ⇒ Object

Adds self to other and adds that result to dest. Equivalent to dest += (self + other). Returns dest.

  • dest is not optional for this method, as it is for most others.


307
308
309
310
# File 'ext/cglm/rb_cglm_vec4.c', line 307

VALUE rb_cglm_vec4_addadd_vec4(VALUE self, VALUE other, VALUE dest) {
  glm_vec4_addadd(VAL2VEC4(self), VAL2VEC4(other), VAL2VEC4(dest));
  return dest;
}

#broadcast!(val) ⇒ self

Sets each member of self to the specified Numeric value and returns self.

Returns:

  • (self)


484
485
486
487
# File 'ext/cglm/rb_cglm_vec4.c', line 484

VALUE rb_cglm_vec4_broadcast_self(VALUE self, VALUE val) {
  glm_vec4_broadcast(NUM2FLT(val), VAL2VEC4(self));
  return self;
}

#clamp(min, max, *extra) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/cglm/vec4.rb', line 88

def clamp(min, max, *extra)
  case min
  when VectorType then clamp_vec4(min, max, *extra)
  when Numeric    then clamp_scalar(min, max, *extra)
  else raise ArgumentError, 'need Vec4 or'
  end
end

#clamp!(min, max) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/cglm/vec4.rb', line 96

def clamp!(min, max)
  case min
  when VectorType then clamp_vec4!(min, max)
  when Numeric    then clamp_scalar!(min, max)
  else raise ArgumentError, 'need Vec4 or Scalar'
  end
end

#clamp_scalar(min, max[, dest]) ⇒ dest | new Vec4

Clamps each component in self to the range given by min and max. Places the result into dest and returns dest. Creates and returns a new Vec4 if dest is omitted.

Returns:



414
415
416
417
418
419
420
421
# File 'ext/cglm/rb_cglm_vec4.c', line 414

VALUE rb_cglm_vec4_clamp_scalar(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, dest;
  rb_scan_args(argc, argv, "21", &a, &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  memcpy(&VAL2VEC4(dest), &VAL2VEC4(self), sizeof(vec4));
  glm_vec4_clamp(VAL2VEC4(dest), NUM2FLT(a), NUM2FLT(b));
  return dest;
}

#clamp_scalar!(min, max) ⇒ self

Clamps each component in self to the range given by min and max. Places the result into self and returns self.

Returns:

  • (self)


428
429
430
431
# File 'ext/cglm/rb_cglm_vec4.c', line 428

VALUE rb_cglm_vec4_clamp_scalar_self(VALUE self, VALUE a, VALUE b) {
  glm_vec4_clamp(VAL2VEC4(self), NUM2FLT(a), NUM2FLT(b));
  return self;
}

#clamp_vec4(min, max[, dest]) ⇒ dest | new Vec4

Clamps each component in self to the range given by min and max. Places the result into dest and returns dest. Creates and returns a new Vec4 if dest is omitted.

Returns:



439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'ext/cglm/rb_cglm_vec4.c', line 439

VALUE rb_cglm_vec4_clamp_vec4(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, dest;
  rb_scan_args(argc, argv, "21", &a, &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  memcpy(&VAL2VEC4(dest), &VAL2VEC4(self), sizeof(vec4));
  vec4 *s = &VAL2VEC4(dest);
  vec4 *low = &VAL2VEC4(a);
  vec4 *high = &VAL2VEC4(b);
  for (int i = 0; i < 4; i++) {
    (*s)[i] = (*low)[i] > (*high)[i] ? (*low)[i] : (*high)[i];
  }
  return dest;
}

#clamp_vec4!(min, max) ⇒ self

Clamps each component in self to the range given by min and max. Places the result into self and returns self.

Returns:

  • (self)


458
459
460
461
462
463
464
465
466
# File 'ext/cglm/rb_cglm_vec4.c', line 458

VALUE rb_cglm_vec4_clamp_vec4_self(VALUE self, VALUE a, VALUE b) {
  vec4 *s = &VAL2VEC4(self);
  vec4 *low = &VAL2VEC4(a);
  vec4 *high = &VAL2VEC4(b);
  for (int i = 0; i < 4; i++) {
    (*s)[i] = (*low)[i] > (*high)[i] ? (*low)[i] : (*high)[i];
  }
  return self;
}

#copy_to(other) ⇒ Object



48
49
50
51
# File 'ext/cglm/rb_cglm_vec4.c', line 48

VALUE rb_cglm_vec4_copy_to(VALUE self, VALUE other) {
  glm_vec4_copy(VAL2VEC4(self), VAL2VEC4(other));
  return other;
}

#distance(vec) ⇒ Numeric

Returns the distance between this vector and the specified one.

Returns:



376
377
378
# File 'ext/cglm/rb_cglm_vec4.c', line 376

VALUE rb_cglm_vec4_distance(VALUE self, VALUE b) {
  return DBL2NUM(glm_vec4_distance(VAL2VEC4(self), VAL2VEC4(b)));
}

#div_scalar(b[, dest]) ⇒ dest | new Vec4

Divides each component in self by the scalar b and places the result into dest. If dest is omitted, a new Vec4 is used instead. Returns dest.

Returns:



282
283
284
285
286
287
288
# File 'ext/cglm/rb_cglm_vec4.c', line 282

VALUE rb_cglm_vec4_div_scalar(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_divs(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(dest));
  return dest;
}

#div_scalar!(b) ⇒ self

Divides each component in self by the scalar b. Modifies self in-place and returns self.

Returns:

  • (self)


295
296
297
298
# File 'ext/cglm/rb_cglm_vec4.c', line 295

VALUE rb_cglm_vec4_div_scalar_self(VALUE self, VALUE b) {
  glm_vec4_divs(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(self));
  return self;
}

#div_vec4(b[, dest]) ⇒ dest | new Vec4

Divides two vectors (component-wise division). Places the result in dest and returns dest. If dest is omitted, a new Vec4 is used instead.

Returns:



258
259
260
261
262
263
264
# File 'ext/cglm/rb_cglm_vec4.c', line 258

VALUE rb_cglm_vec4_div_vec4(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_div(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(dest));
  return dest;
}

#div_vec4!(b) ⇒ self

Divides two vectors (component-wise division). Modifies self in-place and returns self.

Returns:

  • (self)


271
272
273
274
# File 'ext/cglm/rb_cglm_vec4.c', line 271

VALUE rb_cglm_vec4_div_vec4_self(VALUE self, VALUE b) {
  glm_vec4_div(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(self));
  return self;
}

#dot(other) ⇒ Object



71
72
73
# File 'ext/cglm/rb_cglm_vec4.c', line 71

VALUE rb_cglm_vec4_dot(VALUE self, VALUE other) {
  return DBL2NUM(glm_vec4_dot(VAL2VEC4(self), VAL2VEC4(other)));
}

#equalish_scalar(val[, epsilon]) ⇒ Object

Returns true if the given scalar value is very close to each component of this Vec4, false otherwise. Useful for dealing with the loss of precision during floating point arithmetic.



504
505
506
507
508
509
510
511
512
513
514
# File 'ext/cglm/rb_cglm_vec4.c', line 504

VALUE rb_cglm_vec4_equalish_scalar(int argc, VALUE *argv, VALUE self) {
  VALUE val, eps;
  float epsil = FLT_EPSILON;
  rb_scan_args(argc, argv, "11", &val, &eps);
  if (!NIL_P(eps)) epsil = NUM2FLT(eps);
  float s = NUM2FLT(val);
  vec3 *v = &VAL2VEC3(self);
  return fabsf((*v)[0] - s) <= eps &&
         fabsf((*v)[1] - s) <= eps &&
         fabsf((*v)[2] - s) <= eps ? Qtrue : Qfalse;
}

#equalish_vec4(other[, epsilon]) ⇒ Object

Returns true if this vector is very close to equal to the given one. Useful for dealing with the loss of precision during floating point arithmetic.



537
538
539
540
541
542
543
544
545
546
547
548
# File 'ext/cglm/rb_cglm_vec4.c', line 537

VALUE rb_cglm_vec4_equalish_vec4(int argc, VALUE *argv, VALUE self) {
  VALUE val, eps;
  float epsil = FLT_EPSILON;
  rb_scan_args(argc, argv, "11", &val, &eps);
  if (!NIL_P(eps)) epsil = NUM2FLT(eps);
  vec4 *s = &VAL2VEC4(val);
  vec4 *v = &VAL2VEC4(self);
  return fabsf((*v)[0] - (*s)[0]) <= eps &&
         fabsf((*v)[1] - (*s)[1]) <= eps &&
         fabsf((*v)[2] - (*s)[2]) <= eps &&
         fabsf((*v)[3] - (*s)[3]) <= eps ? Qtrue : Qfalse;
}

#equals_allObject

Returns true if each component in this Vec4 has the same exact value.



520
521
522
# File 'ext/cglm/rb_cglm_vec4.c', line 520

VALUE rb_cglm_vec4_equals_all(VALUE self) {
  return glm_vec4_eq_all(VAL2VEC4(self)) ? Qtrue : Qfalse;
}

#equals_scalar(val) ⇒ Object

Returns true if the given scalar value exactly equals each component of this Vec4, false otherwise.



494
495
496
# File 'ext/cglm/rb_cglm_vec4.c', line 494

VALUE rb_cglm_vec4_equals_scalar(VALUE self, VALUE val) {
  return glm_vec4_eq(VAL2VEC4(self), NUM2FLT(val)) ? Qtrue : Qfalse;
}

#equals_vec4(other) ⇒ Object

Returns true if this vector exactly matches the given one.



528
529
530
# File 'ext/cglm/rb_cglm_vec4.c', line 528

VALUE rb_cglm_vec4_equals_vec4(VALUE self, VALUE other) {
  return glm_vec4_eqv(VAL2VEC4(self), VAL2VEC4(other)) ? Qtrue : Qfalse;
}

#flip_signs([dest]) ⇒ dest | new Vec4 Also known as: invert, negate

Flips the sign of each component and places the result into dest. Returns dest. If dest is omitted, a new Vec4 is allocated.

Returns:



355
356
357
358
359
360
361
# File 'ext/cglm/rb_cglm_vec4.c', line 355

VALUE rb_cglm_vec4_flip_signs(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_flipsign_to(VAL2VEC4(self), VAL2VEC4(dest));
  return dest;
}

#flip_signs!self Also known as: invert!, negate!

Flips the sign of each component, modifying self in-place. Returns self.

Returns:

  • (self)


367
368
369
370
# File 'ext/cglm/rb_cglm_vec4.c', line 367

VALUE rb_cglm_vec4_flip_signs_self(VALUE self) {
  glm_vec4_flipsign(VAL2VEC4(self));
  return self;
}

#highestNumeric

Returns the value of the highest component in this Vec4.

Returns:



554
555
556
# File 'ext/cglm/rb_cglm_vec4.c', line 554

VALUE rb_cglm_vec4_highest(VALUE self) {
  return DBL2NUM(glm_vec4_max(VAL2VEC4(self)));
}

#inf?Boolean

Returns true if any component in this vector is inf, false otherwise. You should only use this in DEBUG mode or very critical asserts.

Returns:

  • (Boolean)


580
581
582
# File 'ext/cglm/rb_cglm_vec4.c', line 580

VALUE rb_cglm_vec4_is_inf(VALUE self) {
  return glm_vec4_isinf(VAL2VEC4(self)) ? Qtrue : Qfalse;
}

#inspectObject



7
8
9
# File 'lib/cglm/vec4.rb', line 7

def inspect
  "#<#{self.class}@#{addr.to_i.to_s(16)} #{to_a.inspect}>"
end

#lerp!(from, to, amount) ⇒ self

Performs linear interpolation between from and to, both of which should be Vec4's, by the specified amount which should be a number. Modifies self in-place and returns self.

Returns:

  • (self)


474
475
476
477
# File 'ext/cglm/rb_cglm_vec4.c', line 474

VALUE rb_cglm_vec4_lerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
  glm_vec4_lerp(VAL2VEC4(from), VAL2VEC4(to), NUM2FLT(amount), VAL2VEC4(self));
  return self;
}

#lowestNumeric

Returns the value of the lowest component in this Vec4.

Returns:



562
563
564
# File 'ext/cglm/rb_cglm_vec4.c', line 562

VALUE rb_cglm_vec4_lowest(VALUE self) {
  return DBL2NUM(glm_vec4_min(VAL2VEC4(self)));
}

#luminanceNumeric

Averages the RGB color channels into one value and then multiplies the result by the alpha channel.

Returns:



16
17
18
# File 'ext/cglm/rb_cglm_color.c', line 16

VALUE rb_cglm_color_luminance4(VALUE self) {
  return DBL2NUM(glm_luminance(VAL2VEC3(self)) * VAL2VEC4(self)[3]);
}

#max(vec[, dest]) ⇒ dest | new Vec4

Finds the higher of each component (x, y, z) between self and vec. Places the result into dest and returns dest. Creates and returns a new Vec4 if dest is omitted.

Returns:



386
387
388
389
390
391
392
# File 'ext/cglm/rb_cglm_vec4.c', line 386

VALUE rb_cglm_vec4_max(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_maxv(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(dest));
  return dest;
}

#min(vec[, dest]) ⇒ dest | new Vec4

Finds the lower of each component (x, y, z) between self and vec. Places the result into dest and returns dest. Creates and returns a new Vec4 if dest is omitted.

Returns:



400
401
402
403
404
405
406
# File 'ext/cglm/rb_cglm_vec4.c', line 400

VALUE rb_cglm_vec4_min(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_minv(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(dest));
  return dest;
}

#mul_scalar(b[, dest]) ⇒ dest | new Vec4

Multiplies each component in self with the scalar b and places the result into dest. If dest is omitted, a new Vec4 is used instead. Returns dest.

Returns:



212
213
214
215
216
217
218
# File 'ext/cglm/rb_cglm_vec4.c', line 212

VALUE rb_cglm_vec4_mul_scalar(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_scale(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(dest));
  return dest;
}

#mul_scalar!(b) ⇒ self

Multiplies each component in self with the scalar b. Modifies self in-place and returns self.

Returns:

  • (self)


225
226
227
228
# File 'ext/cglm/rb_cglm_vec4.c', line 225

VALUE rb_cglm_vec4_mul_scalar_self(VALUE self, VALUE b) {
  glm_vec4_scale(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(self));
  return self;
}

#mul_vec4(b[, dest]) ⇒ dest | new Vec4

Multiplies two vectors (component-wise multiplication). Places the result in dest and returns dest. If dest is omitted, a new Vec4 is used instead.

Returns:



188
189
190
191
192
193
194
# File 'ext/cglm/rb_cglm_vec4.c', line 188

VALUE rb_cglm_vec4_mul_vec4(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_mul(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(dest));
  return dest;
}

#mul_vec4!(b) ⇒ self

Multiplies two vectors (component-wise multiplication). Modifies self in-place and returns self.

Returns:

  • (self)


201
202
203
204
# File 'ext/cglm/rb_cglm_vec4.c', line 201

VALUE rb_cglm_vec4_mul_vec4_self(VALUE self, VALUE b) {
  glm_vec4_mul(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(self));
  return self;
}

#muladd(other, dest) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/cglm/vec4.rb', line 80

def muladd(other, dest)
  case other
  when VectorType then muladd_vec4(other, dest)
  when Numeric    then muladd_scalar(other, dest)
  else false
  end
end

#muladd_scalar(other, dest) ⇒ Object

Multiplies self with other and adds that result to dest. Equivalent to dest += (self * other). Returns dest.

  • other is a Numeric, not a vector type.

  • dest is not optional for this method, as it is for most others.



345
346
347
348
# File 'ext/cglm/rb_cglm_vec4.c', line 345

VALUE rb_cglm_vec4_muladd_scalar(VALUE self, VALUE other, VALUE dest) {
  glm_vec4_muladds(VAL2VEC4(self), NUM2FLT(other), VAL2VEC4(dest));
  return dest;
}

#muladd_vec4(other, dest) ⇒ Object

Multiplies self with other and adds that result to dest. Equivalent to dest += (self * other). Returns dest.

  • dest is not optional for this method, as it is for most others.


331
332
333
334
# File 'ext/cglm/rb_cglm_vec4.c', line 331

VALUE rb_cglm_vec4_muladd_vec4(VALUE self, VALUE other, VALUE dest) {
  glm_vec4_muladd(VAL2VEC4(self), VAL2VEC4(other), VAL2VEC4(dest));
  return dest;
}

#nan?Boolean

Returns true if any component in this vector is nan, false otherwise. You should only use this in DEBUG mode or very critical asserts.

Returns:

  • (Boolean)


571
572
573
# File 'ext/cglm/rb_cglm_vec4.c', line 571

VALUE rb_cglm_vec4_is_nan(VALUE self) {
  return glm_vec4_isnan(VAL2VEC4(self)) ? Qtrue : Qfalse;
}

#normNumeric Also known as: magnitude, mag

Returns the norm (magnitude) of this vector.

Returns:



88
89
90
# File 'ext/cglm/rb_cglm_vec4.c', line 88

VALUE rb_cglm_vec4_norm(VALUE self) {
  return DBL2NUM(glm_vec4_norm(VAL2VEC4(self)));
}

#norm2Numeric

Returns the norm (magnitude) of this vector, squared. Call this rather than norm ** 2 to avoid an unnecessary square root.

Returns:



80
81
82
# File 'ext/cglm/rb_cglm_vec4.c', line 80

VALUE rb_cglm_vec4_norm2(VALUE self) {
  return DBL2NUM(glm_vec4_norm2(VAL2VEC4(self)));
}

#normalize([dest]) ⇒ dest | new Vec4

Returns:



639
640
641
642
643
644
645
# File 'ext/cglm/rb_cglm_vec4.c', line 639

VALUE rb_cglm_vec4_normalize(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_normalize_to(VAL2VEC4(self), VAL2VEC4(dest));
  return dest;
}

#normalize!self

Returns:

  • (self)


649
650
651
652
# File 'ext/cglm/rb_cglm_vec4.c', line 649

VALUE rb_cglm_vec4_normalize_self(VALUE self) {
  glm_vec4_normalize(VAL2VEC4(self));
  return self;
}

#one!self

Sets all fields in self to 1 and returns self.

Returns:

  • (self)


66
67
68
69
# File 'ext/cglm/rb_cglm_vec4.c', line 66

VALUE rb_cglm_vec4_one_self(VALUE self) {
  glm_vec4_one(VAL2VEC4(self));
  return self;
}

#resize(b[, dest]) ⇒ dest | new Vec4

Same as normalize(self) * b. Places the result in dest and creates a new Vec4 if dest is omitted.

Returns:



235
236
237
238
239
240
241
# File 'ext/cglm/rb_cglm_vec4.c', line 235

VALUE rb_cglm_vec4_resize(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_scale_as(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(dest));
  return dest;
}

#resize!(b) ⇒ self

Same as normalize(self) * b. Modifies self in-place and returns self.

Returns:

  • (self)


247
248
249
250
# File 'ext/cglm/rb_cglm_vec4.c', line 247

VALUE rb_cglm_vec4_resize_self(VALUE self, VALUE b) {
  glm_vec4_scale_as(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(self));
  return self;
}

#signs([dest]) ⇒ dest | new Vec4

Places +1, 0 or -1 into each component of dest based on whether the corresponding component of this Vec4 is positive, 0/NaN, or negative. If dest is omitted, a new Vec4 is created and returned.

Returns:



599
600
601
602
603
604
605
# File 'ext/cglm/rb_cglm_vec4.c', line 599

VALUE rb_cglm_vec4_signs(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_sign(VAL2VEC4(self), VAL2VEC4(dest));
  return dest;
}

#sizeObject



3
4
5
# File 'lib/cglm/vec4.rb', line 3

def size
  4
end

#sqrt([dest]) ⇒ dest | new Vec4

For each component of this Vec4, places the square root of that component into dest. If dest is omitted, a new Vec4 is created. Returns dest.

Returns:



612
613
614
615
616
617
618
# File 'ext/cglm/rb_cglm_vec4.c', line 612

VALUE rb_cglm_vec4_sqrt(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_sqrt(VAL2VEC4(self), VAL2VEC4(dest));
  return dest;
}

#sub_scalar(b[, dest]) ⇒ dest | new Vec4

Subtracts the Numeric b from each component of self, placing the result in dest. If dest is omitted, a new Vec4 is created and returned.

Returns:



136
137
138
139
140
141
142
# File 'ext/cglm/rb_cglm_vec4.c', line 136

VALUE rb_cglm_vec4_sub_scalar(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_subs(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(dest));
  return dest;
}

#sub_scalar!(b) ⇒ self

Subtracts the Numeric b from each component of self, modifying self in-place and returning it.

Returns:

  • (self)


177
178
179
180
# File 'ext/cglm/rb_cglm_vec4.c', line 177

VALUE rb_cglm_vec4_sub_scalar_self(VALUE self, VALUE b) {
  glm_vec4_subs(VAL2VEC4(self), NUM2FLT(b), VAL2VEC4(self));
  return self;
}

#sub_vec4(b[, dest]) ⇒ dest | new Vec4

Subtracts b from self, placing the result in dest. If dest is omitted, a new Vec4 is created and returned.

Returns:



123
124
125
126
127
128
129
# File 'ext/cglm/rb_cglm_vec4.c', line 123

VALUE rb_cglm_vec4_sub_vec4(int argc, VALUE *argv, VALUE self) {
  VALUE b, dest;
  rb_scan_args(argc, argv, "11", &b, &dest);
  if (NIL_P(dest)) dest = VEC4_NEW(ALLOC_VEC4);
  glm_vec4_sub(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(dest));
  return dest;
}

#sub_vec4!(b) ⇒ self

Subtracts b from self, modifying self in-place and returning it.

Returns:

  • (self)


167
168
169
170
# File 'ext/cglm/rb_cglm_vec4.c', line 167

VALUE rb_cglm_vec4_sub_vec4_self(VALUE self, VALUE b) {
  glm_vec4_sub(VAL2VEC4(self), VAL2VEC4(b), VAL2VEC4(self));
  return self;
}

#subadd(other, dest) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/cglm/vec4.rb', line 72

def subadd(other, dest)
  case other
  when VectorType then subadd_vec4(other, dest)
  when Numeric    then subadd_scalar(other, dest)
  else false
  end
end

#subadd_vec4(other, dest) ⇒ Object

Subtracts other from self and adds that result to dest. Equivalent to dest += (self - other). Returns dest.

  • dest is not optional for this method, as it is for most others.


319
320
321
322
# File 'ext/cglm/rb_cglm_vec4.c', line 319

VALUE rb_cglm_vec4_subadd_vec4(VALUE self, VALUE other, VALUE dest) {
  glm_vec4_subadd(VAL2VEC4(self), VAL2VEC4(other), VAL2VEC4(dest));
  return dest;
}

#to_vec3([dest]) ⇒ dest | new Vec3

Returns:



19
20
21
22
23
24
25
# File 'ext/cglm/rb_cglm_vec4.c', line 19

VALUE rb_cglm_vec4_to_vec3(int argc, VALUE *argv, VALUE self) {
  VALUE dest;
  rb_scan_args(argc, argv, "01", &dest);
  if (NIL_P(dest)) dest = VEC3_NEW(ALLOC_VEC3);
  glm_vec3(VAL2VEC4(self), VAL2VEC3(dest));
  return dest;
}

#valid?Boolean

Returns true if no component in this vector is NaN or infinite, false otherwise. You should only use this in DEBUG mode or very critical asserts.

Returns:

  • (Boolean)


589
590
591
# File 'ext/cglm/rb_cglm_vec4.c', line 589

VALUE rb_cglm_vec4_is_valid(VALUE self) {
  return glm_vec4_isvalid(VAL2VEC4(self)) ? Qtrue : Qfalse;
}

#zero!self

Sets all fields in self to 0 and returns self.

Returns:

  • (self)


57
58
59
60
# File 'ext/cglm/rb_cglm_vec4.c', line 57

VALUE rb_cglm_vec4_zero_self(VALUE self) {
  glm_vec4_zero(VAL2VEC4(self));
  return self;
}