Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker.mit.edu!bloom-beacon!dont-send-mail-to-path-lines From: tomt@maui.coral.COM (Tom Tulinsky) Newsgroups: comp.windows.x Subject: 3d rotation in room coords? Message-ID: <9103050342.AA20065@maui.coral.com> Date: 5 Mar 91 03:42:39 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 76 I'd like to allow the user to do 3d rotations of an object in the 'room' coordinate system; i.e. y is toward the ceiling, x is to his right, and z is out of the screen (rt-handed). I want this to be true even after he has done some rotations.... The naive way of implementing rotations accumulates them so that a 90 deg. y rotation, the x axis is now pointing out of the screen, where the room z axis is. I've tried everything I can think of, and can't get it to work. My latest version, (using the Vogle package from uunet, somewhat like SGI GL) does the y rotation, then tries to calculate where the xroom vector is, and uses an arbitrary rotation routine to rotate about it. The result: it just interchanges the order of rotations: the X axis is constant but the Y axis is rotated by xrot. (also it only works for y<0). while((but = slocator(&x, &y)) != 44) { /* get mouse x,y */ pushmatrix(); { color(BLACK); clear(); yrot = 100.0*-x; xrot = 100.0*-y; rotate(yrot, 'y'); /* do y rot */ /* calc. xroom vector = Ry((1,0,0), -yrot) */ xroom[0] = cos(-yrot*D2R); xroom[1] = 0.0; xroom[2] = -sin(-yrot*D2R); /* do x rot */ rotarb (xroom[0],xroom[1],xroom[2],xrot); callobj(obj); callobj(GNOMON); } popmatrix(); /* rotarb--do rotation about an arbitrary vector */ rotarb (a,b,c, theta) float a,b,c,theta; { float L, V, I, J; /* from Computer Graphics, Harrington, p 261. (modified) */ L = sqrt(a*a + b*b + c*c); /* lenght of vector */ V = sqrt(b*b + c*c); /* len of proj. on y-z plane */ I = R2D*asin(b/V); /* this is diff. from Harrington because I can't J = R2D*-asin(a/L); * set rot mtx directly */ rotate (I,'x'); rotate (J,'y'); rotate (theta,'z'); rotate (-J,'y'); rotate (-I,'x'); }; Coral * ** Tom Tulinsky 508 460-6010 * ** Coral Network Corporation fax 508 481-6258 * ** 734 Forest St net: tomt@coral.com *** Marlboro, MA 01752 ** U S A ********* NETWORKS