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
15 16 17 18 19 20 21 |
# File 'ext/cglm/rb_cglm_quat.c', line 15
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).
242 243 244 245 246 247 248 |
# File 'ext/cglm/rb_cglm_quat.c', line 242
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).
264 265 266 267 268 269 270 |
# File 'ext/cglm/rb_cglm_quat.c', line 264
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.
317 318 319 320 321 322 323 324 325 326 |
# File 'ext/cglm/rb_cglm_quat.c', line 317
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.
317 318 319 320 321 322 323 324 325 326 |
# File 'ext/cglm/rb_cglm_quat.c', line 317
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.
112 113 114 |
# File 'ext/cglm/rb_cglm_quat.c', line 112 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
.
120 121 122 123 124 125 126 |
# File 'ext/cglm/rb_cglm_quat.c', line 120
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
45 46 47 48 49 50 51 |
# File 'ext/cglm/rb_cglm_quat.c', line 45
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
24 25 26 27 |
# File 'ext/cglm/rb_cglm_quat.c', line 24
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
.
80 81 82 83 84 85 86 |
# File 'ext/cglm/rb_cglm_quat.c', line 80
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.
104 105 106 |
# File 'ext/cglm/rb_cglm_quat.c', line 104 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.
92 93 94 95 96 97 98 |
# File 'ext/cglm/rb_cglm_quat.c', line 92
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
54 55 56 57 58 59 60 |
# File 'ext/cglm/rb_cglm_quat.c', line 54
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
63 64 65 66 |
# File 'ext/cglm/rb_cglm_quat.c', line 63 VALUE rb_cglm_quat_invert_self(VALUE self) { glm_quat_inv(VAL2QUAT(self), VAL2QUAT(self)); return self; } |
#lerp!(from, to, amount) ⇒ self
205 206 207 208 |
# File 'ext/cglm/rb_cglm_quat.c', line 205
VALUE rb_cglm_quat_lerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
glm_quat_lerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(amount), 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.
222 223 224 225 226 227 228 |
# File 'ext/cglm/rb_cglm_quat.c', line 222
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.
133 134 135 136 137 138 139 |
# File 'ext/cglm/rb_cglm_quat.c', line 133
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
.
145 146 147 148 149 150 |
# File 'ext/cglm/rb_cglm_quat.c', line 145
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
30 31 32 33 34 35 36 |
# File 'ext/cglm/rb_cglm_quat.c', line 30
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
39 40 41 42 |
# File 'ext/cglm/rb_cglm_quat.c', line 39 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
.
304 305 306 307 308 309 310 311 |
# File 'ext/cglm/rb_cglm_quat.c', line 304
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.
72 73 74 |
# File 'ext/cglm/rb_cglm_quat.c', line 72 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.
290 291 292 293 294 295 296 |
# File 'ext/cglm/rb_cglm_quat.c', line 290
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.
277 278 279 280 281 282 283 |
# File 'ext/cglm/rb_cglm_quat.c', line 277
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
211 212 213 214 |
# File 'ext/cglm/rb_cglm_quat.c', line 211
VALUE rb_cglm_quat_slerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
glm_quat_slerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(amount), 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.
183 184 185 186 187 188 189 |
# File 'ext/cglm/rb_cglm_quat.c', line 183
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.
157 158 159 160 161 162 163 |
# File 'ext/cglm/rb_cglm_quat.c', line 157
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.
196 197 198 199 200 201 202 |
# File 'ext/cglm/rb_cglm_quat.c', line 196
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.
170 171 172 173 174 175 176 |
# File 'ext/cglm/rb_cglm_quat.c', line 170
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;
}
|