question: lookat() command and twist
Stefan Farestam
farestam at ORION.CERFACS.FR
Thu Jan 17 17:14:08 AEST 1991
In article <1991Jan16.181821.20724 at athena.mit.edu>, Matthew A Machlis
<bloom-beacon.mit.edu!bloom-picayune.mit.edu!news> 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 <farestam at cerfacs.fr> .
. __ __ __ _ _ _ .
. / |_ )|_ /_\/ ( European Centre for Research and .
. \_ |__\| / \__) Advanced Training in Scientific Computation .
.................................................................
More information about the Comp.sys.sgi
mailing list