Class: CGLM::Quat
- Inherits:
-
Vec4
- Object
- Base
- VectorType
- Vec4
- CGLM::Quat
- Defined in:
- lib/cglm/quat.rb,
ext/cglm/rb_cglm.c
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
- .axis_angle(axis, angle[, dest]) ⇒ dest | new Quat
- .identity([dest]) ⇒ dest | new Quat
-
.look(dir, fwd, up[, dest]) ⇒ dest | new Quat
Creates a rotation quaternion that has the specified orientation.
-
.look_at(position, target, fwd, up[, dest]) ⇒ dest | new Quat
Creates a rotation quaternion that has the specified orientation.
-
.random([dest]) ⇒ dest | new Quat
Fills
dest
or a new Quat with a random orientation, and returns it. -
.random([dest]) ⇒ dest | new Quat
Fills
dest
or a new Quat with a random orientation, and returns it.
Instance Method Summary collapse
- #*(other) ⇒ Object
-
#angle ⇒ Numeric
Returns the angle of the quaternion.
-
#axis([dest]) ⇒ dest | new Vec3
Returns the axis of the quaternion in
dest
. - #conjugate([dest]) ⇒ dest | new Quat
- #copy_to(dest) ⇒ Object
-
#imag([dest]) ⇒ dest | new Vec3
Returns the imaginary part of the quaternion in
dest
. -
#imaglen ⇒ Numeric
Returns the length of the imaginary part of the quaternion.
-
#imagn([dest]) ⇒ dest | new Vec3
Returns the imaginary part of the quaternion in
dest
, normalized. - #invert([dest]) ⇒ dest | new Quat
- #invert! ⇒ self
- #lerp!(from, to, amount) ⇒ self
-
#look(position[, dest]) ⇒ dest | new Mat4
Creates a view matrix, stored in
dest
, using this quaternion as the camera orientation. -
#mul_quat(other[, dest]) ⇒ dest | new Quat
Multiplies
self
byother
and stores the result indest
. -
#mul_quat!(other) ⇒ self
Multiplies
self
byother
. - #normalize([dest]) ⇒ Object
- #normalize! ⇒ self
-
#pivot_mat4(mat, pivot_point[, dest]) ⇒ dest | new Mat4
Rotates the given transform matrix using this quaternion at the pivot point (a Vec3).
-
#real ⇒ Numeric
Returns the real part of the quaternion.
-
#rotate_mat4(vec[, dest]) ⇒ dest | new Mat4
Rotates the given Mat4 by this quaternion.
-
#rotate_vec3(vec[, dest]) ⇒ dest | new Vec3
Rotates the given Vec3 by this quaternion.
- #slerp!(from, to, amount) ⇒ self
-
#to_mat3([dest]) ⇒ dest | new Mat3
Converts this quaternion into a Mat3.
-
#to_mat4([dest]) ⇒ dest | new Mat4
Converts this quaternion into a Mat4.
-
#to_transposed_mat3([dest]) ⇒ dest | new Mat3
Converts this quaternion into a transposed Mat3.
-
#to_transposed_mat4([dest]) ⇒ dest | new Mat4
Converts this quaternion into a transposed Mat4.
Methods inherited from Vec4
#+, #-, #/, #==, #=~, #[], #[]=, #add_scalar, #add_scalar!, #add_vec4, #add_vec4!, #addadd, #addadd_vec4, alignment, black, #broadcast!, #clamp, #clamp!, #clamp_scalar, #clamp_scalar!, #clamp_vec4, #clamp_vec4!, #distance, #div_scalar, #div_scalar!, #div_vec4, #div_vec4!, #dot, #equalish_scalar, #equalish_vec4, #equals_all, #equals_scalar, #equals_vec4, #flip_signs, #flip_signs!, #highest, #inf?, #inspect, #lowest, #luminance, #max, #min, #mul_scalar, #mul_scalar!, #mul_vec4, #mul_vec4!, #muladd, #muladd_scalar, #muladd_vec4, #nan?, #norm, #norm2, one, #one!, #resize, #resize!, #signs, size, #size, #sqrt, #sub_scalar, #sub_scalar!, #sub_vec4, #sub_vec4!, #subadd, #subadd_vec4, #to_vec3, #valid?, zero, #zero!
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
.axis_angle(axis, angle[, dest]) ⇒ dest | new Quat
13 14 15 16 17 18 19 |
# File 'ext/cglm/rb_cglm_quat.c', line 13
VALUE rb_cglm_quat_new_axis_angle(int argc, VALUE *argv, VALUE self) {
VALUE axis, angle, dest;
rb_scan_args(argc, argv, "21", &axis, &angle, &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quatv(VAL2QUAT(dest), NUM2FLT(angle), VAL2VEC3(axis));
return dest;
}
|
.identity([dest]) ⇒ dest | new Quat
4 5 6 7 8 9 10 |
# File 'ext/cglm/rb_cglm_quat.c', line 4
VALUE rb_cglm_quat_new_identity(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_identity(VAL2QUAT(dest));
return dest;
}
|
.look(dir, fwd, up[, dest]) ⇒ dest | new Quat
Creates a rotation quaternion that has the specified orientation. Places
the result in dest
, or creates a new Quat if dest
was omitted. Returns
dest
.
dir
is the direction to look (a Vec3).fwd
is the forward vector (a Vec3).up
is the up vector (a Vec3).
240 241 242 243 244 245 246 |
# File 'ext/cglm/rb_cglm_quat.c', line 240
VALUE rb_cglm_quat_new_look(int argc, VALUE *argv, VALUE self) {
VALUE dir, fwd, up, dest;
rb_scan_args(argc, argv, "31", &dir, &fwd, &up, &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_for(VAL2VEC3(dir), VAL2VEC3(fwd), VAL2VEC3(up), VAL2QUAT(dest));
return dest;
}
|
.look_at(position, target, fwd, up[, dest]) ⇒ dest | new Quat
Creates a rotation quaternion that has the specified orientation. Places
the result in dest
, or creates a new Quat if dest
was omitted. Returns
dest
.
position
is the current position to look from (a Vec3).target
is the position to look toward (a Vec3).fwd
is the forward vector (a Vec3).up
is the up vector (a Vec3).
262 263 264 265 266 267 268 |
# File 'ext/cglm/rb_cglm_quat.c', line 262
VALUE rb_cglm_quat_new_look_at(int argc, VALUE *argv, VALUE self) {
VALUE position, target, fwd, up, dest;
rb_scan_args(argc, argv, "41", &position, &target, &fwd, &up, &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_forp(VAL2VEC3(position), VAL2VEC3(target), VAL2VEC3(fwd), VAL2VEC3(up), VAL2QUAT(dest));
return dest;
}
|
.random([dest]) ⇒ dest | new Quat
Fills dest
or a new Quat with a random orientation, and returns it.
315 316 317 318 319 320 321 322 323 324 |
# File 'ext/cglm/rb_cglm_quat.c', line 315
VALUE rb_cglm_quat_new_random(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat(VAL2QUAT(dest), drand48(), drand48(), drand48(), drand48());
glm_quat_normalize(VAL2QUAT(dest));
return dest;
}
|
.random([dest]) ⇒ dest | new Quat
Fills dest
or a new Quat with a random orientation, and returns it.
315 316 317 318 319 320 321 322 323 324 |
# File 'ext/cglm/rb_cglm_quat.c', line 315
VALUE rb_cglm_quat_new_random(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat(VAL2QUAT(dest), drand48(), drand48(), drand48(), drand48());
glm_quat_normalize(VAL2QUAT(dest));
return dest;
}
|
Instance Method Details
#*(other) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/cglm/quat.rb', line 3 def *(other) case other when Quat then mul_quat(other) else Quat.new(super) end end |
#angle ⇒ Numeric
Returns the angle of the quaternion.
110 111 112 |
# File 'ext/cglm/rb_cglm_quat.c', line 110 VALUE rb_cglm_quat_angle(VALUE self) { return DBL2NUM(glm_quat_angle(VAL2QUAT(self))); } |
#axis([dest]) ⇒ dest | new Vec3
Returns the axis of the quaternion in dest
.
118 119 120 121 122 123 124 |
# File 'ext/cglm/rb_cglm_quat.c', line 118
VALUE rb_cglm_quat_axis(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_quat_axis(VAL2QUAT(self), VAL2VEC3(dest));
return dest;
}
|
#conjugate([dest]) ⇒ dest | new Quat
43 44 45 46 47 48 49 |
# File 'ext/cglm/rb_cglm_quat.c', line 43
VALUE rb_cglm_quat_conjugate(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_conjugate(VAL2QUAT(self), VAL2QUAT(dest));
return dest;
}
|
#copy_to(dest) ⇒ Object
22 23 24 25 |
# File 'ext/cglm/rb_cglm_quat.c', line 22
VALUE rb_cglm_quat_copy_to(VALUE self, VALUE dest) {
glm_quat_copy(VAL2QUAT(self), VAL2QUAT(dest));
return dest;
}
|
#imag([dest]) ⇒ dest | new Vec3
Returns the imaginary part of the quaternion in dest
.
78 79 80 81 82 83 84 |
# File 'ext/cglm/rb_cglm_quat.c', line 78
VALUE rb_cglm_quat_imag(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_quat_imag(VAL2QUAT(self), VAL2VEC3(dest));
return dest;
}
|
#imaglen ⇒ Numeric
Returns the length of the imaginary part of the quaternion.
102 103 104 |
# File 'ext/cglm/rb_cglm_quat.c', line 102 VALUE rb_cglm_quat_imaglen(VALUE self) { return DBL2NUM(glm_quat_imaglen(VAL2QUAT(self))); } |
#imagn([dest]) ⇒ dest | new Vec3
Returns the imaginary part of the quaternion in dest
, normalized.
90 91 92 93 94 95 96 |
# File 'ext/cglm/rb_cglm_quat.c', line 90
VALUE rb_cglm_quat_imagn(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_quat_imagn(VAL2QUAT(self), VAL2VEC3(dest));
return dest;
}
|
#invert([dest]) ⇒ dest | new Quat
52 53 54 55 56 57 58 |
# File 'ext/cglm/rb_cglm_quat.c', line 52
VALUE rb_cglm_quat_invert(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_inv(VAL2QUAT(self), VAL2QUAT(dest));
return dest;
}
|
#invert! ⇒ self
61 62 63 64 |
# File 'ext/cglm/rb_cglm_quat.c', line 61 VALUE rb_cglm_quat_invert_self(VALUE self) { glm_quat_inv(VAL2QUAT(self), VAL2QUAT(self)); return self; } |
#lerp!(from, to, amount) ⇒ self
203 204 205 206 |
# File 'ext/cglm/rb_cglm_quat.c', line 203
VALUE rb_cglm_quat_lerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
glm_quat_lerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(to), VAL2QUAT(self));
return self;
}
|
#look(position[, dest]) ⇒ dest | new Mat4
Creates a view matrix, stored in dest
, using this quaternion as the
camera orientation. Returns dest
. Creates a new Mat4 if dest
is
omitted.
220 221 222 223 224 225 226 |
# File 'ext/cglm/rb_cglm_quat.c', line 220
VALUE rb_cglm_quat_look(int argc, VALUE *argv, VALUE self) {
VALUE position, dest;
rb_scan_args(argc, argv, "11", &position, &dest);
if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
glm_quat_look(VAL2VEC3(position), VAL2QUAT(self), VAL2MAT4(dest));
return dest;
}
|
#mul_quat(other[, dest]) ⇒ dest | new Quat
Multiplies self
by other
and stores the result in dest
. If dest
is omitted, a new Quat is created. dest
or the new Quat is returned.
131 132 133 134 135 136 137 |
# File 'ext/cglm/rb_cglm_quat.c', line 131
VALUE rb_cglm_quat_mul_quat(int argc, VALUE *argv, VALUE self) {
VALUE other, dest;
rb_scan_args(argc, argv, "11", &other, &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_mul(VAL2QUAT(self), VAL2QUAT(other), VAL2QUAT(dest));
return dest;
}
|
#mul_quat!(other) ⇒ self
Multiplies self
by other
. Modifies self
in-place and returns self
.
143 144 145 146 147 148 |
# File 'ext/cglm/rb_cglm_quat.c', line 143
VALUE rb_cglm_quat_mul_quat_self(VALUE self, VALUE other) {
quat dest;
glm_quat_mul(VAL2QUAT(self), VAL2QUAT(other), dest);
memcpy(&VAL2QUAT(self), &dest, sizeof(quat));
return self;
}
|
#normalize([dest]) ⇒ Object
28 29 30 31 32 33 34 |
# File 'ext/cglm/rb_cglm_quat.c', line 28
VALUE rb_cglm_quat_normalize(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = QUAT_NEW(ALLOC_QUAT);
glm_quat_normalize_to(VAL2QUAT(self), VAL2QUAT(dest));
return dest;
}
|
#normalize! ⇒ self
37 38 39 40 |
# File 'ext/cglm/rb_cglm_quat.c', line 37 VALUE rb_cglm_quat_normalize_self(VALUE self) { glm_quat_normalize(VAL2QUAT(self)); return self; } |
#pivot_mat4(mat, pivot_point[, dest]) ⇒ dest | new Mat4
Rotates the given transform matrix using this quaternion at the pivot
point (a Vec3). Places the resultant Mat4 into dest
, or creates a new
Mat4 if dest
is omitted. Returns dest
.
302 303 304 305 306 307 308 309 |
# File 'ext/cglm/rb_cglm_quat.c', line 302
VALUE rb_cglm_quat_pivot_mat4(int argc, VALUE *argv, VALUE self) {
VALUE mat, pivot, dest;
rb_scan_args(argc, argv, "21", &mat, &pivot, &dest);
if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
memcpy(&VAL2MAT4(dest), &VAL2MAT4(mat), sizeof(mat4));
glm_quat_rotate_at(VAL2MAT4(dest), VAL2QUAT(self), VAL2VEC3(pivot));
return dest;
}
|
#real ⇒ Numeric
Returns the real part of the quaternion.
70 71 72 |
# File 'ext/cglm/rb_cglm_quat.c', line 70 VALUE rb_cglm_quat_real(VALUE self) { return DBL2NUM(glm_quat_real(VAL2QUAT(self))); } |
#rotate_mat4(vec[, dest]) ⇒ dest | new Mat4
Rotates the given Mat4 by this quaternion. Returns the result in dest
,
or a new Mat4 if dest
was omitted.
288 289 290 291 292 293 294 |
# File 'ext/cglm/rb_cglm_quat.c', line 288
VALUE rb_cglm_quat_rotate_mat4(int argc, VALUE *argv, VALUE self) {
VALUE mat, dest;
rb_scan_args(argc, argv, "11", &mat, &dest);
if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
glm_quat_rotate(VAL2MAT4(mat), VAL2QUAT(self), VAL2MAT4(dest));
return dest;
}
|
#rotate_vec3(vec[, dest]) ⇒ dest | new Vec3
Rotates the given Vec3 by this quaternion. Returns the result in dest
,
or a new Vec3 if dest
was omitted.
275 276 277 278 279 280 281 |
# File 'ext/cglm/rb_cglm_quat.c', line 275
VALUE rb_cglm_quat_rotate_vec3(int argc, VALUE *argv, VALUE self) {
VALUE vec, dest;
rb_scan_args(argc, argv, "11", &vec, &dest);
if (NIL_P(dest)) dest = VEC3_NEW(ALLOC_VEC3);
glm_quat_rotatev(VAL2QUAT(self), VAL2VEC3(vec), VAL2VEC3(dest));
return dest;
}
|
#slerp!(from, to, amount) ⇒ self
209 210 211 212 |
# File 'ext/cglm/rb_cglm_quat.c', line 209
VALUE rb_cglm_quat_slerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
glm_quat_slerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(to), VAL2QUAT(self));
return self;
}
|
#to_mat3([dest]) ⇒ dest | new Mat3
Converts this quaternion into a Mat3. Places the result into dest
or
creates a new Mat3.
181 182 183 184 185 186 187 |
# File 'ext/cglm/rb_cglm_quat.c', line 181
VALUE rb_cglm_quat_to_mat3(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = MAT3_NEW(ALLOC_MAT3);
glm_quat_mat3(VAL2QUAT(self), VAL2MAT3(dest));
return dest;
}
|
#to_mat4([dest]) ⇒ dest | new Mat4
Converts this quaternion into a Mat4. Places the result into dest
or
creates a new Mat4.
155 156 157 158 159 160 161 |
# File 'ext/cglm/rb_cglm_quat.c', line 155
VALUE rb_cglm_quat_to_mat4(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
glm_quat_mat4(VAL2QUAT(self), VAL2MAT4(dest));
return dest;
}
|
#to_transposed_mat3([dest]) ⇒ dest | new Mat3
Converts this quaternion into a transposed Mat3. Places the result into
dest
or creates a new Mat3.
194 195 196 197 198 199 200 |
# File 'ext/cglm/rb_cglm_quat.c', line 194
VALUE rb_cglm_quat_to_mat3t(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = MAT3_NEW(ALLOC_MAT3);
glm_quat_mat3t(VAL2QUAT(self), VAL2MAT3(dest));
return dest;
}
|
#to_transposed_mat4([dest]) ⇒ dest | new Mat4
Converts this quaternion into a transposed Mat4. Places the result into
dest
or creates a new Mat4.
168 169 170 171 172 173 174 |
# File 'ext/cglm/rb_cglm_quat.c', line 168
VALUE rb_cglm_quat_to_mat4t(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
glm_quat_mat4t(VAL2QUAT(self), VAL2MAT4(dest));
return dest;
}
|