[Bf-blender-cvs] [80470b6] master: BLI_math: axis_angle_to_quat_single

Campbell Barton noreply at git.blender.org
Thu Oct 22 18:18:47 CEST 2015


Commit: 80470b639c1c5091541c56ae80212fa8e5148913
Author: Campbell Barton
Date:   Fri Oct 23 03:08:17 2015 +1100
Branches: master
https://developer.blender.org/rB80470b639c1c5091541c56ae80212fa8e5148913

BLI_math: axis_angle_to_quat_single

Useful to avoid defining a vector for an axis-aligned rotation.
Matches axis_angle_to_mat3_single behavior.

===================================================================

M	source/blender/blenlib/BLI_math_rotation.h
M	source/blender/blenlib/intern/math_rotation.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_fly.c
M	source/blender/editors/space_view3d/view3d_walk.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h
index fbd026f..ac9295c 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -119,6 +119,8 @@ void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]);
 void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle);
 void      angle_to_mat2(float R[2][2], const float angle);
 
+void axis_angle_to_quat_single(float q[4], const char axis, const float angle);
+
 /****************************** Exponential Map ******************************/
 void quat_to_expmap(float expmap[3], const float q[4]);
 void quat_normalized_to_expmap(float expmap[3], const float q[4]);
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 575710e..949473a 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -1016,6 +1016,20 @@ void angle_to_mat2(float mat[2][2], const float angle)
 	mat[1][1] =  angle_cos;
 }
 
+void axis_angle_to_quat_single(float q[4], const char axis, const float angle)
+{
+	const float angle_half = angle * 0.5f;
+	const float angle_cos = cosf(angle_half);
+	const float angle_sin = sinf(angle_half);
+	const int axis_index = (axis - 'X');
+
+	assert(axis >= 'X' && axis <= 'Z');
+
+	q[0] = angle_cos;
+	zero_v3(q + 1);
+	q[axis_index + 1] = angle_sin;
+}
+
 /****************************** Exponential Map ******************************/
 
 void quat_normalized_to_expmap(float expmap[3], const float q[4])
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index cee0af9..aa53362 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -1097,7 +1097,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y)
 		mul_qt_qtqt(quat_local_x, vod->viewquat, quat_local_x);
 
 		/* Perform the orbital rotation */
-		axis_angle_normalized_to_quat(quat_global_z, zvec_global, sensitivity * vod->reverse * (x - vod->oldx));
+		axis_angle_to_quat_single(quat_global_z, 'Z', sensitivity * vod->reverse * (x - vod->oldx));
 		mul_qt_qtqt(vod->viewquat, quat_local_x, quat_global_z);
 
 		viewrotate_apply_dyn_ofs(vod, vod->viewquat);
@@ -1482,10 +1482,7 @@ static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, ScrArea *sa,
 		rv3d->rot_axis[1] = 0;
 		rv3d->rot_axis[2] = 1;
 
-		quat[0] = cosf(angle);
-		quat[1] = 0.0f;
-		quat[2] = 0.0f;
-		quat[3] = sinf(angle);
+		axis_angle_to_quat_single(quat, 'Z', angle * 2);
 		mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
 
 	}
@@ -3992,14 +3989,12 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
 			}
 
 			if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) {
-				const float zvec[3] = {0.0f, 0.0f, 1.0f};
-
 				if (orbitdir == V3D_VIEW_STEPRIGHT) {
 					angle = -angle;
 				}
 
 				/* z-axis */
-				axis_angle_normalized_to_quat(quat_mul, zvec, angle);
+				axis_angle_to_quat_single(quat_mul, 'Z', angle);
 			}
 			else {
 
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index e6910cf..f3ee99f 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -720,8 +720,6 @@ static int flyApply(bContext *C, FlyInfo *fly)
 	float dvec[3] = {0, 0, 0}; /* this is the direction thast added to the view offset per redraw */
 
 	/* Camera Uprighting variables */
-	float upvec[3] = {0, 0, 0}; /* stores the view's up vector */
-
 	float moffset[2]; /* mouse offset from the views center */
 	float tmp_quat[4]; /* used for rotating the view */
 
@@ -815,6 +813,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
 
 				/* rotate about the X axis- look up/down */
 				if (moffset[1]) {
+					float upvec[3];
 					copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
 					mul_m3_v3(mat, upvec);
 					/* Rotate about the relative up vec */
@@ -830,7 +829,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
 
 				/* rotate about the Y axis- look left/right */
 				if (moffset[0]) {
-
+					float upvec[3];
 					/* if we're upside down invert the moffset */
 					copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f);
 					mul_m3_v3(mat, upvec);
@@ -858,6 +857,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
 				}
 
 				if (fly->zlock == FLY_AXISLOCK_STATE_ACTIVE) {
+					float upvec[3];
 					copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
 					mul_m3_v3(mat, upvec);
 
@@ -882,6 +882,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
 
 				/* only apply xcorrect when mouse isn't applying x rot */
 				if (fly->xlock == FLY_AXISLOCK_STATE_ACTIVE && moffset[1] == 0) {
+					float upvec[3];
 					copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
 					mul_m3_v3(mat, upvec);
 					/* make sure we have some z rolling */
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index 0bda6e3..4d36d70 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -972,9 +972,6 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
 	float mat[3][3]; /* 3x3 copy of the view matrix so we can move along the view axis */
 	float dvec[3] = {0.0f, 0.0f, 0.0f}; /* this is the direction that's added to the view offset per redraw */
 
-	/* Camera Uprighting variables */
-	float upvec[3] = {0.0f, 0.0f, 0.0f}; /* stores the view's up vector */
-
 	int moffset[2]; /* mouse offset from the views center */
 	float tmp_quat[4]; /* used for rotating the view */
 
@@ -1033,6 +1030,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
 			{
 				/* rotate about the X axis- look up/down */
 				if (moffset[1]) {
+					float upvec[3];
 					float angle;
 					float y;
 
@@ -1064,6 +1062,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
 
 				/* rotate about the Y axis- look left/right */
 				if (moffset[0]) {
+					float upvec[3];
 					float x;
 
 					/* if we're upside down invert the moffset */
@@ -1082,10 +1081,8 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
 					/* user adjustement factor */
 					x *= walk->mouse_speed;
 
-					copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
-
 					/* Rotate about the relative up vec */
-					axis_angle_normalized_to_quat(tmp_quat, upvec, x);
+					axis_angle_to_quat_single(tmp_quat, 'Z', x);
 					mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
 				}
 			}




More information about the Bf-blender-cvs mailing list