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/editors/space_view3d | |
parent | 162d02bf5014bd881a1268aca156009108159ff4 (diff) |
utility function for getting the vector direction the mouse is pointing in a perspective view.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 22 |
1 files changed, 22 insertions, 0 deletions
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; |