Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Types | Private Member Functions | Private Attributes
StaticSSG Class Reference

#include <static_ssg.hpp>

Collaboration diagram for StaticSSG:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StaticSSG (ssgEntity *start, int n)
void Draw (ssgBranch *b)
float hot (sgVec3 start, sgVec3 end, ssgLeaf **l, sgVec4 **nrm)
int collision (sgSphere *s, AllHits *allHits)

Private Types

typedef std::vector
< InfoTriangle * > 
allLeavesType
typedef std::vector
< allLeavesType
allBucketsType

Private Member Functions

void Setup (int n)
void Distribute (ssgEntity *start, sgMat4 m)
void StoreTriangle (ssgLeaf *l, int indx, sgVec3 vv1, sgVec3 vv2, sgVec3 vv3)
int GetHash (float x, float y)
int GetHash (int m1, int n1)
void GetRowCol (float x, float y, int *m1, int *n1)

Private Attributes

allLeavesType m_all_leaves
allBucketsTypem_buckets
float m_x_min
float m_x_max
float m_y_min
float m_y_max
int m_n
int m_m
unsigned int m_test_number
float m_invdx
float m_invdy
ssgEntity * m_start

Detailed Description

Definition at line 60 of file static_ssg.hpp.


Member Typedef Documentation

typedef std::vector<allLeavesType> StaticSSG::allBucketsType [private]

Definition at line 69 of file static_ssg.hpp.

typedef std::vector<InfoTriangle*> StaticSSG::allLeavesType [private]

Definition at line 65 of file static_ssg.hpp.


Constructor & Destructor Documentation

StaticSSG::StaticSSG ( ssgEntity *  start,
int  n 
)

Definition at line 31 of file static_ssg.cpp.

{
    m_start  = start_;
    m_x_min   = m_y_min =  1E10;
    m_x_max   = m_y_max = -1E10;
    m_test_number = 0;
    Setup(nSize);
}   // StaticSSG

Here is the call graph for this function:


Member Function Documentation

int StaticSSG::collision ( sgSphere *  s,
AllHits allHits 
)

Definition at line 211 of file static_ssg.cpp.

{

    sgVec3 center; sgCopyVec3(center,s->getCenter());
    float  RADIUS  = s->getRadius();

    /* m_test_number is used to tag each triangle tested during this call to
       collision. This way we make sure that each triangle is tested at 
       most once, even if it belongs to different buckets. To remove the 
       need to reset the m_test_nr value, we increase the testnumber at each test, 
       and only reset this flag if the m_test_number wraps around again to 
       zero ... which is unlikely to happen :)                              */
    m_test_number++;
    if(m_test_number==0)
    {
        /* wrap around of the test number, reset all m_test_nr values to zero,
           and set m_test_number to 1 to have a clean start                      */
        for(unsigned int i=0; i<m_all_leaves.size(); i++)
        {
            m_all_leaves[i]->m_test_nr=0;
        }
        m_test_number=1;
    }   // if m_test_number==0

    int nMin, nMax, mMin, mMax;
    GetRowCol(center[0]-RADIUS, center[1]-RADIUS, &mMin, &nMin);
    GetRowCol(center[0]+RADIUS, center[1]+RADIUS, &mMax, &nMax);
    int count=0;
    for(int j=nMin; j<=nMax; j++)
    {
        for(int i=mMin; i<=mMax; i++)
        {
            int N_HASH  = GetHash(i, j);
            if(N_HASH<0 || N_HASH>=m_n*m_m)
            {   // that should be a car off track
                continue;                   // rescue should take care of this
            }
            int nCount = (int)(*m_buckets)[N_HASH].size();
            for(int k=0; k<nCount; k++)
            {
                InfoTriangle *t = (*m_buckets)[N_HASH][k];
                // Make sure that each triangle is tested only once
                if(t->m_test_nr!=m_test_number)
                {
                    t->m_test_nr=m_test_number;
                    if(t->collision(s))
                    {
                        allHits->push_back(t);
                        count++;
                    }   // if hit
                }   // if t->m_test_nr!=m_test_number
            }   // for k
        }   // for i<=mMax
    }   // for j<=nMax

    return count;
}   // StaticSSG::collision

Here is the call graph for this function:

void StaticSSG::Distribute ( ssgEntity *  start,
sgMat4  m 
) [private]

Definition at line 101 of file static_ssg.cpp.

