Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Public Attributes
InfoTriangle Class Reference

#include <static_ssg.hpp>

List of all members.

Public Member Functions

 InfoTriangle ()
 InfoTriangle (ssgLeaf *l, int i, sgVec3 v1, sgVec3 v2, sgVec3 v3)
 ~InfoTriangle ()
float hot (sgVec3 p)
int collision (sgSphere *s)

Public Attributes

ssgLeaf * m_leaf
int m_indx
sgVec3 m_vv1
sgVec3 m_vv2
sgVec3 m_vv3
unsigned int m_test_nr
sgVec4 m_plane
float m_x_min
float m_x_max
float m_y_min
float m_y_max
float m_dist

Detailed Description

Definition at line 28 of file static_ssg.hpp.


Constructor & Destructor Documentation

Definition at line 40 of file static_ssg.hpp.

{};
InfoTriangle::InfoTriangle ( ssgLeaf *  l,
int  i,
sgVec3  v1,
sgVec3  v2,
sgVec3  v3 
) [inline]

Definition at line 41 of file static_ssg.hpp.

    {
        m_leaf = l; m_indx=i;
        sgCopyVec3(m_vv1,v1);
        sgCopyVec3(m_vv2,v2);
        sgCopyVec3(m_vv3,v3);
        m_test_nr=0;
        l->ref();
    }

Definition at line 50 of file static_ssg.hpp.

{ ssgDeRefDelete(m_leaf); }

Member Function Documentation

int InfoTriangle::collision ( sgSphere *  s)

Definition at line 320 of file static_ssg.cpp.

{

    const sgVec3 * const CENTER = (sgVec3*)s->getCenter();
    const float R = s->getRadius();

    /* First test: see if the sphere is outside the 2d bounding box
       of the triangle - a quite fast and easy test                 */
    if((*CENTER)[0]+R<m_x_min || (*CENTER)[0]-R>m_x_max ||
       (*CENTER)[1]+R<m_y_min || (*CENTER)[1]-R>m_y_max)
    {
        return 0;
    }

    m_dist = (float)fabs( sgDistToPlaneVec3(m_plane, s->getCenter()) );

    if ( m_dist > R ) return 0;

    /*
      The BSphere touches the plane containing
      the triangle - but does it actually touch
      the triangle itself?  Let's erect some
      vertical walls around the triangle.
    */

    /*
      Construct a 'wall' as a plane through
      two vertices and a third vertex made
      by adding the surface normal to the
      first of those two vertices.
    */

    sgVec3 vvX;
    sgVec4 planeX;

    sgAddVec3 ( vvX, m_plane, m_vv1 );
    sgMakePlane ( planeX, m_vv1, m_vv2, vvX );
    const float DP1 = sgDistToPlaneVec3 ( planeX, s->getCenter() );

    if ( DP1 > s->getRadius() ) return 0;

    sgAddVec3 ( vvX, m_plane, m_vv2 );
    sgMakePlane ( planeX, m_vv2, m_vv3, vvX );
    const float DP2 = sgDistToPlaneVec3 ( planeX, s->getCenter() );

    if ( DP2 > s->getRadius() ) return 0;

    sgAddVec3 ( vvX, m_plane, m_vv3 );
    sgMakePlane ( planeX, m_vv3, m_vv1, vvX );
    const float DP3 = sgDistToPlaneVec3 ( planeX, s->getCenter() );

    if ( DP3 > s->getRadius() ) return 0;

    /*
      OK, so we now know that the sphere
      intersects the plane of the triangle
      and is not more than one radius outside
      the walls. However, you can still get
      close enough to the wall and to the
      triangle itself and *still* not
      intersect the triangle itself.

      However, if the center is inside the
      triangle then we don't need that
      costly test.
    */

    if ( DP1 <= 0 && DP2 <= 0 && DP3 <= 0 ) return 1;

    /*
      <sigh> ...now we really need that costly set of tests...

      If the sphere penetrates the plane of the triangle
      and the plane of the wall, then we can use pythagoras
      to determine if the sphere actually intersects that
      edge between the wall and the triangle.

      if ( dp_sqd + dp1_sqd > radius_sqd ) ...in! else ...out!
    */

    const float R2 = s->getRadius() * s->getRadius() - m_dist * m_dist ;

    if ( DP1 * DP1 <= R2 || DP2 * DP2 <= R2 || DP3 * DP3 <= R2 )
    {
        return 1;
    }
    return 0;
}   // InfoTriangle::collision

