[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36823] trunk/blender/source/blender/ editors: fix view3d_persp_mat4, which gave incorrect translation, rename to ED_view3d_to_m4.

Campbell Barton ideasman42 at gmail.com
Mon May 23 04:23:03 CEST 2011


Revision: 36823
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36823
Author:   campbellbarton
Date:     2011-05-23 02:23:03 +0000 (Mon, 23 May 2011)
Log Message:
-----------
fix view3d_persp_mat4, which gave incorrect translation, rename to ED_view3d_to_m4. added doxygen docs.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_fly.c
    trunk/blender/source/blender/editors/space_view3d/view3d_intern.h

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2011-05-22 17:10:24 UTC (rev 36822)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2011-05-23 02:23:03 UTC (rev 36823)
@@ -147,6 +147,43 @@
  */
 void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
 
+/**
+ * Calculate the view transformation matrix from RegionView3D input.
+ * The resulting matrix is equivilent to RegionView3D.viewinv
+ * @param mat The view 4x4 transformation matrix to calculate.
+ * @param ofs The view offset, normally from RegionView3D.ofs.
+ * @param quat The view rotation, quaternion normally from RegionView3D.viewquat.
+ * @param dist The view distance from ofs, normally from RegionView3D.dist.
+ */
+void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist);
+
+/**
+ * Set the view transformation from a 4x4 matrix.
+ * @param mat The view 4x4 transformation matrix to assign.
+ * @param ofs The view offset, normally from RegionView3D.ofs.
+ * @param quat The view rotation, quaternion normally from RegionView3D.viewquat.
+ * @param dist The view distance from ofs, normally from RegionView3D.dist.
+ */
+void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
+
+/**
+ * Set the RegionView3D members from an objects transformation and optionally lens.
+ * @param ob The object to set the view to.
+ * @param ofs The view offset to be set, normally from RegionView3D.ofs.
+ * @param quat The view rotation to be set, quaternion normally from RegionView3D.viewquat.
+ * @param dist The view distance from ofs to be set, normally from RegionView3D.dist.
+ */
+void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
+
+/**
+ * Set the object transformation from RegionView3D members.
+ * @param ob The object which has the transformation assigned.
+ * @param ofs The view offset, normally from RegionView3D.ofs.
+ * @param quat The view rotation, quaternion normally from RegionView3D.viewquat.
+ * @param dist The view distance from ofs, normally from RegionView3D.dist.
+ */
+void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
+
 #if 0 /* UNUSED */
 void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
 #endif
@@ -246,13 +283,6 @@
 unsigned int ED_view3d_datamask(struct Scene *scene, struct View3D *v3d);
 unsigned int ED_viewedit_datamask(struct bScreen *screen);
 
-
-/* assigning view matrix */
-void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
-
-void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
-void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
-
 /* camera lock functions */
 /* copy the camera to the view before starting a view transformation */
 void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-05-22 17:10:24 UTC (rev 36822)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-05-23 02:23:03 UTC (rev 36823)
@@ -3523,26 +3523,7 @@
 }
 #endif // if 0, unused NDof code
 
-/* give a 4x4 matrix from a perspective view, only needs viewquat, ofs and dist
- * basically the same as...
- *     rv3d->persp= RV3D_PERSP
- *     setviewmatrixview3d(scene, v3d, rv3d);
- *     setcameratoview3d(v3d, rv3d, v3d->camera);
- * ...but less of a hassle
- * */
-void view3d_persp_mat4(RegionView3D *rv3d, float mat[][4])
-{
-	float qt[4], dvec[3];
-	copy_qt_qt(qt, rv3d->viewquat);
-	qt[0]= -qt[0];
-	quat_to_mat4(mat, qt);
-	mat[3][2] -= rv3d->dist;
-	translate_m4(mat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]);
-	mul_v3_v3fl(dvec, mat[2], -rv3d->dist);
-	sub_v3_v3v3(mat[3], dvec, rv3d->ofs);
-}
 
-
 /* Gets the view trasnformation from a camera
 * currently dosnt take camzoom into account
 *
@@ -3577,7 +3558,17 @@
 	}
 }
 
+void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist)
+{
+	float iviewquat[4]= {-quat[0], quat[1], quat[2], quat[3]};
+	float dvec[3]= {0.0f, 0.0f, dist};
 
+	quat_to_mat4(mat, iviewquat);
+	mul_mat3_m4_v3(mat, dvec);
+	sub_v3_v3v3(mat[3], dvec, ofs);
+}
+
+
 /* object -> view */
 void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens)
 {
@@ -3591,12 +3582,7 @@
 /* view -> object */
 void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], const float dist)
 {
-	float mat4[4][4];
-	float dvec[3]= {0.0f, 0.0f, dist};
-	float iviewquat[4]= {-quat[0], quat[1], quat[2], quat[3]};
-
-	quat_to_mat4(mat4, iviewquat);
-	mul_mat3_m4_v3(mat4, dvec);
-	sub_v3_v3v3(mat4[3], dvec, ofs);
-	object_apply_mat4(ob, mat4, TRUE, TRUE);
+	float mat[4][4];
+	ED_view3d_to_m4(mat, ofs, quat, dist);
+	object_apply_mat4(ob, mat, TRUE, TRUE);
 }

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_fly.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_fly.c	2011-05-22 17:10:24 UTC (rev 36822)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_fly.c	2011-05-23 02:23:03 UTC (rev 36823)
@@ -568,7 +568,7 @@
 	apply_rotation= 1; /* if the user presses shift they can look about without movinf the direction there looking*/
 
 	if(fly->root_parent)
-		view3d_persp_mat4(rv3d, prev_view_mat);
+		ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist);
 
 	/* the dist defines a vector that is infront of the offset
 	to rotate the view about.
@@ -797,7 +797,7 @@
 					float parent_mat[4][4];
 
 					invert_m4_m4(prev_view_imat, prev_view_mat);
-					view3d_persp_mat4(rv3d, view_mat);
+					ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
 					mul_m4_m4m4(diff_mat, prev_view_imat, view_mat);
 					mul_m4_m4m4(parent_mat, fly->root_parent->obmat, diff_mat);
 					object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE);
@@ -817,7 +817,7 @@
 				}
 				else {
 					float view_mat[4][4];
-					view3d_persp_mat4(rv3d, view_mat);
+					ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
 					object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE);
 					id_key= &v3d->camera->id;
 				}

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_intern.h	2011-05-22 17:10:24 UTC (rev 36822)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_intern.h	2011-05-23 02:23:03 UTC (rev 36823)
@@ -91,7 +91,6 @@
 void VIEW3D_OT_drawtype(struct wmOperatorType *ot);
 
 void view3d_boxview_copy(ScrArea *sa, ARegion *ar);
-void view3d_persp_mat4(struct RegionView3D *rv3d, float mat[][4]);
 
 /* view3d_fly.c */
 void view3d_keymap(struct wmKeyConfig *keyconf);




More information about the Bf-blender-cvs mailing list