Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1899 in orxonox.OLD for orxonox/trunk/core/world.cc


Ignore:
Timestamp:
May 20, 2004, 1:03:53 PM (20 years ago)
Author:
patrick
Message:

trunk/orxonox: collision detection implemented: simple spheres. all debug informations still print out to console. one enemy added, no AI, no move, waits to be killed. No kill signal implemented yet: look debug infos on console.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/core/world.cc

    r1896 r1899  
    3333  lastNPC = null;
    3434  lastEnv = null;
    35   lastShoot = null;
    3635}
    3736
     
    128127
    129128
    130 /**
    131    \brief Add environmental object
    132    \param player A reference to the new env object
    133    
    134    Add a new Environment to the world. Env has to be initialised before.
    135 */
    136 bool World::addShoot(ShootLaser* shoot)
    137 {
    138   shootList* listMember = new shootList;
    139   listMember->shoot = shoot;
    140   if ( lastShoot != null )
    141     {
    142       listMember->number = lastShoot->number + 1;
    143       listMember->next = lastShoot;
    144     }
    145   else
    146     {
    147       listMember->number = 0;
    148       listMember->next = null;
    149     }
    150   lastShoot = listMember;
    151 }
     129
    152130
    153131
     
    193171      tmpEnv = tmpEnv->next;
    194172    }
    195   /* now draw all the shoots (many) */
    196   shootList* tmpShoot = lastShoot;
    197   while( tmpShoot != null )
    198     {
    199       (*tmpShoot->shoot).drawShoot();
    200       tmpShoot = tmpShoot->next;
    201     }
     173
    202174 
    203175  glColor3f(0.0, 1.0, 0.0);
     
    255227
    256228
     229/* collision detection */
     230/* fix: bad efficency: stupid brute force */
     231
     232void World::detectCollision()
     233{
     234  float xOff, yOff, zOff, radius;
     235  npcList* tmpNPC;
     236
     237  //cout << "World::detectCollsions" << endl;
     238  /* first: check if any player's shoots trigger a collision */
     239  playerList* tmpPlayer = lastPlayer;
     240  Player* player = tmpPlayer->player;
     241  while( tmpPlayer != null )
     242    {
     243      tmpNPC = lastNPC;
     244      while( tmpNPC != null )
     245        {
     246          radius = tmpNPC->npc->collisionRadius;
     247          ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot;
     248          while( shoota != null )
     249            {
     250              xOff = shoota->xCor - tmpNPC->npc->xCor;
     251              yOff = shoota->yCor - tmpNPC->npc->yCor;
     252              zOff = shoota->zCor - tmpNPC->npc->zCor;
     253              if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
     254                cout << "COLLISION " << endl;
     255              shoota = shoota->next;
     256            }
     257          tmpNPC = tmpNPC->next;
     258        }
     259     
     260      tmpPlayer = tmpPlayer->next;
     261    }
     262
     263  /* second: check if any player hits an enemy */
     264
     265  /* third: check if any enemy shoots a player */
     266
     267  //cout << "World::detectCollisions end" << endl;
     268}
     269
     270
    257271
    258272/**
Note: See TracChangeset for help on using the changeset viewer.