[Bf-committers] Bug #816 (180 deg rotation limit for trackball in 3D window) with Possible Patch

Nathanael Law bf-committers@blender.org
Sat, 27 Dec 2003 06:07:30 -0700


Here is a summary of the relevant code changes for ease of reading.
In this part of the code, 'si' denotes the relative distance
that the users has dragged the mouse since pressing down the middle
mouse button and 'phi' is the angle of rotation.

Relevant Old Code
=================

/* is there an acceptable solution? (180 degrees limitor) */
if (si < 1.0) {
	/* Calculate axis of rotation */

	phi = asin(si);

	/* Generate rotation quaternion from phi and apply it to view */
}

Relevant New Code
=================

/* Calculate axis of rotation */

while (si > 1.0)
	si -= 2.0;

phi = si * M_PI / 2.0;

/* Generate rotation quaternion from phi and apply it to view */

Complete Old Code
=================

/* is there an acceptable solution? (180 degrees limitor) */
if(si<1.0) {
	Crossf(q1+1, firstvec, newvec);

	Normalise(q1+1);

	phi= asin(si);

	si= sin(phi);
	q1[0]= cos(phi);
	q1[1]*= si;
	q1[2]*= si;
	q1[3]*= si;

	QuatMul(G.vd->viewquat, q1, oldquat);

	if( (U.flag & TRACKBALL)==0 ) {

		/* rotate around z-axis (mouse x moves)  */

		phi= 2*(mval[0]-mvalball[0]);
		phi/= (float)curarea->winx;
		si= sin(phi);
		q1[0]= cos(phi);
		q1[1]= q1[2]= 0.0;
		q1[3]= si;

		QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
	}
}

Complete New Code
=================

Crossf(q1+1, firstvec, newvec);

Normalise(q1+1);
 
/* Allow for rotation beyond the interval
 * [-pi, pi] */
while (si > 1.0)
	si -= 2.0;

/* This relation is used instead of
 * phi = asin(si) so that the angle
 * of rotation is linearly proportional
 * to the distance that the mouse is
 * dragged. */
phi = si * M_PI / 2.0;

si= sin(phi);
q1[0]= cos(phi);
q1[1]*= si;
q1[2]*= si;
q1[3]*= si;

QuatMul(G.vd->viewquat, q1, oldquat);

if( (U.flag & TRACKBALL)==0 ) {

	/* rotate around z-axis (mouse x moves)  */

	phi= 2*(mval[0]-mvalball[0]);
	phi/= (float)curarea->winx;
	si= sin(phi);
	q1[0]= cos(phi);
	q1[1]= q1[2]= 0.0;
	q1[3]= si;

	QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
}

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

I'm wondering, did my webserver give a error for the images?  Anyhow, I
hope this is easier to read.  If there's anything else I can do, please
let me know.

--
 - Nathanael Law <njlaw@xyrodian.com>