/** * Calculate a 3d location from 2d window coordinates. * \param ar The region (used for the window width and height). * \param depth_pt The reference location used to calculate the Z depth. * \param mval The area relative location (such as event->mval converted to floats). * \param out The resulting world-space location. */ void ED_view3d_win_to_3d(ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]) { RegionView3D *rv3d = ar->regiondata; float line_sta[3]; float line_end[3]; if (rv3d->is_persp) { float mousevec[3]; copy_v3_v3(line_sta, rv3d->viewinv[3]); ED_view3d_win_to_vector(ar, mval, mousevec); add_v3_v3v3(line_end, line_sta, mousevec); if (isect_line_plane_v3(out, line_sta, line_end, depth_pt, rv3d->viewinv[2], TRUE) == 0) { /* highly unlikely to ever happen, mouse vec paralelle with view plane */ zero_v3(out); } } else { const float dx = (2.0f * mval[0] / (float)ar->winx) - 1.0f; const float dy = (2.0f * mval[1] / (float)ar->winy) - 1.0f; line_sta[0] = (rv3d->persinv[0][0] * dx) + (rv3d->persinv[1][0] * dy) + rv3d->viewinv[3][0]; line_sta[1] = (rv3d->persinv[0][1] * dx) + (rv3d->persinv[1][1] * dy) + rv3d->viewinv[3][1]; line_sta[2] = (rv3d->persinv[0][2] * dx) + (rv3d->persinv[1][2] * dy) + rv3d->viewinv[3][2]; add_v3_v3v3(line_end, line_sta, rv3d->viewinv[2]); closest_to_line_v3(out, depth_pt, line_sta, line_end); } }
static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObject *args) { VectorObject *line_a, *line_b, *plane_co, *plane_no; int no_flip = 0; float isect[3]; if (!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_plane", &vector_Type, &line_a, &vector_Type, &line_b, &vector_Type, &plane_co, &vector_Type, &plane_no, &no_flip)) { return NULL; } if (BaseMath_ReadCallback(line_a) == -1 || BaseMath_ReadCallback(line_b) == -1 || BaseMath_ReadCallback(plane_co) == -1 || BaseMath_ReadCallback(plane_no) == -1) { return NULL; } if (ELEM4(2, line_a->size, line_b->size, plane_co->size, plane_no->size)) { PyErr_SetString(PyExc_ValueError, "geometry.intersect_line_plane(...): " " can't use 2D Vectors"); return NULL; } if (isect_line_plane_v3(isect, line_a->vec, line_b->vec, plane_co->vec, plane_no->vec, no_flip) == 1) { return Vector_CreatePyObject(isect, 3, Py_NEW, NULL); } else { Py_RETURN_NONE; } }