Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1899 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
May 20, 2004, 1:03:53 PM (21 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.

Location:
orxonox/trunk/core
Files:
9 edited

Legend:

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

    r1896 r1899  
    3030
    3131
    32 void NPC::setPosition(int x, int y, int z)
     32void NPC::setPosition(float x, float y, float z)
    3333{
    3434  xCor = x; yCor = y; zCor = z;
    3535}
    3636
    37 void NPC::getPosition(int* x, int* y, int* z)
     37void NPC::getPosition(float* x, float* y, float* z)
    3838{
    3939  *x = xCor;
     
    4242}
    4343
    44 void NPC::setCollisionRadius(int r)
     44void NPC::setCollisionRadius(float r)
    4545{
    4646  collisionRadius = r;
     
    5656void NPC::drawNPC(void)
    5757{
    58   cout << "Player::drawNPC()" << endl;
     58  glPushMatrix();
     59  glTranslatef(xCor, yCor, 3.0);
     60  //glScalef(1.0, 3.0, 1.0);
     61  glutWireSphere(1.0, 10, 10);
     62  glPopMatrix();
     63  //cout << "Player::drawNPC()" << endl;
    5964}
  • orxonox/trunk/core/npc.h

    r1896 r1899  
    33#define NPC_H
    44
     5/* openGL Headers */
     6#include <GL/glut.h>
    57
    68class NPC {
     
    1012  ~NPC ();
    1113
     14  /* collision control */
     15  float collisionRadius;
     16
     17  float xCor;
     18  float yCor;
     19  float zCor;
     20
    1221  void drawNPC(void);
    13   void setPosition(int x, int y, int z);
    14   void getPosition(int* x, int* y, int* z);
    15   void setCollisionRadius(int r);
     22  void setPosition(float x, float y, float z);
     23  void getPosition(float* x, float* y, float* z);
     24  void setCollisionRadius(float r);
    1625  float getCollisionRadius();
    1726
     
    2130  int npcType;
    2231
    23   /* collision control */
    24   int collisionRadius;
    2532
    26   int xCor;
    27   int yCor;
    28   int zCor;
    2933;
    3034
  • orxonox/trunk/core/orxonox.cc

    r1897 r1899  
    9999{
    100100  glClearColor(0.0, 0.0, 0.0, 0.0);
     101 
     102  /* world init, shouldnt be done here later */
    101103  world = new World;
    102104  (*world).initEnvironement();
    103105  localPlayer = new Player;
     106  localPlayer->setPosition(0.0, -10.0, 3.0);
    104107  io = new InputOutput(world, localPlayer);
    105108  (*world).addPlayer(localPlayer);
    106109  Environment *env = new Environment;
    107110  (*world).addEnv(env);
     111  NPC* npc = new NPC;
     112  npc->setPosition(3.0, 0.0, 3.0);
     113  npc->setCollisionRadius(1.0);
     114  world->addNPC(npc);
    108115
    109116  glutSpecialFunc(specFunc);
     
    248255  /* increment the frames-per-second counter*/
    249256  fps++;
     257  /* check for collisions */
     258  world->detectCollision();
     259
    250260  /* check for input to pass it over */
    251261  if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) {
  • orxonox/trunk/core/player.cc

    r1896 r1899  
    2525
    2626Player::Player () {
     27  // cout << "Player::Player" << endl;
    2728  xCor = yCor = zCor = 0;
    2829  shootLaser = new ShootLaser;
  • orxonox/trunk/core/player.h

    r1896 r1899  
    1515  ~Player ();
    1616
     17  /* position of the spacecraft */
     18  float xCor;
     19  float yCor;
     20  float zCor;
     21
     22  /* this player wanna shoot? so include a ref to ShootLaser */
     23  ShootLaser* shootLaser;
     24
    1725  void setPosition(float x, float y, float z);
    1826  void getPosition(float* x, float* y, float* z);
     
    2533
    2634 private:
    27   /* position of the spacecraft */
    28   float xCor;
    29   float yCor;
    30   float zCor;
    3135
    3236
    33   /* this player wanna shoot? so include a ref to ShootLaser */
    34   ShootLaser* shootLaser;
    3537};
    3638
  • orxonox/trunk/core/shoot_laser.cc

    r1898 r1899  
    5454      /* fix1: weak boundaries check all four sides */
    5555      /* fix2: conditions, that a struct tree can be cut off */
     56      /* fix3: more efficent and nicer please */
    5657      if (tmpShoot->yCor > 50)
    5758        {
  • orxonox/trunk/core/shoot_laser.h

    r1896 r1899  
    2424    float collisionRadius;
    2525  };
     26  shoot* lastShoot;
    2627
    2728  ShootLaser ();
     
    3435
    3536 private:
    36   shoot* lastShoot;
     37
    3738};
    3839
  • 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/**
  • orxonox/trunk/core/world.h

    r1896 r1899  
    66
    77#include <stdlib.h>
     8#include <cmath>
    89
    910#include "npc.h"
     
    4849  envList* lastEnv;
    4950
    50   /* a list of all shoot-amental objects */
    51   struct shootList {
    52     shootList* next;
    53     ShootLaser* shoot;
    54     int number;
    55   };
    56   shootList* lastShoot;
     51
    5752
    5853
     
    6358  bool removeNPC(NPC* npc);
    6459  bool addEnv(Environment* env);
    65   bool addShoot(ShootLaser* shoot);
    6660
    6761  void drawWorld(void);
    6862  void initEnvironement(void);
    6963  void updateWorld(void);
     64  void detectCollision(void);
    7065  void testThaTest(void);
    7166
Note: See TracChangeset for help on using the changeset viewer.