diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-04-05 06:58:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-04-05 06:58:19 +0400 |
commit | db6ea4d3a5852882cdf8bfac125ca789532b694a (patch) | |
tree | f6e433c31a2dad812993ead00cce5b6e90fef3e1 /source/blender | |
parent | 162d02bf5014bd881a1268aca156009108159ff4 (diff) |
utility function for getting the vector direction the mouse is pointing in a perspective view.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index a48e311ae97..c741c41ff5e 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -82,6 +82,7 @@ float *give_cursor(struct Scene *scene, struct View3D *v3d); int initgrabz(struct RegionView3D *rv3d, float x, float y, float z); void window_to_3d(struct ARegion *ar, float *vec, short mx, short my); void window_to_3d_delta(struct ARegion *ar, float *vec, short mx, short my); +void window_to_3d_vector(struct ARegion *ar, float *vec, short mx, short my); void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z); /* Depth buffer */ diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 8f8b46d07ad..f98b2dc934f 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -677,6 +677,28 @@ void window_to_3d_delta(ARegion *ar, float *vec, short mx, short my) vec[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy); } +/* doesn't rely on initgrabz */ +/* for perspective view, get the vector direction to + * the mouse cursor as a normalized vector */ +void window_to_3d_vector(ARegion *ar, float *vec, short mx, short my) +{ + RegionView3D *rv3d= ar->regiondata; + float dx, dy; + float viewvec[3]; + + dx= 2.0f*mx/ar->winx; + dy= 2.0f*my/ar->winy; + + /* normalize here so vecs are proportional to eachother */ + normalize_v3_v3(viewvec, rv3d->viewinv[2]); + + vec[0]= viewvec[0] - (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy); + vec[1]= viewvec[1] - (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy); + vec[2]= viewvec[2] - (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy); + + normalize_v3(vec); +} + float read_cached_depth(ViewContext *vc, int x, int y) { ViewDepths *vd = vc->rv3d->depths; |