Method: CGLM::Mat4.random
- Defined in:
- ext/cglm/rb_cglm_mat4.c
.random([dest]) ⇒ dest | new Mat4
Fills dest or a new Mat4 with a random translation and rotation, and
returns it.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'ext/cglm/rb_cglm_mat4.c', line 255
VALUE rb_cglm_mat4_new_random(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_mat4_copy(GLM_MAT4_IDENTITY, VAL2MAT4(dest));
/* random position */
VAL2MAT4(dest)[3][0] = drand48();
VAL2MAT4(dest)[3][1] = drand48();
VAL2MAT4(dest)[3][2] = drand48();
/* random rotatation around random axis with random angle */
glm_rotate(VAL2MAT4(dest), drand48(), (vec3){drand48(), drand48(), drand48()});
/* random scale */
/* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */
return dest;
}
|