Re: Tracking camera...

New Message Reply Date view Thread view Subject view Author view

paul barham (barham++at++gnarly.cs.nps.navy.mil)
Wed, 11 May 1994 12:40:21 -0700 (PDT)


>
> Forgive me if this is really basic, but I want to implement a "tracking"
> camera. That is, a camera which always looks at a particular model. This
> model will be driven by data, so its position cannot be known before hand.
>
> The way I've been going about it is: take the position of the model and
> subtract the position of the camera. This gives a vector from the camera
> to the model. The problem now is getting this vector into a hpr form so
> that I can use the pfChanView function to set the viewing direction.
>
> Am I going about this wrong? I've looked in the myriad of Performer
> function calls to see if there is a conversion from vector to hpr, but
> can't find any. Is there a "Performer way" that does all this
> automatically?
>
> Thanks in advance!
>
> jan.
>
>
> Jan Anthony Barglowski Phone: (619) 927-1057
> Computer Dude Internet: jan++at++archimedes.nwc.navy.mil
> Visualization Lab Packet: SYSOP++at++WA6YBN.#SOCA.CA.US.NA
> Naval Air Warfare Center kc6uth++at++kc6uth.ampr.org
> -Weapons Division [44.17.2.6]
>
>

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)+ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:16 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.