Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3231 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Dec 20, 2004, 12:49:07 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: iniparser, collision fixed

Location:
orxonox/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/campaign.cc

    r3225 r3231  
    181181  ListTemplate<StoryEntity>* l;
    182182  StoryEntity* entity = NULL;
    183   l = this->entities->get_next(); 
     183  l = this->entities->getNext(); 
    184184  while( l != NULL)
    185185    {
    186       entity = l->get_object();
    187       l = l->get_next();
     186      entity = l->getObject();
     187      l = l->getNext();
    188188      int id = entity->getStoryID();
    189189      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
  • orxonox/trunk/src/collision.cc

    r2190 r3231  
    2828CollisionCluster::CollisionCluster (float rad = 1.0, Vector mid = Vector(0,0,0))
    2929{
    30   root = (CC_Tree*) malloc( sizeof( CC_Tree));
     30  root = (CCTree*) malloc( sizeof( CCTree));
    3131  root->n = 0;
    3232  root->data.ID = 0;
     
    6262  }
    6363 
    64   root = load_CC_Tree (stream);
     64  root = loadCCTree (stream);
    6565  fclose (stream);
    6666}
     
    7171CollisionCluster::~CollisionCluster ()
    7272{
    73   free_CC_Tree( root);
     73  freeCCTree(root);
    7474}
    7575
     
    8585  stream = fopen( filename, "wb");
    8686  if( stream == NULL) return -1;
    87   r = save_CC_Tree (root, stream);
     87  r = saveCCTree(root, stream);
    8888  fclose (stream);
    8989  return r;
     
    9999   \return true on collision, false otherwise. If true is returned, the flag in ahitflags that symbolises the hit subsphere is set, and impactpoint is set to the Location where the intersection occured
    100100*/
    101 bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint)
    102 {
    103         CC_Tree* t;
     101bool checkTrace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint)
     102{
     103        CCTree* t;
    104104        if( (t = a->root) == NULL) return false;
    105105       
    106   return cctree_trace( pa, t, ahitflags, trace, impactpoint);
     106  return cctreeTrace( pa, t, ahitflags, trace, impactpoint);
    107107}
    108108
     
    118118   If true is returned, all flags in ahitflags and bhitflags that symbolize intersecting subspheres in the respective CollisionCluster are set
    119119*/
    120 bool check_collision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags)
    121 {
    122   CC_Tree* ta, *tb;
     120bool checkCollision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags)
     121{
     122  CCTree* ta, *tb;
    123123  if( (ta = a->root) == NULL) return false;
    124124  if( (tb = b->root) == NULL) return false;
    125125 
    126   return cctree_iterate(pa, ta, ahitflags, pb, tb, bhitflags);
     126  return cctreeIterate(pa, ta, ahitflags, pb, tb, bhitflags);
    127127}
    128128
     
    135135   \return true on intersection, false otherwise
    136136*/
    137 bool sphere_sphere_collision( Vector m1, float r1, Vector m2, float r2)
     137bool sphereSphereCollision( Vector m1, float r1, Vector m2, float r2)
    138138{
    139139  if ((m1-m2).len() < r1+r2) return true;
     
    149149   \return true on intersection, false otherwise. If true is returned, impactpoint is set to the loaction where the intersection occured
    150150*/
    151 bool trace_sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint)
     151bool traceSphereCollision( Vector m, float r, const Line* l, Vector* impactpoint)
    152152{
    153153  float A, B, C, D, t[2];
     
    176176}
    177177
    178 bool cctree_iterate(const Placement* pa, CC_Tree* ta, unsigned long* ahitflags, const Placement* pb, CC_Tree* tb, unsigned long* bhitflags)
     178bool cctreeIterate(const Placement* pa, CCTree* ta, unsigned long* ahitflags, const Placement* pb, CCTree* tb, unsigned long* bhitflags)
    179179{
    180180  bool r = false;
     
    182182  Vector mra = pa->r + pa->w.apply(ta->m);
    183183  Vector mrb = pb->r + pb->w.apply(tb->m);
    184   CC_Tree* use_a, *use_b;
    185  
    186   if( use_a == NULL || use_b == NULL) return false;
    187  
    188   if( sphere_sphere_collision( mra, ta->r, mrb, tb->r))
     184  CCTree* useA, *useB;
     185 
     186  if( useA == NULL || useB == NULL) return false;
     187 
     188  if( sphereSphereCollision( mra, ta->r, mrb, tb->r))
    189189  {
    190190    if( ta->n == 0 && tb->n == 0)
     
    196196    for( ia = 0; ia < ta->n || ta->n == 0; ia++)
    197197    {
    198       if( ta->n == 0) use_a = ta;
    199       else use_a = ta->data.b[ia];
     198      if( ta->n == 0) useA = ta;
     199      else useA = ta->data.b[ia];
    200200      for( ib = 0; ib < tb->n || ta->n == 0; ib++)
    201201      {
    202         if( ta->n == 0) use_b = ta;
    203         else use_b = ta->data.b[ib];
     202        if( ta->n == 0) useB = ta;
     203        else useB = ta->data.b[ib];
    204204       
    205         r = r || cctree_iterate( pa, use_a, ahitflags, pb, use_b, bhitflags);
     205        r = r || cctreeIterate( pa, useA, ahitflags, pb, useB, bhitflags);
    206206       
    207207        if( tb->n == 0) break;
     
    233233
    234234/**
    235    \brief frees the memory allocated in a CC_Tree
    236 */
    237 void free_CC_Tree( CC_Tree* tree)
     235   \brief frees the memory allocated in a CCTree
     236*/
     237void freeCCTree( CCTree* tree)
    238238{
    239239  if (tree == NULL) return;
    240240  for (int i = 0; i < tree->n; i++)
    241241  {
    242     free_CC_Tree( tree->data.b[i]);
     242    freeCCTree(tree->data.b[i]);
    243243  }
    244244  free( tree);
     
    246246
    247247/**
    248    \brief loads a CC_Tree from a stream
    249 */
    250 CC_Tree* load_CC_Tree (FILE* stream)
    251 {
    252   CC_Tree* tree = NULL;
    253   CC_Tree** branches = NULL;
     248   \brief loads a CCTree from a stream
     249*/
     250CCTree* loadCCTree (FILE* stream)
     251{
     252  CCTree* tree = NULL;
     253  CCTree** branches = NULL;
    254254  float buf[4];
    255255  unsigned long n;
     
    267267  else
    268268  {
    269     branches = (CC_Tree**)malloc( sizeof(CC_Tree*) * n);
     269    branches = (CCTree**)malloc( sizeof(CCTree*) * n);
    270270    for( int i = 0; i < n; i++)
    271271    {
    272       if ((branches[i] = load_CC_Tree (stream)) == NULL)
     272      if ((branches[i] = loadCCTree (stream)) == NULL)
    273273      {
    274274        for( int j = 0; j < i; j++)
    275275        {
    276           free_CC_Tree (branches[j]);
    277           free (branches);
     276          freeCCTree (branches[j]);
     277          free(branches);
    278278          return NULL;
    279279        }
     
    283283 
    284284  // assemble
    285   tree = (CC_Tree*) malloc (sizeof(CC_Tree));
     285  tree = (CCTree*) malloc (sizeof(CCTree));
    286286  tree->m.x = buf[0];
    287287  tree->m.y = buf[1];
     
    297297
    298298/**
    299    \brief saves a CC_Tree to a stream
    300 */
    301 int save_CC_Tree (CC_Tree* tree, FILE* stream)
     299   \brief saves a CCTree to a stream
     300*/
     301int saveCCTree (CCTree* tree, FILE* stream)
    302302{
    303303  float buf[4];
     
    321321    for( int i = 0; i < tree->n; i++)
    322322    {
    323       if ( save_CC_Tree (tree->data.b[i], stream) == -1) return -1;
     323      if ( saveCCTree (tree->data.b[i], stream) == -1) return -1;
    324324    }
    325325  }
     
    329329}
    330330
    331 bool cctree_trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint)
     331bool cctreetrace( const Placement* p, CCTree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint)
    332332{
    333333  bool r = false;
    334334  int i;
    335335  Vector mr = p->r + p->w.apply (t->m);
    336   CC_Tree* use_t;
     336  CCTree* useT;
    337337  Vector* ips;
    338338  unsigned long* hfs;
    339339 
    340   if( trace_sphere_collision (mr, t->r, trace, impactpoint))
     340  if( traceSphereCollision (mr, t->r, trace, impactpoint))
    341341  {
    342342        if( t->n == 0)
     
    352352                for (i = 0; i < t->n; i++)
    353353                {
    354                         r = r || cctree_trace (p, t->data.b[i], &(hfs[i]), trace, &(ips[i]));
     354                        r = r || cctreeTrace (p, t->data.b[i], &(hfs[i]), trace, &(ips[i]));
    355355                }
    356356                if( r)
  • orxonox/trunk/src/collision.h

    r3224 r3231  
    1414
    1515//! Tree structure used by the CollisionCluster
    16 typedef struct CC_Tree
     16typedef struct CCTree
    1717{
    1818  unsigned long n;
    1919  union
    2020  {
    21   struct CC_Tree** b;
     21  struct CCTree** b;
    2222  unsigned long ID;
    2323  } data;
    2424  float r;
    2525  Vector m;
    26 } CC_Tree;
     26} CCTree;
    2727
    2828//! Basic collision detection class
     
    4242class CollisionCluster {
    4343 
    44   CC_Tree* root;
     44  CCTree* root;
    4545 
    4646 
     
    5252  int store (char* filename);
    5353 
    54   friend bool cctree_trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint);
    55   friend bool cctree_iterate(const Placement* pa, CC_Tree* ta, unsigned long* ahitflags, const Placement* pb, CC_Tree* tb, unsigned long* bhitflags);
    56   friend bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint);
    57   friend bool check_collision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags);
     54  friend bool cctreeTrace( const Placement* p, CCTree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint);
     55  friend bool cctreeIterate(const Placement* pa, CCTree* ta, unsigned long* ahitflags, const Placement* pb, CCTree* tb, unsigned long* bhitflags);
     56  friend bool checkTrace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint);
     57  friend bool checkCollision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags);
    5858};
    5959
    60 bool sphere_sphere_collision( Vector m1, float r1, Vector m2, float r2);
    61 bool trace_sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint);
     60bool sphereSphereCollision( Vector m1, float r1, Vector m2, float r2);
     61bool traceSphereCollision( Vector m, float r, const Line* l, Vector* impactpoint);
    6262
    6363void setflag( unsigned long* flags, unsigned long ID);
    6464
    65 void free_CC_Tree( CC_Tree* tree);
    66 CC_Tree* load_CC_Tree (FILE* stream);
    67 int save_CC_Tree (CC_Tree* tree, FILE* stream);
     65void freeCCTree( CCTree* tree);
     66CCTree* loadCCTree (FILE* stream);
     67int saveCCTree (CCTree* tree, FILE* stream);
    6868
    6969#endif /* _COLLISION_H */
  • orxonox/trunk/src/ini_parser.cc

    r2551 r3231  
    2525IniParser::IniParser (char* filename)
    2626{
    27         stream = NULL;
    28         bInSection = false;
    29         open_file (filename);
     27  stream = NULL;
     28  bInSection = false;
     29  openFile(filename);
    3030}
    3131
     
    3535IniParser::~IniParser ()
    3636{
    37         if( stream != NULL) fclose (stream);
     37  if( stream != NULL) fclose (stream);
    3838}
    3939
    4040/**
    41         \brief opens another file to parse
    42         \param filename: path and name of the new file to parse
    43         \return zero on success or -1 if an error occured;
     41   \brief opens another file to parse
     42   \param filename: path and name of the new file to parse
     43   \return zero on success or -1 if an error occured;
    4444*/
    45 int IniParser::open_file( char* filename)
     45int IniParser::openFile( char* filename)
    4646{
    47         if( filename == NULL) return -1;
    48         if( stream != NULL)     fclose (stream);
    49         if( (stream = fopen (filename, "r")) == NULL)
    50         {
    51                 printf("IniParser could not open %s\n", filename);
    52                 return -1;
    53         }
    54         bInSection = false;
    55         return 0;
     47  if( filename == NULL) return -1;
     48  if( stream != NULL)   fclose (stream);
     49  if( (stream = fopen (filename, "r")) == NULL)
     50    {
     51      printf("IniParser could not open %s\n", filename);
     52      return -1;
     53    }
     54  bInSection = false;
     55  return 0;
    5656}
    5757
    5858/**
    59         \brief set the parsing cursor to the specified section
    60         \param section: the name of the section to set the cursor to
    61         \return zero on success or -1 if the section could not be found
     59   \brief set the parsing cursor to the specified section
     60   \param section: the name of the section to set the cursor to
     61   \return zero on success or -1 if the section could not be found
    6262*/
    63 int IniParser::get_section( char* section)
     63int IniParser::getSection( char* section)
    6464{
    6565  bInSection = false;
     
    9595
    9696/**
    97         \brief gets the next VarName=VarValue pair from the parsing stream
    98         \param name: a pointer to a buffer to store the name of the entry
    99         \param value: a pointer to a buffer to store the value of the entry
    100         \return zero if the buffers have been filled with data or -1 if there are no entries left in the current section
     97   \brief gets the next VarName=VarValue pair from the parsing stream
     98   \param name: a pointer to a buffer to store the name of the entry
     99   \param value: a pointer to a buffer to store the value of the entry
     100   \return zero if the buffers have been filled with data or -1 if there are no entries left in the current section
    101101*/
    102 int IniParser::next_var( char* name, char* value)
     102int IniParser::nextVar( char* name, char* value)
    103103{
    104         if( stream == NULL)
     104  if( stream == NULL)
     105    {
     106      bInSection = false;
     107      return -1;
     108    }
     109  if( !bInSection) return -1;
     110 
     111  char linebuffer[PARSELINELENGHT];
     112  char* ptr;
     113 
     114  while( !feof( stream))
     115    {
     116      // get next line
     117      fgets (linebuffer, PARSELINELENGHT, stream);
     118      // remove newline char
     119      if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0;
     120      if( linebuffer[0] == '[')
    105121        {
    106                 bInSection = false;
    107                 return -1;
     122          bInSection = false;
     123          return -1;
    108124        }
    109         if( !bInSection) return -1;
    110        
    111         char linebuffer[PARSELINELENGHT];
    112         char* ptr;
    113 
    114         while( !feof( stream))
     125      if( (ptr = strchr( linebuffer, '=')) != NULL)
    115126        {
    116                         // get next line
    117                 fgets (linebuffer, PARSELINELENGHT, stream);
    118                         // remove newline char
    119                 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0;
    120                 if( linebuffer[0] == '[')
    121                 {
    122                         bInSection = false;
    123                         return -1;
    124                 }
    125                 if( (ptr = strchr( linebuffer, '=')) != NULL)
    126                 {
    127                         if( ptr == linebuffer) continue;
    128                         strcpy (value, &ptr[1]);
    129                         strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1);
    130                         return 0;
    131                 }
     127          if( ptr == linebuffer) continue;
     128          strcpy (value, &ptr[1]);
     129          strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1);
     130          return 0;
    132131        }
    133         return -1;     
     132    }
     133  return -1;   
    134134}
    135135
    136136/**
    137         \brief directly acesses an entry in a section
    138         \param name: the name of the entry to find
    139         \param section: the section where the entry is to be found
    140         \param defvalue: what should be returned in case the entry cannot be found
    141         \return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found
    142 
    143         The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly
    144         lead to unwanted behaviour.
     137   \brief directly acesses an entry in a section
     138   \param name: the name of the entry to find
     139   \param section: the section where the entry is to be found
     140   \param defvalue: what should be returned in case the entry cannot be found
     141   \return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found
     142   
     143   The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly
     144   lead to unwanted behaviour.
    145145*/
    146 char* IniParser::get_var( char* name, char* section, char* defvalue = "")
     146char* IniParser::getVar( char* name, char* section, char* defvalue = "")
    147147{
    148         strcpy (internbuf, defvalue);
    149         if( get_section (section) == -1) return internbuf;
    150        
    151         char namebuf[PARSELINELENGHT];
    152         char valuebuf[PARSELINELENGHT];
    153        
    154         while( next_var (namebuf, valuebuf) != -1)
     148  strcpy (internbuf, defvalue);
     149  if( getSection (section) == -1) return internbuf;
     150 
     151  char namebuf[PARSELINELENGHT];
     152  char valuebuf[PARSELINELENGHT];
     153 
     154  while( nextVar (namebuf, valuebuf) != -1)
     155    {
     156      if( !strcmp (name, namebuf))
    155157        {
    156                 if( !strcmp (name, namebuf))
    157                 {
    158                         strcpy (internbuf, valuebuf);
    159                         return internbuf;
    160                 }
     158          strcpy (internbuf, valuebuf);
     159          return internbuf;
    161160        }
    162         return internbuf;
     161    }
     162  return internbuf;
    163163}
  • orxonox/trunk/src/ini_parser.h

    r3224 r3231  
    2929  ~IniParser ();
    3030 
    31   char* get_var( char* name, char* section, char* defvalue);
    32         int open_file( char* name);
    33   int get_section( char* section);
    34   int next_var( char* name, char* value);
     31  char* getVar( char* name, char* section, char* defvalue);
     32        int openFile( char* name);
     33  int getSection( char* section);
     34  int nextVar( char* name, char* value);
    3535};
    3636
Note: See TracChangeset for help on using the changeset viewer.