[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36753] trunk/blender/source/blender/ editors: window_to_3d() wasn't working at all (only used by grease pencil/ path conversion), now works in ortho and perspective view, initgrabz() is no longer needs to be called first.

Campbell Barton ideasman42 at gmail.com
Wed May 18 20:01:01 CEST 2011


Revision: 36753
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36753
Author:   campbellbarton
Date:     2011-05-18 18:01:01 +0000 (Wed, 18 May 2011)
Log Message:
-----------
window_to_3d() wasn't working at all (only used by grease pencil/path conversion), now works in ortho and perspective view, initgrabz() is no longer needs to be called first.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_edit.c	2011-05-18 17:52:26 UTC (rev 36752)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_edit.c	2011-05-18 18:01:01 UTC (rev 36753)
@@ -377,7 +377,6 @@
 	}
 	else {
 		float *fp= give_cursor(scene, v3d);
-		float dvec[3];
 		int mval[2];
 		int mx, my;
 		
@@ -396,9 +395,7 @@
 		/* convert screen coordinate to 3d coordinates 
 		 *	- method taken from editview.c - mouse_cursor() 
 		 */
-		project_int_noclip(ar, fp, mval);
-		window_to_3d(ar, dvec, mval[0]-mx, mval[1]-my);
-		sub_v3_v3v3(p3d, fp, dvec);
+		window_to_3d(ar, p3d, fp, mval[0], mval[1]);
 	}
 }
 
@@ -564,8 +561,6 @@
 	bGPdata *gpd= gpencil_data_get_active(C);
 	bGPDlayer *gpl= gpencil_layer_getactive(gpd);
 	Scene *scene= CTX_data_scene(C);
-	View3D *v3d= CTX_wm_view3d(C);
-	float *fp= give_cursor(scene, v3d);
 	int mode= RNA_enum_get(op->ptr, "type");
 
 	/* check if there's data to work with */
@@ -574,9 +569,6 @@
 		return OPERATOR_CANCELLED;
 	}
 
-	/* initialise 3d-cursor correction globals */
-	initgrabz(CTX_wm_region_view3d(C), fp[0], fp[1], fp[2]);
-
 	/* handle conversion modes */
 	switch (mode) {
 		case GP_STROKECONVERT_PATH:

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2011-05-18 17:52:26 UTC (rev 36752)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2011-05-18 18:01:01 UTC (rev 36753)
@@ -80,7 +80,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 out[3], const int mx, const int my);
+void window_to_3d(struct ARegion *ar, float out[3], const float depth_pt[3], const int mx, const int my);
 void window_to_3d_delta(struct ARegion *ar, float out[3], const int mx, const int my);
 void window_to_3d_vector(struct ARegion *ar, float out[3], const int mx, const int my);
 void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2011-05-18 17:52:26 UTC (rev 36752)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2011-05-18 18:01:01 UTC (rev 36753)
@@ -598,21 +598,37 @@
 	return flip;
 }
 
-/* always call initgrabz */
-void window_to_3d(ARegion *ar, float out[3], const int mx, const int my)
+void window_to_3d(ARegion *ar, float out[3], const float depth_pt[3], const int mx, const int my)
 {
 	RegionView3D *rv3d= ar->regiondata;
 	
-	float dx= ((float)(mx-(ar->winx/2)))*rv3d->zfac/(ar->winx/2);
-	float dy= ((float)(my-(ar->winy/2)))*rv3d->zfac/(ar->winy/2);
-	
-	float fz= rv3d->persmat[0][3]*out[0]+ rv3d->persmat[1][3]*out[1]+ rv3d->persmat[2][3]*out[2]+ rv3d->persmat[3][3];
-	fz= fz/rv3d->zfac;
-	
-	out[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0];
-	out[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1];
-	out[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2];
-	
+	float line_sta[3];
+	float line_end[3];
+
+	if(rv3d->is_persp) {
+		float mousevec[3];
+		float view_z[3];
+		float pt_mid[3];
+
+		window_to_3d_vector(ar, mousevec, mx, my);
+
+		copy_v3_v3(line_sta, rv3d->viewinv[3]);
+		normalize_v3_v3(view_z, rv3d->viewinv[2]);
+		add_v3_v3v3(line_end, line_sta, view_z);
+		closest_to_line_v3(pt_mid, depth_pt, line_sta, line_end);
+		mul_v3_fl(mousevec, shell_angle_to_dist(angle_normalized_v3v3(view_z, mousevec)) * len_v3v3(line_sta, pt_mid));
+		add_v3_v3v3(out, line_sta, mousevec);
+	}
+	else {
+        const float dx= (2.0f * (float)mx / (float)ar->winx) - 1.0f;
+        const float dy= (2.0f * (float)my / (float)ar->winy) - 1.0f;
+		line_sta[0]= (rv3d->persinv[0][0] * dx) + (rv3d->persinv[1][0] * dy) + rv3d->viewinv[3][0];
+		line_sta[1]= (rv3d->persinv[0][1] * dx) + (rv3d->persinv[1][1] * dy) + rv3d->viewinv[3][1];
+		line_sta[2]= (rv3d->persinv[0][2] * dx) + (rv3d->persinv[1][2] * dy) + rv3d->viewinv[3][2];
+
+		add_v3_v3v3(line_end, line_sta, rv3d->viewinv[2]);
+		closest_to_line_v3(out, depth_pt, line_sta, line_end);
+	}
 }
 
 /* always call initgrabz */




More information about the Bf-blender-cvs mailing list