Here is the caller graph for this function:

float InfoTriangle::hot ( sgVec3  p)

Definition at line 270 of file static_ssg.cpp.

{
    /*
      Does the X/Y coordinate lie outside the triangle's bbox, or
      does the Z coordinate lie beneath the bbox ?
    */
    if ( ( s[0] < m_vv1[0] && s[0] < m_vv2[0] && s[0] < m_vv3[0] ) ||
         ( s[1] < m_vv1[1] && s[1] < m_vv2[1] && s[1] < m_vv3[1] ) ||
         ( s[0] > m_vv1[0] && s[0] > m_vv2[0] && s[0] > m_vv3[0] ) ||
         ( s[1] > m_vv1[1] && s[1] > m_vv2[1] && s[1] > m_vv3[1] ) ||
         ( s[2] < m_vv1[2] && s[2] < m_vv2[2] && s[2] < m_vv3[2] ) ) return NOINTERSECT;


    /* No HOT from upside-down or vertical triangles */
    if ( m_leaf->getCullFace() && m_plane [ 2 ] <= 0 ) return NOINTERSECT;

    /* Find the point vertically below the text point
       as it crosses the plane of the polygon */
    const float Z = sgHeightOfPlaneVec2 ( m_plane, s );

    /* No HOT from below the triangle */
    if ( Z > s[2] ) return NOINTERSECT;

    /* Outside the vertical extent of the triangle? */
    if ( ( Z < m_vv1[2] && Z < m_vv2[2] && Z < m_vv3[2] ) ||
         ( Z > m_vv1[2] && Z > m_vv2[2] && Z > m_vv3[2] ) ) return NOINTERSECT;

    /*
      Now it gets messy - the isect point is inside
      the bbox of the triangle - but that's not enough.
      Is it inside the triangle itself?
    */
    const float  E1 =  s [0] * m_vv1[1] -  s [1] * m_vv1[0] ;
    const float  E2 =  s [0] * m_vv2[1] -  s [1] * m_vv2[0] ;
    const float  E3 =  s [0] * m_vv3[1] -  s [1] * m_vv3[0] ;
    const float EP1 = m_vv1[0] * m_vv2[1] - m_vv1[1] * m_vv2[0] ;
    const float EP2 = m_vv2[0] * m_vv3[1] - m_vv2[1] * m_vv3[0] ;
    const float EP3 = m_vv3[0] * m_vv1[1] - m_vv3[1] * m_vv1[0] ;

    const float AP = (float) fabs ( EP1 + EP2 + EP3 ) ;
    const float AI = (float) ( fabs ( E1 + EP1 - E2 ) +
                         fabs ( E2 + EP2 - E3 ) +
                         fabs ( E3 + EP3 - E1 ) ) ;

    if ( AI > AP * 1.01 ) return NOINTERSECT;

    return Z;
}   // InfoTriangle::hot

Here is the caller graph for this function:


Member Data Documentation

Definition at line 38 of file static_ssg.hpp.

Definition at line 32 of file static_ssg.hpp.

Definition at line 31 of file static_ssg.hpp.

Definition at line 35 of file static_ssg.hpp.

Definition at line 34 of file static_ssg.hpp.

Definition at line 33 of file static_ssg.hpp.

Definition at line 33 of file static_ssg.hpp.

Definition at line 33 of file static_ssg.hpp.

Definition at line 36 of file static_ssg.hpp.

Definition at line 36 of file static_ssg.hpp.

Definition at line 36 of file static_ssg.hpp.

Definition at line 36 of file static_ssg.hpp.


The documentation for this class was generated from the following files: