paul barham (barham++at++gnarly.cs.nps.navy.mil)
Wed, 11 May 1994 12:40:21 -0700 (PDT)
Here is a subroutine from our NPSNET-IV virtual world simulator which will
perform the operation you need (in C++):
void compute_hpr ( pfVec3 &from_pos, pfVec3 &to_pos, pfVec3 &hpr_result )
{
float bearing_angle;
float pitch_angle;
float ordered_heading;
float target_dist;
target_dist = pfDistancePt3 ( to_pos, from_pos );
bearing_angle = atan2f( (from_pos[Y] - to_pos[Y]),
(from_pos[X] - to_pos[X]) );
pitch_angle = RAD_TO_DEG * asinf( (to_pos[Z] - from_pos[Z])/target_dist );
ordered_heading = RAD_TO_DEG * (HALFPI + bearing_angle);
while ( ordered_heading < 0.0f )
ordered_heading += 360.0f;
while ( ordered_heading >= 360.0f )
ordered_heading -= 360.0f;
pfSetVec3 ( hpr_result, ordered_heading, pitch_angle, 0.0f );
}
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Paul T. Barham Computer Specialist Computer Graphics Research + + + + Naval Postgraduate School barham++at++cs.nps.navy.mil + + Computer Science Department, Code CS Spanagel Hall Room 311A + + Monterey, Calfornia 93943 (408)656-2253 (2814 fax)+ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:16 PDT