Re: [Plib-devel] Bug with sign of pitch?
Brought to you by:
sjbaker
From: Curtis L. O. <cu...@me...> - 2000-07-18 14:36:35
|
Last I looked I didn't see anything like this, but what I would really like is some code that would take a directional vector and an up vector and translate this into an ssg XYZ - HPR coord structure. What I'd like to use this for is given I know my camera position, and the position of something I want centered on the screen, I want to look directly at it (with control over the up direction.) For example, a chase plane view in a flight sim. It's probably a simple thing to impliment, but I just haven't had a chance to sit down and think it through ... and if someone has already done the work I'd happily use that. :-) Regards, Curt. Wolfram Kuss writes: > BTW, I game developers might use this code as well. > I use it for camera-movement (when I do a "make object fully > visible"). > Its quite simple, but perhaps you want to put it into plib? > > Here is the function: > > --------------------- cut ------------------------------ > void /*sg*/Vec3fromHPR ( sgVec3 vec3, const sgVec3 hpr ) > // If hpr are the hpr of the camera, then this function gives the > normalised > // viewing direction. Of course roll is lost in this conversion. > { > double ch, sh, cp, sp; > > if ( hpr[0] == SG_ZERO ) > { > ch = SGD_ONE ; > sh = SGD_ZERO ; > } > else > { > sh = (SGfloat) sin( (double)( hpr[0] * SG_DEGREES_TO_RADIANS )) ; > ch = (SGfloat) cos( (double)( hpr[0] * SG_DEGREES_TO_RADIANS )) ; > } > > if ( hpr[1] == SG_ZERO ) > { > cp = SGD_ONE ; > sp = SGD_ZERO ; > } > else > { > sp = sin( (double)( hpr[1] * SG_DEGREES_TO_RADIANS )) ; > cp = cos( (double)( hpr[1] * SG_DEGREES_TO_RADIANS )) ; > } > vec3[0] = (SGfloat)( -sh * cp ) ; > vec3[1] = (SGfloat)( ch * cp ) ; > vec3[2] = (SGfloat)( sp ) ; > // rest is check > sgVec3 hprCheck; > sgHPRfromVec3 ( hprCheck, vec3) ; > if(0.01<abs(hprCheck[0]-hpr[0])) > fprintf(stderr,"\n*** Heading: %f vs %f***\n",hprCheck[0],hpr[0]); > if(0.01<abs(hprCheck[1]-hpr[1])) > fprintf(stderr,"\n*** Pitch: %f vs %f ***\n",hprCheck[1],hpr[1]); > > > } > --------------------- cut ------------------------------ > > Bye bye, > Wolfram Kuss. > > > _______________________________________________ > plib-devel mailing list > pli...@li... > http://lists.sourceforge.net/mailman/listinfo/plib-devel -- Curtis Olson Human Factors Research Lab Flight Gear Project Twin Cities cu...@hf... cu...@fl... Minnesota http://www.menet.umn.edu/~curt http://www.flightgear.org |