Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!agate!ucbvax!ORION.CERFACS.FR!farestam From: farestam@ORION.CERFACS.FR (Stefan Farestam) Newsgroups: comp.sys.sgi Subject: Re: question: lookat() command and twist Message-ID: <9101170614.AA25522@ultima.cerfacs.fr> Date: 17 Jan 91 06:14:08 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 57 In article <1991Jan16.181821.20724@athena.mit.edu>, Matthew A Machlis writes > I am developing a 3-D realtime simulation on a Personal IRIS which has > head-tracking capability to display what the user is actually looking at. > I am using the lookat() command to actually do the transformation involved > in head-tracking. I have run into an unfortunate aspect of the lookat > command: everything is fine when I am looking straight ahead (along the > positive z-axis) with zero twist. But as the "look vector" is rotated > downward (towards the negative y axis), still with zero twist, the > direction which is "up" in terms of what is displayed on the screen > rotates 180 degrees as the head rotates through straight down. > How can I compensate for this twisting of the up direction with lookat? I'm not sure I understand your problem, but the following might prove useful for you: Suppose that : * view_point is the point you are looking from * ref_point is the point you are looking towards * up_vec is a vector that represents the direction up (i.e. if you would plot up_vec after lookat was applied it would be a vertical vector pointing upwards on the screen) * v = view_point - ref_point * w = (up_vec) x (v) where 'x' signifies the vector product * v and w are normalized then the twist angle used in lookat can be calculated by: swy = (int) copysign(1.0, wy) ; twist = swy * acos((wx*vz - wz*vx) / sqrt(vx*vx + vz*vz) / sqrt(wx*wx + wy*wy + wz*wz)) ; and the call to lookat would look like: lookat(view_point->x, view_point->y, view_point->z, ref_point->x, ref_point->y, ref_point->z, twist * 180/PI * 10) ; /Stefan Farestam -- ................................................................. . Stefan Farestam . . __ __ __ _ _ _ . . / |_ )|_ /_\/ ( European Centre for Research and . . \_ |__\| / \__) Advanced Training in Scientific Computation . .................................................................