{
    if(p->isAKindOf(ssgTypeLeaf()))
    {
        ssgLeaf* l=(ssgLeaf*)p;
        if (material_manager->getMaterial(l)->isIgnore())return;
        for(int i=0; i<l->getNumTriangles(); i++)
        {
            short v1,v2,v3;
            sgVec3 vv1, vv2, vv3;

            l->getTriangle(i, &v1, &v2, &v3);

            sgXformPnt3 ( vv1, l->getVertex(v1), m );
            sgXformPnt3 ( vv2, l->getVertex(v2), m );
            sgXformPnt3 ( vv3, l->getVertex(v3), m );
            StoreTriangle(l, i, vv1, vv2, vv3);
        }   // for i<p->getNumTriangles
    }
    else if (p->isAKindOf(ssgTypeTransform()))
    {
        ssgBaseTransform* t=(ssgBaseTransform*)p;

        sgMat4 tmpT, tmpM;
        t->getTransform(tmpT);
        sgCopyMat4(tmpM, m);
        sgPreMultMat4(tmpM,tmpT);

        for(ssgEntity* e=t->getKid(0); e!=NULL; e=t->getNextKid())
        {
            Distribute(e, tmpM);
        }   // for i<getNumKids

    }
    else if (p->isAKindOf(ssgTypeBranch()))
    {
        ssgBranch* b =(ssgBranch*)p;
        for(ssgEntity* e=b->getKid(0); e!=NULL; e=b->getNextKid())
        {
            Distribute(e, m);
        }   // for i<getNumKids
    }
    else
    {
        printf("StaticSSG::Distribute: unkown type\n");
        p->print(stdout, 0, 0);
    }
}   // Distribute

Here is the call graph for this function:

Here is the caller graph for this function:

void StaticSSG::Draw ( ssgBranch *  b)

Definition at line 74 of file static_ssg.cpp.

{
    for(int j=0; j<m_n; j++)
    {
        for(int i=0; i<m_m; i++)
        {
            ssgVertexArray* a = new ssgVertexArray();
            sgVec3 v;
            float h=0.2f;
            v[0]=m_x_min+1/m_invdx*i;    v[1]= m_y_min+1/m_invdy*j;    v[2]=h; a->add(v);
            v[0]=m_x_min+1/m_invdx*(i+1);v[1]= m_y_min+1/m_invdy*j;    v[2]=h; a->add(v);
            v[0]=m_x_min+1/m_invdx*(i+1);v[1]= m_y_min+1/m_invdy*(j+1);v[2]=h; a->add(v);
            v[0]=m_x_min+1/m_invdx*i;    v[1]= m_y_min+1/m_invdy*(j+1);v[2]=h; a->add(v);
            ssgColourArray* c = new ssgColourArray();
            v[0]=float(j)/float(m_n);v[1]=float(i)/float(m_m);v[2]=0;
            c->add(v);c->add(v);c->add(v);c->add(v);
            ssgVtxTable*    l = new ssgVtxTable(GL_POLYGON, a,
                                                (ssgNormalArray*)NULL,
                                                (ssgTexCoordArray*)NULL,
                                                c);
            //       (ssgColourArray*)NULL);
            b->addKid(l);
        }   // for i
    }   //   for j
}   // Draw
int StaticSSG::GetHash ( float  x,
float  y 
) [inline, private]

