Method: CGLM::Mat4#unproject

Defined in:
ext/cglm/rb_cglm_project.c

#unproject(pos, viewport[, dest]) ⇒ dest | new Vec3

Maps the specified position into the space represented by this matrix, places it in dest or a new Vec3 if dest is omitted, and returns it.

  • NOTE: This method must calculate the inverse of the current matrix. If you already have the inverse handy, you should use #unproject_i for better performance.

  • If self is a projection matrix, then the result will be in view space.

  • If self is a projection * view matrix, then the result will be in world space.

  • If self is an projection * view * model matrix, then the result will be in object space.

  • pos is a Vec3 specifying the coordinates to unproject.

  • viewport is a Vec4 specifying the dimensions of the viewport in [x, y, width, height] format.

  • dest is the Vec3 to place the results into, and will be created if omitted.

Returns:



66
67
68
69
70
71
72
# File 'ext/cglm/rb_cglm_project.c', line 66

VALUE rb_cglm_project_unproject(int argc, VALUE *argv, VALUE self) {
  VALUE pos, viewport, dest;
  rb_scan_args(argc, argv, "21", &pos, &viewport, &dest);
  if (NIL_P(dest)) dest = VEC3_NEW(ALLOC_VEC3);
  glm_unproject(VAL2VEC3(pos), VAL2MAT4(self), VAL2VEC4(viewport), VAL2VEC3(dest));
  return dest;
}