1 
2 #include "tuxkart.h"
3 
4 
getHeightAndNormal(sgVec3 my_position,sgVec3 normal)5 float getHeightAndNormal ( sgVec3 my_position, sgVec3 normal )
6 {
7   /* Look for the nearest polygon *beneath* my_position */
8 
9   ssgHit *results ;
10   int num_hits ;
11 
12   float hot ;        /* H.O.T == Height Of Terrain */
13   sgVec3 HOTvec ;
14 
15   sgMat4 invmat ;
16   sgMakeIdentMat4 ( invmat ) ;
17   invmat[3][0] = - my_position [0] ;
18   invmat[3][1] = - my_position [1] ;
19   invmat[3][2] = 0.0 ;
20 
21   sgSetVec3 ( HOTvec, 0.0f, 0.0f, my_position [ 2 ] ) ;
22 
23   num_hits = ssgHOT ( scene, HOTvec, invmat, &results ) ;
24 
25   hot = DEEPEST_HELL ;
26 
27   for ( int i = 0 ; i < num_hits ; i++ )
28   {
29     ssgHit *h = &results [ i ] ;
30 
31     float hgt = - h->plane[3] / h->plane[2] ;
32 
33     if ( hgt >= hot )
34     {
35       hot = hgt ;
36 
37       if ( normal != NULL )
38         sgCopyVec3 ( normal, h->plane ) ;
39     }
40   }
41 
42   return hot ;
43 }
44 
45 
46