Back to index

supertuxkart  0.5+dfsg1
Functions
isect.cpp File Reference
#include <plib/ssg.h>
#include "isect.hpp"

Go to the source code of this file.

Functions

float getHeightAndNormal (ssgBranch *branch, sgVec3 my_position, sgVec3 normal)

Function Documentation

float getHeightAndNormal ( ssgBranch *  branch,
sgVec3  my_position,
sgVec3  normal 
)

Definition at line 23 of file isect.cpp.

{
    /* Look for the nearest polygon *beneath* my_position */

    ssgHit *results ;

    float hot ;        /* H.O.T == Height Of Terrain */
    sgVec3 HOTvec ;

    sgMat4 invmat ;
    sgMakeIdentMat4 ( invmat ) ;
    invmat[3][0] = - my_position [0] ;
    invmat[3][1] = - my_position [1] ;
    invmat[3][2] = 0.0 ;

    sgSetVec3 ( HOTvec, 0.0f, 0.0f, my_position [ 2 ] ) ;

    const int NUM_HITS = ssgHOT (branch, HOTvec, invmat, &results ) ;

    hot = - FLT_MAX ;

    for ( int i = 0 ; i < NUM_HITS ; i++ )
    {
        ssgHit *h = &results [ i ] ;

        float hgt = - h->plane[3] / h->plane[2] ;

        if ( hgt >= hot )
        {
            hot = hgt ;

            if ( normal != NULL )
                sgCopyVec3 ( normal, h->plane ) ;
        }
    }

    return hot ;
}

Here is the caller graph for this function: