diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-05-20 14:28:40 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-05-20 14:28:40 +0400 |
commit | 4916c44af8a2c916c8f2e1d82ace4af9a2e797a6 (patch) | |
tree | 5981efe3534bfad4899d5699da4216bf7cc0311b /source/blender | |
parent | 2999d0fad9f2a7ec88315610bf998f63b6b97322 (diff) |
simplify window_to_3d_vector() and call it from viewline()
also update python view function to match.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 10 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 52 |
3 files changed, 21 insertions, 43 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index a9061ce1b80..9eec5eeb7f0 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -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 */ - diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index f79a8a55045..9cb36e8e0f8 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -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; diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 41b26e4a715..8a17d0ca171 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -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] + ( |