Back to index

supertuxkart  0.5+dfsg1
static_ssg.hpp
Go to the documentation of this file.
00001 //  $Id: static_ssg.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distribhuted in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef _HEADER_STATICSSG_
00021 #define _HEADER_STATICSSG_
00022 
00023 #include <vector>
00024 #include <plib/ssg.h>
00025 
00026 #define NOINTERSECT -999999.9f
00027 
00028 class InfoTriangle
00029 {
00030 public:
00031     ssgLeaf*     m_leaf;
00032     int          m_indx;
00033     sgVec3       m_vv1,m_vv2,m_vv3;
00034     unsigned int m_test_nr;
00035     sgVec4       m_plane;
00036     float        m_x_min, m_x_max, m_y_min, m_y_max;
00037     // distance to plane in case of a hit, undefined otherwise
00038     float        m_dist;
00039 public:
00040     InfoTriangle() {};
00041     InfoTriangle(ssgLeaf* l,int i,sgVec3 v1,sgVec3 v2,sgVec3 v3)
00042     {
00043         m_leaf = l; m_indx=i;
00044         sgCopyVec3(m_vv1,v1);
00045         sgCopyVec3(m_vv2,v2);
00046         sgCopyVec3(m_vv3,v3);
00047         m_test_nr=0;
00048         l->ref();
00049     }
00050     ~InfoTriangle()                           { ssgDeRefDelete(m_leaf); }
00051     float hot(sgVec3 p);
00052     int   collision(sgSphere *s);
00053 }
00054 ;   // InfoTriangle
00055 
00056 // =============================================================================
00057 typedef std::vector<InfoTriangle*> AllHits;
00058 
00059 // =============================================================================
00060 class StaticSSG
00061 {
00062 private:
00063     /* allLeavesType is a list storing all triangles which
00064        touch a certain hash bucket.                        */
00065     typedef std::vector<InfoTriangle*>  allLeavesType;
00066 
00067     /* This is the list of buckets, each of which stores
00068        a list of leaves at that hash value/bucket          */
00069     typedef std::vector<allLeavesType> allBucketsType;
00070 
00071     allLeavesType   m_all_leaves;
00072     allBucketsType* m_buckets;
00073     float           m_x_min, m_x_max, m_y_min, m_y_max;
00074     int             m_n, m_m;
00075     unsigned int    m_test_number;
00076     float           m_invdx, m_invdy;
00077     ssgEntity*      m_start;
00078 
00079     void Setup        (int n);
00080     void Distribute   (ssgEntity* start, sgMat4 m);
00081     void StoreTriangle(ssgLeaf* l, int indx, sgVec3 vv1, sgVec3 vv2, sgVec3 vv3);
00082     int  GetHash  (float x, float y)
00083     {
00084         int m1; int n1;
00085         GetRowCol(x,y,&m1,&n1);
00086         return GetHash(m1, n1);
00087     }
00088     int  GetHash  (int m1,  int n1 ) { return m1+n1*m_m;             }
00089     void GetRowCol(float x, float y, int *m1, int *n1)
00090     {
00091         *m1=(int)((x-m_x_min)*m_invdx);
00092         *n1=(int)((y-m_y_min)*m_invdy);
00093     }
00094 public:
00095     StaticSSG(ssgEntity* start, int n);
00096     void Draw(ssgBranch* b);
00097     float hot(sgVec3 start, sgVec3 end, ssgLeaf** l, sgVec4** nrm);
00098     int collision(sgSphere *s, AllHits *allHits);
00099 };
00100 #endif