home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 09 Racing and Sports AI / 01 Biasillo / Listing1.cpp
Encoding:
Text File  |  2001-12-09  |  813 b   |  22 lines

  1. /* Copyright (C) Gari Biasillo, 2001. 
  2.  * All rights reserved worldwide.
  3.  *
  4.  * This software is provided "as is" without express or implied
  5.  * warranties. You may freely copy and compile this source into
  6.  * applications you distribute provided that the copyright text
  7.  * below is included in the resulting source code, for example:
  8.  * "Portions Copyright (C) Gari Biasillo, 2001"
  9.  */
  10.  
  11. // A simple approach that works extremely well in practice is 
  12. // to compute the traveled distance parallel to the driving line 
  13. // as shown in the following code snippet.
  14.  
  15. float DistAlongSector(const CSector& sector, const vector3& pos)
  16. {
  17.     vector3 delta = pos - sector.drivingLinePos;
  18.     delta.y = 0.0f;
  19.     float dist = DotProduct(sector.drivingLineForward, delta);
  20.     return (dist * lengthScale);
  21. }
  22.