Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3238 in orxonox.OLD for orxonox/branches/nico/src/collision.cc


Ignore:
Timestamp:
Dec 20, 2004, 2:42:54 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches: updated branches: buerli, nico, sound. And moved bezierTrack to old.bezierTrack. Conflicts resolved in a usefull order.
Conflics mostly resolved in favor of trunk
merge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/nico/src/collision.cc

    r2190 r3238  
    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)
Note: See TracChangeset for help on using the changeset viewer.