[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21280] branches/soc-2009-yukishiro/source /blender: improve rotation.

Jingyuan Huang jingyuan.huang at gmail.com
Wed Jul 1 06:38:54 CEST 2009


Revision: 21280
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21280
Author:   yukishiro
Date:     2009-07-01 06:38:53 +0200 (Wed, 01 Jul 2009)

Log Message:
-----------
improve rotation. QuatToEul doesn't give me the right euler...

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Modified: branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-07-01 01:17:58 UTC (rev 21279)
+++ branches/soc-2009-yukishiro/source/blender/editors/sculpt_paint/paint_light.c	2009-07-01 04:38:53 UTC (rev 21280)
@@ -583,28 +583,20 @@
 	switch(event->type) {
 		case MOUSEMOVE: // use trackball
 		{
-			float phi, si, q1[4], dvec[3], newvec[3];
+			float phi, si, rvec[4], dvec[3], newvec[3];
 			calctrackballvec(&rop->ar->winrct, event->x, event->y, newvec);
 
 			VecSubf(dvec, newvec, rop->trackvec);
-
 			si= sqrt(dvec[0]*dvec[0]+ dvec[1]*dvec[1]+ dvec[2]*dvec[2]);
 			si/= (2.0*TRACKBALLSIZE);
 			
-			Crossf(q1+1, rop->trackvec, newvec);
-			Normalize(q1+1);
+			Crossf(rvec+1, rop->trackvec, newvec);
+			Normalize(rvec+1);
 			
 			while (si > 1.0) si -= 2.0;
-			phi = si * M_PI / 2.0;
+			rvec[0] = si * M_PI;
 
-			si= sin(phi);
-			q1[0]= cos(phi);
-			q1[1]*= si;
-			q1[2]*= si;
-			q1[3]*= si;
-
-			SH_rotateLightEnv(env, q1);
-
+			SH_rotateLightEnv(env, rvec);
 			calctrackballvec(&rop->ar->winrct, event->x, event->y, rop->trackvec);
 
 			WM_event_add_notifier(C, NC_LIGHTENV|ND_SH_RESULT, NULL);

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-07-01 01:17:58 UTC (rev 21279)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-07-01 04:38:53 UTC (rev 21280)
@@ -758,15 +758,58 @@
         }
 }
 
-void SH_rotateLightEnv(LightEnv *env, float *quat)
+static void rotvec_to_matrix(float rvec[4], float mat[][3])
 {
+	// rotation vec to matrix
+	float theta = rvec[0];
+	float x = rvec[1];
+	float y = rvec[2];
+	float z = rvec[3];
+	float c = cos(theta);
+	float s = sin(theta);
+
+	mat[0][0] = c + (1-c) * x * x;
+	mat[0][1] = (1-c) * x * y + z * s;
+	mat[0][2] = (1-c) * x * z - y * s;
+	mat[1][0] = (1-c) * y * x - z * s;
+	mat[1][1] = c + (1-c) * y * y;
+	mat[1][2] = (1-c) * y * z + x * s;
+	mat[2][0] = (1-c) * z * x + y * s;
+	mat[2][1] = (1-c) * z * y - x * s;
+	mat[2][2] = c + (1-c) * z * z;
+
+}
+
+static void matrix_to_eul(float mat[][3], float eul[3])
+{
+	if (mat[2][2] > 0.9999) {
+		eul[0] = atan2(mat[0][1], mat[1][1]);
+		eul[1] = eul[2] = 0.0;
+	} 
+	else if (mat[2][2] < -0.9999) {
+		eul[0] = atan2(mat[0][1], mat[1][1]);
+		eul[1] = M_PI;
+		eul[2] = 0.0;
+	}
+	else {
+		eul[0] = atan2(mat[2][1], mat[2][0]);
+		eul[1] = acos(mat[2][2]);
+		eul[2] = atan2(mat[1][2], -mat[0][2]);
+	}
+}
+
+void SH_rotateLightEnv(LightEnv *env, float *rvec)
+{
 	int deg, l, m, n;
 	float eul[3];
+	float mat[3][3];
 	float new_coeffs[25][3];
 	ShWigner wigner;
 
-	QuatToEul(quat, eul);
-
+	// rotation vec to euler
+	rotvec_to_matrix(rvec, mat);
+	matrix_to_eul(mat, eul);
+	
 	// create wigner
 	deg = env->degree;
 	wigner = allocate_ShWigner(deg);





More information about the Bf-blender-cvs mailing list