simplify window_to_3d_vector() and call it from viewline()
also update python view function to match.
This commit is contained in:
@@ -36,17 +36,19 @@ def region_2d_to_vector_3d(region, rv3d, coord):
|
||||
"""
|
||||
from mathutils import Vector
|
||||
|
||||
viewvec = rv3d.view_matrix.inverted()[2].xyz.normalized()
|
||||
|
||||
if rv3d.is_perspective:
|
||||
dx = (2.0 * coord[0] / region.width) - 1.0
|
||||
dy = (2.0 * coord[1] / region.height) - 1.0
|
||||
persinv = rv3d.perspective_matrix.inverted()
|
||||
|
||||
persmat = rv3d.perspective_matrix.copy()
|
||||
perspinv_x, perspinv_y = persmat.inverted().to_3x3()[0:2]
|
||||
return ((perspinv_x * dx + perspinv_y * dy) - viewvec).normalized()
|
||||
out = Vector(((2.0 * coord[0] / region.width) - 1.0,
|
||||
(2.0 * coord[1] / region.height) - 1.0,
|
||||
-0.5
|
||||
))
|
||||
|
||||
w = (out[0] * persinv[0][3]) + (out[1] * persinv[1][3]) + (out[2] * persinv[2][3]) + persinv[3][3]
|
||||
|
||||
return ((out * persinv) / w) - rv3d.view_matrix.inverted()[3].xyz
|
||||
else:
|
||||
return viewvec
|
||||
return rv3d.view_matrix.inverted()[2].xyz.normalized()
|
||||
|
||||
|
||||
def region_2d_to_location_3d(region, rv3d, coord, depth_location):
|
||||
|
||||
@@ -104,10 +104,10 @@ void project_int_noclip(struct ARegion *ar, const float vec[3], int adr[2]);
|
||||
void project_float(struct ARegion *ar, const float vec[3], float adr[2]);
|
||||
void project_float_noclip(struct ARegion *ar, const float vec[3], float adr[2]);
|
||||
|
||||
void viewvector(struct RegionView3D *rv3d, float coord[3], float vec[3]);
|
||||
void viewvector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
|
||||
|
||||
void viewline(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_start[3], float ray_end[3]);
|
||||
void viewray(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_start[3], float ray_normal[3]);
|
||||
void viewline(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3]);
|
||||
void viewray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]);
|
||||
|
||||
void get_object_clip_range(struct Object *ob, float *lens, float *clipsta, float *clipend);
|
||||
int get_view3d_cliprange(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
|
||||
@@ -198,8 +198,4 @@ void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);
|
||||
/* copy the view to the camera */
|
||||
void ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d);
|
||||
|
||||
int view3d_is_ortho(struct View3D *v3d, struct RegionView3D *rv3d);
|
||||
|
||||
|
||||
#endif /* ED_VIEW3D_H */
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
|
||||
}
|
||||
|
||||
/* for dolly */
|
||||
window_to_3d_vector(vod->ar, vod->mousevec, vod->oldx - vod->ar->winrct.xmin, vod->oldy - vod->ar->winrct.ymin);
|
||||
window_to_3d_vector(vod->ar, vod->mousevec, event->mval[0], event->mval[1]);
|
||||
|
||||
/* lookup, we dont pass on v3d to prevent confusement */
|
||||
vod->grid= vod->v3d->grid;
|
||||
|
||||
@@ -502,29 +502,20 @@ void view3d_calculate_clipping(BoundBox *bb, float planes[4][4], bglMats *mats,
|
||||
}
|
||||
|
||||
/* create intersection coordinates in view Z direction at mouse coordinates */
|
||||
void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float ray_end[3])
|
||||
void viewline(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3])
|
||||
{
|
||||
RegionView3D *rv3d= ar->regiondata;
|
||||
float vec[4];
|
||||
int a;
|
||||
|
||||
if(rv3d->is_persp) {
|
||||
vec[0]= 2.0f * mval[0] / ar->winx - 1;
|
||||
vec[1]= 2.0f * mval[1] / ar->winy - 1;
|
||||
vec[2]= -1.0f;
|
||||
vec[3]= 1.0f;
|
||||
|
||||
mul_m4_v4(rv3d->persinv, vec);
|
||||
mul_v3_fl(vec, 1.0f / vec[3]);
|
||||
|
||||
float vec[3];
|
||||
window_to_3d_vector(ar, vec, mval[0], mval[1]);
|
||||
|
||||
copy_v3_v3(ray_start, rv3d->viewinv[3]);
|
||||
sub_v3_v3(vec, ray_start);
|
||||
normalize_v3(vec);
|
||||
|
||||
VECADDFAC(ray_start, rv3d->viewinv[3], vec, v3d->near);
|
||||
VECADDFAC(ray_end, rv3d->viewinv[3], vec, v3d->far);
|
||||
}
|
||||
else {
|
||||
float vec[4];
|
||||
vec[0] = 2.0f * mval[0] / ar->winx - 1;
|
||||
vec[1] = 2.0f * mval[1] / ar->winy - 1;
|
||||
vec[2] = 0.0f;
|
||||
@@ -537,13 +528,16 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float
|
||||
}
|
||||
|
||||
/* clipping */
|
||||
if(rv3d->rflag & RV3D_CLIPPING)
|
||||
for(a=0; a<4; a++)
|
||||
if(rv3d->rflag & RV3D_CLIPPING) {
|
||||
int a;
|
||||
for(a=0; a<4; a++) {
|
||||
clip_line_plane(ray_start, ray_end, rv3d->clip[a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* create intersection ray in view Z direction at mouse coordinates */
|
||||
void viewray(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float ray_normal[3])
|
||||
void viewray(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3])
|
||||
{
|
||||
float ray_end[3];
|
||||
|
||||
@@ -552,7 +546,7 @@ void viewray(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float
|
||||
normalize_v3(ray_normal);
|
||||
}
|
||||
|
||||
void viewvector(RegionView3D *rv3d, float coord[3], float vec[3])
|
||||
void viewvector(RegionView3D *rv3d, const float coord[3], float vec[3])
|
||||
{
|
||||
if (rv3d->persp != RV3D_ORTHO)
|
||||
{
|
||||
@@ -652,18 +646,11 @@ void window_to_3d_vector(ARegion *ar, float out[3], const float mx, const float
|
||||
RegionView3D *rv3d= ar->regiondata;
|
||||
|
||||
if(rv3d->is_persp) {
|
||||
float dx, dy;
|
||||
float viewvec[3];
|
||||
|
||||
dx= (2.0f * mx / ar->winx) - 1.0f;
|
||||
dy= (2.0f * my / ar->winy) - 1.0f;
|
||||
|
||||
/* normalize here so vecs are proportional to eachother */
|
||||
normalize_v3_v3(viewvec, rv3d->viewinv[2]);
|
||||
|
||||
out[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy) - viewvec[0];
|
||||
out[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy) - viewvec[1];
|
||||
out[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy) - viewvec[2];
|
||||
out[0]= 2.0f * (mx / ar->winx) - 1.0f;
|
||||
out[1]= 2.0f * (my / ar->winy) - 1.0f;
|
||||
out[2]= -0.5f;
|
||||
mul_project_m4_v3(rv3d->persinv, out);
|
||||
sub_v3_v3(out, rv3d->viewinv[3]);
|
||||
}
|
||||
else {
|
||||
copy_v3_v3(out, rv3d->viewinv[2]);
|
||||
@@ -1887,11 +1874,6 @@ void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, f
|
||||
}
|
||||
}
|
||||
|
||||
int view3d_is_ortho(View3D *v3d, RegionView3D *rv3d)
|
||||
{
|
||||
return (rv3d->persp == RV3D_ORTHO || (v3d->camera && ((Camera *)v3d->camera->data)->type == CAM_ORTHO));
|
||||
}
|
||||
|
||||
float view3d_pixel_size(struct RegionView3D *rv3d, const float co[3])
|
||||
{
|
||||
return (rv3d->persmat[3][3] + (
|
||||
|
||||
Reference in New Issue
Block a user