forked from bartvdbraak/blender
utility function for getting the vector direction the mouse is pointing in a perspective view.
This commit is contained in:
parent
162d02bf50
commit
db6ea4d3a5
@ -82,6 +82,7 @@ float *give_cursor(struct Scene *scene, struct View3D *v3d);
|
|||||||
int initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
|
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(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_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);
|
void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
|
||||||
|
|
||||||
/* Depth buffer */
|
/* Depth buffer */
|
||||||
|
@ -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);
|
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)
|
float read_cached_depth(ViewContext *vc, int x, int y)
|
||||||
{
|
{
|
||||||
ViewDepths *vd = vc->rv3d->depths;
|
ViewDepths *vd = vc->rv3d->depths;
|
||||||
|
Loading…
Reference in New Issue
Block a user