Definition at line 82 of file static_ssg.hpp.

    {
        int m1; int n1;
        GetRowCol(x,y,&m1,&n1);
        return GetHash(m1, n1);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

int StaticSSG::GetHash ( int  m1,
int  n1 
) [inline, private]

Definition at line 88 of file static_ssg.hpp.

{ return m1+n1*m_m;             }
void StaticSSG::GetRowCol ( float  x,
float  y,
int *  m1,
int *  n1 
) [inline, private]

Definition at line 89 of file static_ssg.hpp.

    {
        *m1=(int)((x-m_x_min)*m_invdx);
        *n1=(int)((y-m_y_min)*m_invdy);
    }

Here is the caller graph for this function:

float StaticSSG::hot ( sgVec3  start,
sgVec3  end,
ssgLeaf **  l,
sgVec4 **  nrm 
)

Definition at line 175 of file static_ssg.cpp.

{

    float hot      = NOINTERSECT;
    int N_HASH_START = GetHash(start[0], start[1]);
    int nTriangles = (int)(*m_buckets)[N_HASH_START].size();
    *leaf          = NULL;
    for(int i=0; i<nTriangles; i++)
    {
        InfoTriangle *t = (*m_buckets)[N_HASH_START][i];
        const float HOT_NEW = t->hot(start);
        if(HOT_NEW>hot)
        {
            hot   = HOT_NEW;
            *leaf = t->m_leaf;
            *nrm  = &t->m_plane;
        }
    }   // for i <nTriangles

    if(start[0]==end[0] && start[1]==end[1]) return hot;

    const int HASH_END = GetHash(end[0], end[1]);
    nTriangles   = (int)(*m_buckets)[HASH_END].size();
    for(int i=0; i<nTriangles; i++)
    {
        InfoTriangle *t = (*m_buckets)[HASH_END][i];
        const float HOT_NEW = t->hot(end);
        if(HOT_NEW>hot)
        {
            hot=HOT_NEW;
            *leaf = t->m_leaf;
        }
    }   // for i <nTriangles
    return hot;
}   // StaticSSG::hot

Here is the call graph for this function:

void StaticSSG::Setup ( int  n) [private]

Definition at line 41 of file static_ssg.cpp.

{
    // First compute the minimum and maximum x/y values of all leaves
    MinMax(m_start, &m_x_min, &m_x_max, &m_y_min, &m_y_max);

    const float RATIO = (m_x_max-m_x_min)/(m_y_max-m_y_min);

    /* The m_n, m_m computed here is the maximum value which can be used,
       so the actual range is 0-m_n and 0-m_m, or m_n+1 and m_m+1 'buckets' */
    m_n = (int)round(sqrt(nSize/RATIO));
    m_m = (int)round(nSize/m_n);

    /* Make sure that we don't use more than requested.
       This is done by reducing the larger value by 1.  */
    while(m_n*m_m>nSize)
    {
        if(m_n>m_m) m_n--; else m_m--;
    }

    /* If 'm_m' would be used instead of 'm_m-1', the hash value for the column
       can be any number between 0 and m_m, i.e. m_m+1 different values!        */
    m_invdx   = (float)(m_m-1)/(m_x_max-m_x_min);
    m_invdy   = (float)(m_n-1)/(m_y_max-m_y_min);
    //JH  printf("hash data: m_m=%d, m_n=%d, m_x_max=%f, m_x_min=%f, m_y_max=%f, m_y_min=%f, m_invdx=%f, m_invdy=%f\m_n",
    //  m_m,m_n,m_x_max,m_x_min,m_y_max,m_y_min,m_invdx,m_invdy);
    m_buckets   = new allBucketsType(m_n*m_m);

    sgMat4 mat;
    sgMakeIdentMat4(mat);
    Distribute(m_start, mat);
}   // Setup

Here is the call graph for this function:

Here is the caller graph for this function:

void StaticSSG::StoreTriangle ( ssgLeaf *  l,
int  indx,
sgVec3  vv1,
sgVec3  vv2,
sgVec3  vv3 
) [private]

Definition at line 150 of file static_ssg.cpp.

{
    InfoTriangle* t;
    t = new InfoTriangle(l, indx, vv1, vv2, vv3);
    t->m_x_min = std::min(std::min(vv1[0],vv2[0]), vv3[0]);
    t->m_x_max = std::max(std::max(vv1[0],vv2[0]), vv3[0]);
    t->m_y_min = std::min(std::min(vv1[1],vv2[1]), vv3[1]);
    t->m_y_max = std::max(std::max(vv1[1],vv2[1]), vv3[1]);
    sgMakePlane(t->m_plane, vv1,vv2,vv3);
    int nMin, mMin, nMax, mMax;
    GetRowCol(t->m_x_min, t->m_y_min, &mMin, &nMin);
    GetRowCol(t->m_x_max, t->m_y_max, &mMax, &nMax);
    for(int j=nMin; j<=nMax; j++)
    {
        for(int i=mMin; i<=mMax; i++)
        {
            int nHash = GetHash(i, j);
            (*m_buckets)[nHash].push_back(t);
        }   // for i<=mMax
    }   // for j<=nMax

}   // StoreTriangle

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 71 of file static_ssg.hpp.

Definition at line 72 of file static_ssg.hpp.

float StaticSSG::m_invdx [private]

Definition at line 76 of file static_ssg.hpp.

float StaticSSG::m_invdy [private]

Definition at line 76 of file static_ssg.hpp.

int StaticSSG::m_m [private]

Definition at line 74 of file static_ssg.hpp.

int StaticSSG::m_n [private]

Definition at line 74 of file static_ssg.hpp.

ssgEntity* StaticSSG::m_start [private]

Definition at line 77 of file static_ssg.hpp.

unsigned int StaticSSG::m_test_number [private]

Definition at line 75 of file static_ssg.hpp.

float StaticSSG::m_x_max [private]

Definition at line 73 of file static_ssg.hpp.

float StaticSSG::m_x_min [private]

Definition at line 73 of file static_ssg.hpp.

float StaticSSG::m_y_max [private]

Definition at line 73 of file static_ssg.hpp.

float StaticSSG::m_y_min [private]

Definition at line 73 of file static_ssg.hpp.


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