Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-05-20 14:28:40 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-05-20 14:28:40 +0400
commit4916c44af8a2c916c8f2e1d82ace4af9a2e797a6 (patch)
tree5981efe3534bfad4899d5699da4216bf7cc0311b /source/blender/editors/space_view3d
parent2999d0fad9f2a7ec88315610bf998f63b6b97322 (diff)
simplify window_to_3d_vector() and call it from viewline()
also update python view function to match.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c52
2 files changed, 18 insertions, 36 deletions
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] + (