Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9003 in orxonox.OLD for trunk


Ignore:
Timestamp:
Jul 2, 2006, 1:36:13 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

Location:
trunk/src
Files:
2 deleted
30 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r8973 r9003  
    188188  CL_SKYDOME                    =    0x00000313,
    189189  CL_DOOR                       =    0x00000314,
     190  CL_REPAIR_STATION             =    0x00000315,
     191  CL_CRANE                      =    0x00000316,
     192  CL_BRAKING_WALL               =    0X00000317,
    190193
    191194  // Playables
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8894 r9003  
    2323#include "world_entity.h"
    2424#include "cr_physics_ground_walk.h"
     25#include "collision_reaction.h"
    2526
    2627#include <vector>
     
    5859void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
    5960{
    60   CollisionEvent* ce = collision->getCollisionEvents().front();
    61   Vector normal = ce->getGroundNormal();
    62   // normal.normalize();
    63 
    64   // put it back
    65   //   PRINTF(0)("putting it back to lastPos: \n");
    66   //   this->lastPositions[0].debug();
    67   //   PRINTF(0)("current pos:\n");
    68   //   collision->getEntityB()->getAbsCoor().debug();
    69 
    70   float height;
     61
    7162  AABB* box = collision->getEntityB()->getModelAABB();
    7263  WorldEntity* entity = collision->getEntityB();
    73 
    74   // collision position maths
    75   Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
    76 
    77   float CR_MAX_WALK_HEIGHT = 2.0f;
    78   float CR_THRESHOLD = 0.2f;
    7964
    8065  if( box == NULL)
     
    8570
    8671
    87   switch( ce->getType())
     72  float CR_MAX_WALK_HEIGHT = 2.0f;
     73  float CR_THRESHOLD = 0.2f;
     74
     75  float height = 0;
     76  float front = 0;
     77  float side = 0;
     78
     79  //PRINTF(0)("collision raction======================================\n");
     80
     81  const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     82  std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     83  for(; it != collisionEvents->end(); it++)
    8884  {
    89     case COLLISION_TYPE_AXIS_Y:
    90 
    91       height = collPos.y - box->halfLength[1];
    92      // PRINTF(0)("height: %f          , model height: %f\n", height, box->halfLength[1]);
    93      // PRINTF(0)(" ground normal: %f, %f, %f\n", normal.x, normal.y, normal.z);
    94 
    95       // object is beneath the plane (ground)
    96       if( height <= 0.0f )
    97       {
    98         entity->shiftCoor(Vector(0, -height, 0));
    99       }
    100       // object is already in the wall
    101       else if( ce->isInWall())
    102       {
    103         entity->setAbsCoor(entity->getLastAbsCoor());
    104       }
    105       break;
    106 
    107 
    108     case COLLISION_TYPE_AXIS_X:
    109     case COLLISION_TYPE_AXIS_Z:
    110       break;
    111 
    112     }
    113 
    114 
     85
     86    CollisionEvent* ce = (*it);
     87    Vector normal = ce->getGroundNormal();
     88
     89    // calculate the collision position
     90    Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     91
     92    // test the 3 axis differently
     93    switch( ce->getType())
     94    {
     95        // collision in the x-axis
     96      case COLLISION_TYPE_AXIS_X:
     97        front = collPos.x - box->halfLength[0]; // should be [0]
     98
     99        // object is beneath the plane (ground)
     100        if( front <= 0.0f )
     101        {
     102          Vector backoff = entity->getAbsDirX() * front;
     103//           entity->shiftCoor(backoff);
     104        }
     105        // object is already in the wall
     106        else if( ce->isInWall())
     107        {
     108//           entity->setAbsCoor(entity->getLastAbsCoor());
     109        }
     110        break;
     111
     112
     113        // collision in the y-axis
     114      case COLLISION_TYPE_AXIS_Y:
     115        // calulate the height above ground
     116        height = collPos.y - box->halfLength[1];
     117
     118
     119        // object is beneath the plane (ground)
     120        if( height <= 0.0f )
     121        {
     122          entity->shiftCoor(Vector(0.0f, -height, 0.0f));
     123          entity->setOnGround(true);
     124        }
     125        // object is already in the wall
     126        else if( ce->isInWall())
     127        {
     128          entity->setAbsCoor(entity->getLastAbsCoor());
     129        }
     130        else
     131        {
     132          // entity is not on ground
     133          entity->setOnGround(false);
     134        }
     135        break;
     136
     137
     138        // collision in the z-axis
     139      case COLLISION_TYPE_AXIS_Z:
     140
     141        side = collPos.z - box->halfLength[2]; // should be [2]
     142
     143        // object is beneath the plane (ground)
     144        if( side <= 0.0f )
     145        {
     146          Vector backoff = entity->getAbsDirX() * side;
     147//           entity->shiftCoor(backoff);
     148        }
     149        // object is already in the wall
     150        else if( ce->isInWall())
     151        {
     152//           entity->setAbsCoor(entity->getLastAbsCoor());
     153        }
     154        break;
     155    }
     156  }
     157  //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
    115158
    116159
     
    126169
    127170
    128   if( box != NULL) {
    129 
    130 
    131     if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
     171  if( box != NULL)
     172  {
     173
     174
     175    if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
     176    {
    132177      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    133178      return;
    134179    }
    135     if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
     180    if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
     181    {
    136182      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    137183      return;
    138184    }
    139185
    140     if(ce->getGroundNormal().len() <= 0.1f) {
     186    if(ce->getGroundNormal().len() <= 0.1f)
     187    {
    141188      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    142189      return;
     
    144191
    145192
    146     if(ce->getGroundNormal().len() >= 1.4f) {
     193    if(ce->getGroundNormal().len() >= 1.4f)
     194    {
    147195      downspeed++;
    148196      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
     
    164212
    165213    }
    166     else {
     214    else
     215    {
    167216      if(height.y <  box->halfLength[1] + 0.0f   /* && height.y  >  - 55.0f*/) // below ground
    168217      {
     
    194243 */
    195244void CRPhysicsGroundWalk::update(WorldEntity* owner)
    196 {
    197 
    198 }
    199 
    200 
     245{}
     246
     247
  • trunk/src/lib/graphics/importer/bsp_file.cc

    r8894 r9003  
    4646BspFile::BspFile()
    4747{}
     48
     49BspFile::~ BspFile()
     50{
     51  delete [] nodes;
     52  delete [] leaves;
     53  delete [] planes;
     54  delete [] bspModels;
     55  delete [] leafFaces;
     56  delete [] faces;
     57  delete [] leafBrushes;
     58  delete [] brushes;
     59  delete [] brushSides;
     60  delete [] vertice;
     61  delete [] meshverts;
     62  delete [] visData;
     63  delete [] textures;
     64  delete [] patchVertice;
     65  delete [] patchIndexes;
     66 // delete [] patchTrianglesPerRow;
     67  delete [] lightMaps;
     68 
     69  for(int i = 0; i < this->numPatches; ++i) delete this->VertexArrayModels[i];
     70 // delete  [] VertexArrayModels;
     71 
     72  for(int i = 0; i < this->numTextures; ++i)
     73  {
     74    delete this->Materials[i].mat;
     75    //delete this->Materials[i].aviMat;
     76  }
     77  delete [] this->Materials;
     78  //delete [] testSurf;
     79 
     80 
     81 
     82}
    4883
    4984/**
     
    294329    this->patchVertice = new char[8*8*44*(this->numPatches+10)];
    295330    this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)];
    296     this->patchRowIndexes = new int*[7*4*this->numPatches];
     331 // this->patchRowIndexes = new int*[7*4*this->numPatches]; Not needed?
    297332    this->patchTrianglesPerRow = new char[7*4*this->numPatches];
    298333    this->VertexArrayModels  = new VertexArrayModel*[this->numPatches];
     
    464499
    465500    if(File(absFileName).exists()) {
    466       PRINTF(0)("BSP FILE: gefunden . \n");
     501      PRINTF(4)("BSP FILE: gefunden . \n");
    467502      this->Materials[i] = this->loadAVI(fileName);
    468503      continue;
     
    553588    }
    554589
    555     PRINTF(0)("BSP FILE: Textur %s nicht  gefunden . \n", &this->textures[8+72*i]);
     590    PRINTF(0)("BSP FILE: Texture %s not found.",&this->textures[8+ 72*i] );
    556591    //  Default Material
    557592    this->Materials[i].mat = new Material();
     
    10121047  Face->meshvert = patchOffset -sz;  //3*(patchOffset-sz)*level1*level1;
    10131048  Face->n_meshverts = sz;
    1014   PRINTF(4)("BSP FILE: sz: %i. \n", sz);
    1015   PRINTF(4)("BSP FILE: Face->meshvert %i . \n", Face->meshvert);
     1049  PRINTF(0)("BSP FILE: sz: %i. \n", sz);
     1050  PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert);
    10161051
    10171052  //Face->n_meshverts = sz;
  • trunk/src/lib/graphics/importer/bsp_file.h

    r8490 r9003  
    151151public:
    152152  BspFile();
     153  ~BspFile();
    153154  int read(const char* name );
    154155  void build_tree();
     
    183184
    184185  int** patchRowIndexes;
    185   VertexArrayModel** VertexArrayModels;
     186  VertexArrayModel** VertexArrayModels; 
    186187  int patchOffset;
    187188
  • trunk/src/lib/graphics/importer/bsp_manager.cc

    r8894 r9003  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3  
     3
    44   Copyright (C) 2006 orx
    5  
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10  
     10
    1111   ### File Specific:
    1212   main-programmer: bottac@ee.ethz.ch
    13  
     13
    1414   Inspired by:
    1515   Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
    1616   Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
    17  
     17
    1818   Collision detection adapted from:
    1919   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
     
    6969BspManager::BspManager(const TiXmlElement* root)
    7070{
    71  
    72  
     71
     72
    7373  if( root != NULL)
    7474    this->loadParams(root);
    75  
     75
    7676  CDEngine::getInstance()->setBSPModel(this);
    7777} */
    7878
    79 void BspManager::load(const char* fileName, float scale)
     79BspManager::~BspManager()
     80{
     81  if(this->bspFile)
     82    delete this->bspFile;
     83}
     84
     85int BspManager::load(const char* fileName, float scale)
    8086{
    8187  // open a BSP file
     88
     89
    8290  this->bspFile = new BspFile();
    8391  this->bspFile->scale =  scale;
    84   this->bspFile->read(ResourceManager::getFullName(fileName).c_str());
     92  if(this->bspFile->read(ResourceManager::getFullName(fileName).c_str()) == -1)
     93    return -1;
     94
    8595  this->bspFile->build_tree();
    8696  this->root  = this->bspFile->get_root();
     
    8898
    8999  this->outputFraction = 1.0f;
     100
     101  return 0;
    90102}
    91103/*
     
    99111  this->root  = this->bspFile->get_root();
    100112  this->alreadyVisible = new bool [this->bspFile->numFaces];
    101  
     113
    102114  CDEngine::getInstance()->setBSPModel(this);
    103115}
     
    962974  Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; //
    963975  Vector dest1 = position + forwardDir*4.0f;
    964   Vector dest2 = position2 + forwardDir;
     976  Vector dest2 = position2 + forwardDir*4.0;
    965977  dest = position - Vector(0.0, 40.0,0.0);
    966978  Vector out = dest;
     
    974986
    975987  if( box != NULL) {
    976     position = worldEntity->getAbsCoor() +  box->center; // + box->axis[1] * box->halfLength[1];
    977     dest     = worldEntity->getAbsCoor() +  box->center - box->axis[1] * box->halfLength[1] * 40.0;
    978 
    979     position1 = worldEntity->getAbsCoor() +  box->center + box->axis[0] * box->halfLength[0] * 2.0f;
    980     dest1     = worldEntity->getAbsCoor() +  box->center - box->axis[0] * box->halfLength[0] *2.0f;
    981 
    982 
    983     position2 = worldEntity->getAbsCoor() +  box->center + box->axis[2] * box->halfLength[2] * 2.0f;
    984     dest2     = worldEntity->getAbsCoor() +  box->center - box->axis[2] * box->halfLength[2] * 2.0f;
     988    position = worldEntity->getAbsCoor() +  box->center + Vector(0.0, 1.0, 0.0) * box->halfLength[1];
     989    dest     = worldEntity->getAbsCoor() +  box->center - Vector(0.0, 1.0, 0.0) * (box->halfLength[1] + BSP_Y_OFFSET);
     990
     991    position1 = worldEntity->getAbsCoor() +  box->center - worldEntity->getAbsDirX() * (box->halfLength[0]  + BSP_X_OFFSET);
     992    dest1     = worldEntity->getAbsCoor() +  box->center + worldEntity->getAbsDirX() * (box->halfLength[0]  + BSP_X_OFFSET);
     993
     994    position2 = worldEntity->getAbsCoor() +  box->center - worldEntity->getAbsDirZ() * (box->halfLength[2]  + BSP_Z_OFFSET);
     995    dest2     = worldEntity->getAbsCoor() +  box->center + worldEntity->getAbsDirZ() * (box->halfLength[2]  + BSP_Z_OFFSET);
    985996
    986997  } else {
     
    9891000  }
    9901001
     1002
     1003//   PRINTF(0)("x and v\n");
     1004//   worldEntity->getAbsDirX().debug();
     1005//   worldEntity->getAbsDirV().debug();
    9911006
    9921007
     
    10351050  plane* testPlane = this->collPlane;
    10361051
    1037 
    10381052  bool xCollision = false;
    10391053  bool zCollision = false;
    1040   if(!SolidFlag) {
     1054
    10411055
    10421056    // 2nd Collision Detection
     
    10481062    this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
    10491063
    1050     if(!this->outputAllSolid != 1.0f) {
     1064    if(this->outputFraction < 1.0f) {
    10511065      out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction;
     1066      dest1 = position1 + (dest1 -position1) * this->outputFraction;
    10521067      xCollision = true;
    10531068      testPlane = this->collPlane;
    10541069    }
    1055     if(this->outputAllSolid) {
     1070    if(this->outputAllSolid ) {
     1071
     1072      this->collPlane = new plane;
     1073      this->collPlane->x = 0.0f;
     1074      this->collPlane->y = 0.0f;
     1075      this->collPlane->z = 0.0f;
     1076      testPlane = this->collPlane;
    10561077      SolidFlag = true;
    1057       xCollision = true; 
     1078      xCollision = true;
    10581079    }
    10591080    //out.z = this->outputFraction;
    10601081
    1061     if(!SolidFlag) {
     1082
    10621083
    10631084      // 3rd Collision Detection
     
    10671088      this->inputStart =  position2;
    10681089      this->inputEnd =   dest2;
     1090
    10691091      this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
    10701092      //out.x = this->outputFraction;
    10711093
    1072       if(this->outputFraction != 1.0f ) {
     1094      if(this->outputFraction < 1.0f ) {
    10731095        out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction;
     1096        dest2 = position2 + (dest2 -position2) * this->outputFraction;
    10741097        zCollision = true;
    10751098        testPlane = this->collPlane;
    10761099
    10771100      }
    1078       if(this->outputAllSolid) {
    1079           SolidFlag = true;
    1080           zCollision = true;   
     1101      if(this->outputAllSolid ) {
     1102        this->collPlane = new plane;
     1103        this->collPlane->x = 0.0f;
     1104        this->collPlane->y = 0.0f;
     1105        this->collPlane->z = 0.0f;
     1106        testPlane = this->collPlane;
     1107
     1108        SolidFlag = true;
     1109        zCollision = true;
    10811110      }
    1082     }
    1083   }//end if
     1111
     1112  //end if
    10841113  /*
    10851114  This is how you would calculate the Coordinates where worldEntity Collided with the BSP world.
     
    10911120  // Return the normal here: Normal's stored in this->collPlane;
    10921121  if( collision) {
    1093     PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
    1094     worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y || (xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0), this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
    1095   } else {
    1096     if(xCollision || zCollision) {
    1097 
    1098       worldEntity->registerCollision((xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0) , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
    1099     }
    1100 
    1101   }
     1122    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
     1123}
     1124  if(xCollision) {
     1125    worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag);
     1126  }
     1127  if(zCollision) {
     1128    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag);
     1129  }
     1130
     1131
    11021132  //else  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y, this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest, false);
    11031133
  • trunk/src/lib/graphics/importer/bsp_manager.h

    r8724 r9003  
    2828
    2929
     30#define BSP_X_OFFSET 20.0f
     31#define BSP_Y_OFFSET 40.0f
     32#define BSP_Z_OFFSET 20.0f
     33
    3034
    3135// FORWARD DECLARATIONS
     
    4145class WorldEntity;
    4246
     47
     48// Obsolete
    4349struct BspCollisionEvent
    4450{
     
    5460
    5561  BspManager(const char* fileName, float scale = 0.4f);
    56   void load(const char* fileName, float scale);
     62
     63  // Deconstructor
     64  ~BspManager();
     65
     66
    5767
    5868  // Functions
     69  int load(const char* fileName, float scale);
    5970  const void draw();
    6071  const void tick(float time);
     
    99110  Vector inputStart;
    100111  Vector inputEnd;
    101  
     112
    102113  Vector traceMins; //!< Mins of current bbox
    103114  Vector traceMaxs; //!< Maxs of current bbox
     
    112123  ::std::deque<int> opal; //!< the others here.
    113124
    114   Vector out;  //!< For debugging only
     125  Vector out;  //!< Stores collision coordinates
    115126  Vector out1; //!< For debugging only
    116127  Vector out2; //!< For debugging only
    117                        
     128
    118129  int tgl;
    119130};
  • trunk/src/lib/graphics/importer/interactive_model.h

    r8894 r9003  
    4040    virtual int getAnimation() = 0;
    4141
     42    virtual bool isAnimationFinished() { return false; }
     43
    4244    virtual void setAnimationSpeed(float speed) {}
    4345};
  • trunk/src/lib/graphics/importer/md2/md2Model.cc

    r8894 r9003  
    8585
    8686  this->scaleFactor = scale;
     87  this->animationSpeed = 1.0f;
    8788
    8889  shadeDots = MD2Model::anormsDots[0];
     
    103104  this->pModelInfo.pTexCoor = (float*)this->data->pTexCoor;
    104105
    105   this->animationSpeed = 1.0f;
    106106
    107107  // triangle conversion
  • trunk/src/lib/graphics/importer/md2/md2Model.h

    r8894 r9003  
    161161  inline int MD2Model::getAnimation() { return this->animationState.type; }
    162162  virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; }
     163  virtual bool isAnimationFinished() { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
    163164  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
    164165  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
  • trunk/src/lib/script_engine/script.cc

    r8783 r9003  
    2424
    2525#include "class_list.h"
     26// uncommet this when the std:string and the const bug is fixed
     27//CREATE_SCRIPTABLE_CLASS(Script, CL_SCRIPT,
     28//                               addMethod("addObject", ExecutorLua2<Script,std::string,std::string>(&Script::addObject))
     29//                               ):
    2630
    2731Script::Script(const TiXmlElement* root)
     
    7377bool Script::loadFile(const std::string& filename)
    7478 {
    75 
     79   this->setName(filename);
    7680   std::string filedest(ResourceManager::getInstance()->getDataDir());
    7781   filedest += "scripts/" + filename;
     
    9397     {
    9498      currentFile = filename;
     99      //this->addThisScript();
    95100      return true;
    96101     }
     
    323328 }
    324329
     330
     331void Script::addThisScript()
     332{
     333  BaseObject* scriptClass = ClassList::getObject("Script", CL_SCRIPT_CLASS);
     334   if (scriptClass != NULL)
     335   {
     336     static_cast<ScriptClass*>(scriptClass)->registerClass(this);
     337     static_cast<ScriptClass*>(scriptClass)->insertObject(this, this,"thisscript", false);
     338   }
     339}
     340
    325341 int Script::reportError(int error)
    326342 {
  • trunk/src/lib/script_engine/script.h

    r8711 r9003  
    3131    void loadFileNoRet(const std::string& filename) { loadFile(filename); };
    3232    bool loadFile(const std::string& filename);
    33     void addObject(const std::string& className, const std::string& objectName);
     33    void addObject( const std::string& className,const std::string& objectName);
    3434
    3535    /// QUERRYING
     
    6161
    6262  private:
    63 
     63    void addThisScript();
    6464    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
    6565    bool registerStandartClasses();                   //!< Register all the classes that the script might need
  • trunk/src/lib/script_engine/script_class.h

    r8408 r9003  
    3434  virtual void registerClass(Script* script) = 0;
    3535  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
     36  virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0;
    3637
    3738  const ScriptMethod* scriptMethods() const { return this->_scriptMethods; }
     
    6465    return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc);
    6566  }
     67
     68  virtual int insertObject(Script* L, BaseObject* obj,const std::string& name, bool gc=false)
     69  {
     70    return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), name, gc);
     71  }
    6672};
    6773
  • trunk/src/lib/script_engine/script_manager.cc

    r8711 r9003  
    7474    while(!scripts->empty())
    7575      delete scripts->front();
     76  //Delete all triggers
     77  if(this->getTriggers())
     78    while(!triggers->empty())
     79      delete triggers->front();
     80 
    7681}
    7782
  • trunk/src/lib/util/executor/executor_lua.cc

    r8894 r9003  
    3737template<> void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); };
    3838template<> void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); };
    39 template<> void toLua<const std::string&>(lua_State* state, const std::string& value) {lua_pushstring (state, value.c_str()); }
     39template<> void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); }
  • trunk/src/util/hud.cc

    r9001 r9003  
    5959
    6060  this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
     61  this->subscribeEvent(ES_ALL, SDLK_TAB);
    6162
    6263
     
    226227  if (event.type == EV_VIDEO_RESIZE)
    227228    this->updateResolution();
    228 }
    229 
    230 
     229  else if (event.type == SDLK_TAB)
     230  {
     231    /// TODO SHOW THE INPUT-LINE
     232  //  this->inputLine->select();
     233  }
     234
     235
     236}
     237
     238
  • trunk/src/world_entities/WorldEntities.am

    r8994 r9003  
    55                world_entities/npcs/ground_turret.cc \
    66                world_entities/npcs/generic_npc.cc \
     7                world_entities/npcs/door.cc \
     8                world_entities/npcs/repair_station.cc \
    79                \
    810                world_entities/environment.cc \
     
    1618                world_entities/character_attributes.cc \
    1719                world_entities/test_entity.cc \
    18                 world_entities/door.cc \
    1920                world_entities/planet.cc \
    2021                world_entities/bsp_entity.cc \
     
    6768                npcs/npc_test1.h \
    6869                npcs/ground_turret.h \
     70                npcs/door.cc \
     71                npcs/repair_station.cc \
     72                \
    6973                environment.h \
    7074                skysphere.h \
     
    7781                character_attributes.h \
    7882                test_entity.h \
    79                 door.h \
    8083                planet.h \
    8184                bsp_entity.h \
  • trunk/src/world_entities/bsp_entity.cc

    r8490 r9003  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3 
     3 
    44   Copyright (C) 2004 orx
    5 
     5 
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10 
     10 
    1111   ### File Specific:
    1212   main-programmer: Claudio Botta
     
    1515
    1616#include "bsp_entity.h"
     17#include "util/loading/resource_manager.h"
    1718#include "util/loading/resource_manager.h"
    1819
     
    3839BspEntity::~BspEntity ()
    3940{
    40   if( this->bspManager)
     41  if( this->bspManager != NULL)
    4142    delete this->bspManager;
    4243}
     44
    4345
    4446
     
    4951void BspEntity::init()
    5052{
    51   this->setClassID(CL_BSP_ENTITY, "BspEntity");
    5253
    53   this->bspManager = new BspManager(this);
    54   this->toList(OM_ENVIRON);
    55 
     54  this->bspManager = NULL;
    5655  /**
    5756   * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition)
     
    6463  PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str());
    6564
    66   this->bspManager->load(name.c_str(), 0.1f);
     65  // Check wether file exists....
     66  if ( File(ResourceManager::getFullName(name)).exists()  ) {
     67
     68    this->setClassID(CL_BSP_ENTITY, "BspEntity");
     69    this->bspManager = new BspManager(this);
     70
     71    if(this->bspManager->load(name.c_str(), 0.1f) == -1 ) {
     72      this->bspManager = NULL;
     73
     74    } else {
     75      this->toList(OM_ENVIRON); // Success!!!
     76    }
     77  } else {
     78    this->bspManager = NULL;
     79    this->toList(OM_DEAD);
     80  }
    6781}
    6882
     
    7690{
    7791  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
    78  // WorldEntity::loadParam(root);
     92  // WorldEntity::loadParam(root);
    7993
    8094  LoadParam(root, "Name", this, BspEntity, setName)
    81       .describe("Sets the of the BSP file.");
     95  .describe("Sets the of the BSP file.");
    8296
    83 /*  LoadParam(root, "Scale", this, BSpEntity, setScale)
    84       .describe("Sets the scale factore of the bsp level.");
    85 */
     97  /*  LoadParam(root, "Scale", this, BSpEntity, setScale)
     98        .describe("Sets the scale factore of the bsp level.");
     99  */
    86100
    87101  /**
     
    115129 */
    116130void BspEntity::collidesWith (WorldEntity* entity, const Vector& location)
    117 {
    118 
    119 }
     131{}
  • trunk/src/world_entities/creatures/fps_player.cc

    r8894 r9003  
    8383  this->bBackward = false;
    8484  this->bJump = false;
     85  this->bPosBut = false;
    8586
    8687  this->xMouse = 0.0f;
     
    9091  this->setHealth(80);
    9192
     93  this->fallVelocity = 0.0f;
    9294
    9395  this->cameraNode.setParent(this);
     
    121123
    122124  this->getWeaponManager().setSlotCount(2);
    123   this->getWeaponManager().setSlotPosition(0, Vector(0.0, 5.0, 0.0));
    124   this->getWeaponManager().setSlotDirection(1, Quaternion(M_PI_4*.5, Vector(0,1,0)));
     125  this->getWeaponManager().setSlotPosition(0, Vector(1.5, -0.7, 1.1));
     126//   this->getWeaponManager().setSlotDirection(0, Quaternion(M_PI_2, Vector(0,1,0)));
    125127  this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    126   this->getWeaponManager().setSlotPosition(1, Vector(-0.5, .2, 1.9));
     128  this->getWeaponManager().setSlotPosition(1, Vector(5.0, 0.0, 0.0));
    127129  this->getWeaponManager().setSlotDirection(1, Quaternion(M_PI_4*.5, Vector(1,0,0)));
    128130
     
    205207void FPSPlayer::tick (float time)
    206208{
     209 
     210  if( this->bPosBut)
     211  {
     212    this->bPosBut = false;
     213    printf("prisoner:walkTo( %f, height, %f)\n",this->getAbsCoorX(),this->getAbsCoorZ());
     214  }
     215 
    207216  Playable::tick( time );
    208217
     
    251260  }
    252261
     262
    253263  velocity *= 100;
    254264
     265
     266  // physical falling of the player
     267  if( !this->isOnGround())
     268  {
     269    this->fallVelocity += 300.0f * time;
     270    velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
     271  }
     272  else
     273  {
     274    this->fallVelocity = 0.0f;
     275  }
     276
     277
    255278  this->shiftCoor( velocity*time );
     279
     280
     281
    256282
    257283
     
    321347  }
    322348  else if( event.type == KeyMapper::PEV_JUMP)
    323     this->getAbsCoor().debug();
    324 }
    325 
    326 
    327 
    328 
     349    this->bPosBut = event.bPressed;
     350}
     351
     352
     353
     354
  • trunk/src/world_entities/creatures/fps_player.h

    r8731 r9003  
    4242    bool                  bBackward;
    4343    bool                  bJump;              //!< jumping
     44    bool                  bPosBut;             //!< position button
    4445
    4546    float                 xMouse;             //!< mouse moved in x-Direction
     
    5152
    5253    PNode                 cameraNode;
     54
     55    float                 fallVelocity;        //!< velocity for falling down
    5356};
    5457
  • trunk/src/world_entities/elements/glgui_radar.cc

    r9002 r9003  
    135135      glRotatef((this->_centerNode->getAbsDir().getHeading() - M_PI_2)* 180.0 /M_PI , 0, 0, 1);
    136136
    137       glPointSize(2.0f);
     137      glPointSize(4.0f);
    138138      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
    139139      {
  • trunk/src/world_entities/npcs/generic_npc.cc

    r8894 r9003  
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    1818
     19#include "generic_npc.h"
     20
    1921
    2022#include "util/loading/factory.h"
     
    2830#include "loading/resource_manager.h"
    2931
    30 #include "generic_npc.h"
    31 
    32 #include "animation/animation3d.h"
    33 
    34 using namespace std;
    35 
    36 
    3732
    3833CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC);
     
    4035#include "script_class.h"
    4136CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC,
    42                        // Move
    43                         addMethod("walkTo", ExecutorLua3ret<GenericNPC,float,float,float,float>(&GenericNPC::walkTo))
    44                         ->addMethod("setTime", ExecutorLua1<GenericNPC,float>(&GenericNPC::setTime))
    45                         ->addMethod("turnTo", ExecutorLua4ret<GenericNPC,bool,float,float,float,float>(&GenericNPC::turnTo))
    46                        // Display
     37                        // Move
     38                        addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo))
     39                        ->addMethod("runTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::runTo))
     40                        ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo))
     41                        ->addMethod("finalGoalReached", ExecutorLua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached))
     42                        // Display
    4743                        ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
    4844                        ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide))
    49                        // Coordinates
     45                        // Coordinates
    5046                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    5147                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     
    5349                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    5450                        ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir))
    55                            
     51
    5652                       );
    5753
     
    6258 */
    6359GenericNPC::GenericNPC(const TiXmlElement* root)
    64   : NPC(root)
     60    : NPC(root)
    6561{
    6662  this->init();
     
    7167
    7268
    73 GenericNPC::GenericNPC()
    74   : NPC(NULL)
    75 {
    76 
    77 }
    78 
    7969/**
    8070 * deconstructor
    8171 */
    8272GenericNPC::~GenericNPC ()
    83 {
    84   if( this->currentAnim != NULL)
    85     delete this->currentAnim;
    86 }
     73{}
    8774
    8875
     
    10087
    10188  time = 30.0f;
     89
    10290  // collision reaction registration
    103 //   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
     91  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    10492}
    10593
     
    128116
    129117
     118
     119/**
     120 * @returns the current animation number
     121 */
     122int GenericNPC::getAnimation()
     123{
     124  if( likely(this->getModel(0) != NULL))
     125    return ((InteractiveModel*)this->getModel(0))->getAnimation();
     126  else
     127    return -1;
     128}
     129
     130
     131
     132/**
     133 * @returns true if animation is finished
     134 */
     135bool GenericNPC::isAnimationFinished()
     136{
     137  if( likely(this->getModel(0) != NULL))
     138    return ((InteractiveModel*)this->getModel(0))->isAnimationFinished();
     139  else
     140    return false;
     141}
     142
     143
     144/**
     145 * sets the animation speed of this entity
     146 */
     147void GenericNPC::setAnimationSpeed(float speed)
     148{
     149  if( likely(this->getModel(0) != NULL))
     150    ((InteractiveModel*)this->getModel(0))->setAnimationSpeed(speed);
     151}
     152
     153
     154
    130155/**
    131156 * sets the animation of this npc
     
    146171 */
    147172void GenericNPC::playSound(std::string filename)
    148 {
    149 
    150 }
    151 
    152 
    153 /**
    154  * walt to
    155  * @param coordinate: coordinate to go to
    156  */
    157 float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    158 {
    159   Vector destCoor = Vector(x, y, z);
    160   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    161 
    162   // check if this is the current goal
    163   if( this->destCoor != destCoor || this->destDir != destDir)
    164   {
    165     this->destCoor = destCoor;
    166     this->destDir = destDir;
    167 
    168     //float time = 100.0f;
    169 
    170     if( this->currentAnim != NULL)
    171       delete this->currentAnim;
    172 
    173     this->currentAnim = new Animation3D(this);
    174     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
    175     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    176     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    177 
    178     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    179     this->currentAnim->play();
    180 
    181     this->setAnimation(RUN, MD2_ANIM_LOOP);
    182   }
    183 
    184   // calculate the distance
    185   Vector distance = this->getAbsCoor() - this->destCoor;
    186   return distance.len();
    187 }
    188 
    189 
    190 /**
    191  * walk to a specific place with direction
    192  *
    193  * @param x: x coordinate to go to
    194  * @param y: y coordinate to go to
    195  * @param z: z coordinate to go to
    196  *
    197  * without turning itself
    198  */
    199 float GenericNPC::walkTo(float x, float y, float z)
    200 {
    201   Quaternion q = this->getAbsDir();
    202 
    203   //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z);
    204 
    205   return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z);
    206 }
    207 
    208 /**
    209  * walk to a specific place with direction
    210  *
    211  * @param x: x coordinate to go to
    212  * @param y: y coordinate to go to
    213  * @param qu: angle to rotate
    214  * @param qx: x coordinate of rotation vector
    215  * @param qy: y coordinate of rotation vector
    216  * @param qz: z coordinate of rotation vector
    217  *
    218  */
    219 float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
    220 {
    221   return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
    222 }
    223 
    224 
    225 /**
    226  * walk to a specific place with direction
    227  *
    228  * @param coor: vector place
    229  * @param dir: direction
    230  *
    231  */
    232 float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir)
    233 {
    234   return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    235 }
    236 
    237 
    238 
    239 /**
    240  * run to a specific place with direction
    241  *
    242  * @param x: x coordinate to go to
    243  * @param y: y coordinate to go to
    244  * @param z: z coordinate to go to
    245  * @param qu: angle to rotate
    246  * @param qx: x coordinate of rotation vector
    247  * @param qy: y coordinate of rotation vector
    248  * @param qz: z coordinate of rotation vector
    249  *
    250  */
    251 float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    252 {
    253   Vector destCoor = Vector(x, y, z);
    254   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    255 
    256   // check if this is the current goal
    257   if( this->destCoor != destCoor || this->destDir != destDir)
    258   {
    259     this->destCoor = destCoor;
    260     this->destDir = destDir;
    261 
    262     float time = 5.0f;
    263 
    264     if( this->currentAnim != NULL)
    265       delete this->currentAnim;
    266 
    267     this->currentAnim = new Animation3D(this);
    268     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    269     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    270 
    271 
    272     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    273     this->currentAnim->play();
    274 
    275     this->setAnimation(RUN, MD2_ANIM_LOOP);
    276   }
    277 
    278   // calculate the distance
    279   Vector distance = this->getAbsCoor() - this->destCoor;
    280   return distance.len();
    281 }
    282 
    283 
    284 /**
    285  * run to a specific place with direction
    286  *
    287  * @param x: x coordinate to go to
    288  * @param y: y coordinate to go to
    289  * @param qu: angle to rotate
    290  * @param qx: x coordinate of rotation vector
    291  * @param qy: y coordinate of rotation vector
    292  * @param qz: z coordinate of rotation vector
    293  *
    294  */
    295 float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz)
    296 {
    297   this->runTo(x, y, 0.0f, qu, qx, qy, qz);
    298 }
    299 
    300 
    301 /**
    302  * run to a specific place with direction
    303  *
    304  * @param coor: vector place
    305  * @param dir: direction
    306  *
    307  */
    308 float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir)
    309 {
    310   this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    311 }
    312 
    313 
    314 /**
    315  * crouch to a specific place with direction
    316  *
    317  * @param x: x coordinate to go to
    318  * @param y: y coordinate to go to
    319  * @param z: z coordinate to go to
    320  * @param qu: angle to rotate
    321  * @param qx: x coordinate of rotation vector
    322  * @param qy: y coordinate of rotation vector
    323  * @param qz: z coordinate of rotation vector
    324  *
    325  */
    326 float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    327 {
    328   Vector destCoor = Vector(x, y, z);
    329   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    330 
    331   // check if this is the current goal
    332   if( this->destCoor != destCoor || this->destDir != destDir)
    333   {
    334     this->destCoor = destCoor;
    335     this->destDir = destDir;
    336 
    337 
    338     if( this->currentAnim != NULL)
    339       delete this->currentAnim;
    340 
    341     this->currentAnim = new Animation3D(this);
    342     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    343     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    344 
    345 
    346     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    347     this->currentAnim->play();
    348 
    349     this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
    350   }
    351 
    352   // calculate the distance
    353   Vector distance = this->getAbsCoor() - this->destCoor;
    354   return distance.len();
    355 }
    356 
    357 
    358 /**
    359  * couch to a specific place with direction
    360  *
    361  * @param x: x coordinate to go to
    362  * @param y: y coordinate to go to
    363  * @param qu: angle to rotate
    364  * @param qx: x coordinate of rotation vector
    365  * @param qy: y coordinate of rotation vector
    366  * @param qz: z coordinate of rotation vector
    367  *
    368  */
    369 float GenericNPC::crouchTo(float x, float y, float qu, float qx, float qy, float qz)
    370 {
    371   this->crouchTo(x, y, 0.0f, qu, qx, qy, qz);
    372 }
    373 
    374 
    375 
    376 /**
    377  * crouch to a specific place with direction
    378  *
    379  * @param coor: vector place
    380  * @param dir: direction
    381  *
    382  */
    383 float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir)
    384 {
    385   this->crouchTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    386 }
     173{}
     174
    387175
    388176
     
    391179 */
    392180void GenericNPC::stop()
    393 {
    394   if( this->currentAnim != NULL)
    395   {
    396     this->currentAnim->stop();
    397     delete this->currentAnim;
    398     this->currentAnim = NULL;
    399 
     181{}
     182
     183
     184
     185void GenericNPC::initNPC()
     186{
     187  if (!this->behaviourList.empty())
     188  {
     189    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     190
     191    switch(this->behaviourList.front().type)
     192    {
     193      case Walk:
     194      {
     195        if( this->getAnimation() != RUN)
     196          this->setAnimation(RUN, MD2_ANIM_LOOP);
     197
     198        Vector dir = (currentAnimation.v - this->getAbsCoor());
     199        dir.y = 0.0f;
     200        dir.getNormalized();
     201        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     202
     203        this->setAnimationSpeed(0.5f);
     204      }
     205        break;
     206      case Run:
     207      {
     208        if( this->getAnimation() != RUN)
     209          this->setAnimation(RUN, MD2_ANIM_LOOP);
     210
     211        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     212        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     213
     214        this->setAnimationSpeed(1.0f);
     215      }
     216        break;
     217      case Crouch:
     218      {
     219        if( this->getAnimation() != CROUCH_WALK)
     220          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     221
     222        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     223        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     224
     225        this->setAnimationSpeed(1.0f);
     226      }
     227        break;
     228      case LookAt:
     229        if( this->getAnimation() != STAND)
     230          this->setAnimation(STAND, MD2_ANIM_LOOP);
     231        break;
     232      case Shoot:
     233        if( this->getAnimation() != STAND)
     234          this->setAnimation(STAND, MD2_ANIM_LOOP);
     235        break;
     236
     237      default:
     238        if( this->getAnimation() != STAND)
     239          this->setAnimation(STAND, MD2_ANIM_LOOP);
     240        break;
     241
     242    }
     243  }
     244}
     245
     246
     247void GenericNPC::nextStep()
     248{
     249  if (!this->behaviourList.empty())
     250    this->behaviourList.pop_front();
     251  else
     252    return;
     253
     254
     255  if (!this->behaviourList.empty())
     256  {
     257    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     258
     259    switch( currentAnimation.type)
     260    {
     261      case Walk:
     262      {
     263        if( this->getAnimation() != RUN)
     264          this->setAnimation(RUN, MD2_ANIM_LOOP);
     265
     266        Vector dir = (currentAnimation.v - this->getAbsCoor());
     267        dir.y = 0.0f;
     268        dir.getNormalized();
     269        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     270
     271        this->setAnimationSpeed(0.5f);
     272      }
     273        break;
     274      case Run:
     275      {
     276        if( this->getAnimation() != RUN)
     277          this->setAnimation(RUN, MD2_ANIM_LOOP);
     278
     279        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     280        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     281
     282        this->setAnimationSpeed(1.0f);
     283      }
     284        break;
     285      case Crouch:
     286      {
     287        if( this->getAnimation() != CROUCH_WALK)
     288          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     289
     290        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     291        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     292
     293        this->setAnimationSpeed(1.0f);
     294      }
     295        break;
     296      case LookAt:
     297      {
     298        if( this->getAnimation() != STAND)
     299          this->setAnimation(STAND, MD2_ANIM_LOOP);
     300      }
     301        break;
     302      case Shoot:
     303        if( this->getAnimation() != STAND)
     304        this->setAnimation(STAND, MD2_ANIM_LOOP);
     305        break;
     306
     307      default:
     308        if( this->getAnimation() != STAND)
     309        this->setAnimation(STAND, MD2_ANIM_LOOP);
     310        break;
     311
     312    }
     313  }
     314  else
     315  {
    400316    this->setAnimation(STAND, MD2_ANIM_LOOP);
    401317  }
    402318}
     319
     320
     321
     322
     323void GenericNPC::walkTo(const Vector& coordinate)
     324{
     325
     326  GenericNPC::Anim anim;
     327  anim.v = coordinate;
     328  anim.type = Walk;
     329  anim.speed = 30.0f;
     330
     331  if( this->behaviourList.empty())
     332  {
     333    this->behaviourList.push_back(anim);
     334    this->initNPC();
     335  }
     336  else
     337    this->behaviourList.push_back(anim);
     338}
     339
     340void GenericNPC::walkTo(float x, float y, float z)
     341{
     342  //printf("Walking to %f, %f, %f \n",x,y,z);
     343  this->walkTo(Vector(x,y,z));
     344
     345}
     346
     347/* running functions */
     348void GenericNPC::runTo(const Vector& coordinate)
     349{
     350  GenericNPC::Anim anim;
     351  anim.v = coordinate;
     352  anim.type = Run;
     353  anim.speed = 60.0f;
     354
     355  if( this->behaviourList.empty())
     356  {
     357    this->behaviourList.push_back(anim);
     358    this->initNPC();
     359  }
     360  else
     361    this->behaviourList.push_back(anim);
     362}
     363
     364void GenericNPC::runTo(float x, float y, float z)
     365{
     366  this->runTo(Vector(x,y,z));
     367}
     368
     369/* couching functinos */
     370void GenericNPC::crouchTo(const Vector& coordinate)
     371{
     372  GenericNPC::Anim anim;
     373  anim.v = coordinate;
     374  anim.type = Crouch;
     375
     376  if( this->behaviourList.empty())
     377  {
     378    this->behaviourList.push_back(anim);
     379    this->initNPC();
     380  }
     381  else
     382    this->behaviourList.push_back(anim);
     383}
     384void GenericNPC::crouchTo(float x, float y, float z)
     385{
     386  this->crouchTo(Vector(x,y,z));
     387}
     388
     389
     390
     391void GenericNPC::turnTo(float degreeInY)
     392{
     393  GenericNPC::Anim anim;
     394  anim.q = Quaternion(Vector(0,1,0), degreeInY);
     395  anim.type = TurnTo;
     396
     397  if( this->behaviourList.empty())
     398  {
     399    this->behaviourList.push_back(anim);
     400    this->initNPC();
     401  }
     402  else
     403    this->behaviourList.push_back(anim);
     404}
     405
    403406
    404407
     
    407410 * @param worldEntity: the worldentity to look at
    408411 */
    409 float GenericNPC::lookAt(WorldEntity* worldEntity)
    410 {}
    411 
    412 
    413 /**
    414  * turns to a given direction
    415  */
    416 bool GenericNPC::turnTo(float qu, float qx, float qy, float qz)
    417 {
    418   Quaternion destDir = Quaternion(Vector(qx, qy, qz).getNormalized(), qu);
    419 
    420   printf("Turning: %f, %f, %f, %f \n",qu,qx,qy,qz);
    421   // check if this is the current goal
    422   if( this->destDir != destDir)
    423   {
    424 //     if( this->currentAnim != NULL)
    425 //       this->currentAnim->stop();
    426 //
    427     PRINTF(0)("SET ANIMATION\n");
    428     this->destDir = destDir;
    429 //
    430 
    431 
    432     if( this->currentAnim != NULL)
    433       delete this->currentAnim;
    434 
    435     this->setAbsDir(destDir);
    436 /*
    437     this->currentAnim = new Animation3D(this);
    438     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
    439     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    440     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    441 
    442 
    443     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    444     this->currentAnim->play();*/
    445 
    446     this->setAnimation(STAND, MD2_ANIM_LOOP);
    447   }
    448 
    449   // calculate the distance
    450   Vector distance = this->getAbsCoor() - this->destCoor;
    451   return distance.len();
    452 }
     412void GenericNPC::lookAt(WorldEntity* worldEntity)
     413{
     414  GenericNPC::Anim anim;
     415  anim.entity = worldEntity;
     416  anim.type = LookAt;
     417
     418  if( this->behaviourList.empty())
     419  {
     420    this->behaviourList.push_back(anim);
     421    this->initNPC();
     422  }
     423  else
     424    this->behaviourList.push_back(anim);
     425}
     426
    453427
    454428
     
    459433 * @param dialogNr: sound nr to be played (from the xml load tags)
    460434 */
    461 float GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
     435void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
    462436{}
    463437
     
    483457 * @param time: time in seconds expirded since the last tick
    484458 */
    485 void GenericNPC::tick (float time)
     459void GenericNPC::tick (float dt)
    486460{
    487461  if( likely(this->getModel(0) != NULL))
    488     ((InteractiveModel*)this->getModel(0))->tick(time);
     462    ((InteractiveModel*)this->getModel(0))->tick(dt);
     463
     464
     465  if (!this->behaviourList.empty())
     466  {
     467    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     468
     469    switch( currentAnimation.type)
     470    {
     471      case Walk:
     472        {
     473          Vector dest = currentAnimation.v - this->getAbsCoor();
     474          if (dest.len() < .5)
     475            this->nextStep();
     476          else
     477          {
     478            dest.y = 0.0f;
     479            this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     480
     481          }
     482        }
     483        break;
     484
     485      case Run:
     486      {
     487        Vector dest = currentAnimation.v - this->getAbsCoor();
     488        if (dest.len() < .5)
     489          this->nextStep();
     490        else
     491        {
     492          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     493        }
     494      }
     495      break;
     496
     497      case Crouch:
     498      {
     499        Vector dest = currentAnimation.v - this->getAbsCoor();
     500        if (dest.len() < .5)
     501          this->nextStep();
     502        else
     503        {
     504          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     505        }
     506      }
     507      break;
     508
     509      case TurnTo:
     510        //Quaternion direction = this->
     511        break;
     512
     513      case LookAt:
     514        break;
     515
     516      case Shoot:
     517        break;
     518
     519      default:
     520        break;
     521
     522    }
     523  }
     524
     525  // physical falling of the player
     526  if( !this->isOnGround())
     527  {
     528    this->fallVelocity += 300.0f * dt;
     529    velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
     530   // PRINTF(0)("%s is not on ground\n", this->getName());
     531  }
     532  else
     533  {
     534    this->fallVelocity = 0.0f;
     535  }
     536
     537  this->shiftCoor(Vector(0, -this->fallVelocity * dt,0));
    489538
    490539}
     
    495544{
    496545  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
     546
     547  this->setAnimationSpeed(1.0f);
    497548
    498549  if( randi == 1)
  • trunk/src/world_entities/npcs/generic_npc.h

    r8894 r9003  
    1010#include "npc.h"
    1111
    12 #include <string>
    1312
    1413#include "sound_source.h"
    15 
    16 #include "vector.h"
    17 #include "quaternion.h"
    18 
    1914
    2015namespace OrxSound{ class SoundSource; }
     
    2722class GenericNPC : public NPC
    2823{
     24
     25
    2926 public:
    30   GenericNPC();
    31   GenericNPC(const TiXmlElement* root);
     27  GenericNPC(const TiXmlElement* root = NULL);
    3228  virtual ~GenericNPC ();
    3329
    34   void init();
    3530  virtual void loadParams(const TiXmlElement* root);
    3631
    37   void setAnimation(int animationIndex, int animPlaybackMode);
    3832  /** sets the sound volume to @param vol: volume of the sound */
    3933  inline void setVolume(float vol) { this->soundVolume = vol; }
    4034
    4135
    42   /* npc controlling functions */
    4336
     37  bool finalGoalReached() { return this->behaviourList.empty(); };
     38
     39  /* npc controlling functions to be Queued */
    4440  /* walking functions */
    45   float walkTo(const Vector& coordinate, const Quaternion& dir);
    46   float walkTo(float x, float y, float z);
    47   float walkTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    48   float walkTo(float x, float y, float qu, float qx, float qy, float qz);
     41  void walkTo(const Vector& coordinate);
     42  void walkTo(float x, float y, float z);
    4943
    5044  /* running functions */
    51   float runTo(const Vector& coordinate, const Quaternion& dir);
    52   float runTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    53   float runTo(float x, float y, float qu, float qx, float qy, float qz);
     45  void runTo(const Vector& coordinate);
     46  void runTo(float x, float y, float z);
    5447
    5548  /* couching functinos */
    56   float crouchTo(const Vector& coordinate, const Quaternion& dir);
    57   float crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    58   float crouchTo(float x, float y, float qu, float qx, float qy, float qz);
     49  void crouchTo(const Vector& coordinate);
     50  void crouchTo(float x, float y, float z);
    5951
    6052  /* stopping the movement */
    6153  void stop();
     54  void nextStep();
    6255
    6356  /* some oriantation functions */
    64   float lookAt(WorldEntity* worldEntity);
    65   bool turnTo(float qu, float qx, float qy, float qz);
     57  void lookAt(WorldEntity* worldEntity);
     58  void turnTo(float qu, float qx, float qy, float qz);
     59  void turnTo(float degreeInY);
    6660
    6761  /* talking funcitons*/
    68   float talkTo(WorldEntity* worldEntity, int dialogNr);
     62  void talkTo(WorldEntity* worldEntity, int dialogNr);
    6963
    7064  /* shooting functions */
     
    7771  void playSound(int i);
    7872
    79   void setTime(float newTime){ this->time = newTime; };
    80  
    8173  virtual void tick (float time);
    8274
     
    8476  void destroy();
    8577
     78  private:
     79    void init();
     80
     81    void setAnimation(int animationIndex, int animPlaybackMode);
     82    int getAnimation();
     83    bool isAnimationFinished();
     84    void setAnimationSpeed(float speed);
     85
     86    void initNPC();
     87
    8688
    8789 private:
     90
     91   typedef enum {
     92    Walk,
     93    Run,
     94    Crouch,
     95    Jump,
     96    TurnTo,
     97    LookAt,
     98    TalkTo,
     99
     100    Shoot,
     101
     102
     103   } AnimType;
     104
     105   typedef struct Anim
     106   {
     107     Vector        v;
     108     Quaternion    q;
     109
     110
     111     WorldEntity*  entity;
     112     float         speed;
     113
     114
     115     AnimType      type;
     116   };
     117   typedef std::list<GenericNPC::Anim>     genNPCAnimList;
     118
     119
     120
    88121   OrxSound::SoundSource                   soundSource;
    89122   OrxSound::SoundBuffer*                  soundBuffer;
    90123   float                                   soundVolume;
    91124
     125   std::list<GenericNPC::Anim>             behaviourList;
    92126   Vector                                  destCoor;
    93127   Quaternion                              destDir;
     
    95129   Animation3D*                            currentAnim;
    96130   float                                   time;          //!< Duration of the action
     131   float                                   fallVelocity;
    97132};
    98133
  • trunk/src/world_entities/npcs/npc.cc

    r8894 r9003  
    2929
    3030  this->toList(OM_GROUP_00);
     31
    3132}
    3233
  • trunk/src/world_entities/script_trigger.cc

    r8894 r9003  
    1414*/
    1515
    16 
    1716#include "script_trigger.h"
    1817#include "class_list.h"
     
    2322
    2423CREATE_SCRIPTABLE_CLASS(ScriptTrigger, CL_SCRIPT_TRIGGER,
    25                             addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    26                             ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    27                             ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
    28                             ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     24                          //Position
     25                     addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
     26                     ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
     27                     ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     28                     ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     29                     //Set values
     30                    // ->addMethod("setTarget", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTarget))
     31                    // ->addMethod("setTriggerParent", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTriggerParent))
     32                     ->addMethod("setTriggerLasts", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setTriggerLasts))
     33                     ->addMethod("setInvert", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert))
     34                     ->addMethod("setRadius", ExecutorLua1<ScriptTrigger, float >(&ScriptTrigger::setRadius))
     35                     //->addMethod("setScript", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setScript))
     36                     //->addMethod("setFunction", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setFunction))
     37                     ->addMethod("setDebugDraw", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert))
    2938                       );
    3039
     
    92101    LoadParam(root, "radius", this, ScriptTrigger, setRadius)
    93102        .describe("the fileName of the script, that should be triggered by this script trigger")
    94         .defaultValues(0);
    95     LoadParam(root, "delay", this, ScriptTrigger, setDelay)
    96         .describe("the delay after which the funtion sould be triggered")
    97103        .defaultValues(0);
    98104    LoadParam(root, "worldentity", this, ScriptTrigger, setTarget)
  • trunk/src/world_entities/script_trigger.h

    r8894 r9003  
    3838    void setInvert(const bool inv) { this->invert = invert; }
    3939    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    40     void setDelay(const float time){if(delay>0) this->delay = delay; }
    4140    void setScript(const std::string& file);
    4241    void setFunction(const std::string& function){ this->functionName = function;}
  • trunk/src/world_entities/test_entity.cc

    r8778 r9003  
    3737
    3838CREATE_FACTORY(TestEntity, CL_TEST_ENTITY);
     39
     40#include "script_class.h"
     41CREATE_SCRIPTABLE_CLASS(TestEntity, CL_TEST_ENTITY,
     42                            addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
     43                            ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
     44                            ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     45                            ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     46                           
     47                       );
    3948
    4049
  • trunk/src/world_entities/weapons/fps_sniper_rifle.cc

    r8894 r9003  
    6767{
    6868  // model will be deleted from WorldEntity-destructor
     69  if( this->material != NULL)
     70    delete this->material;
    6971}
    7072
     
    7476  this->setClassID(CL_FPS_SNIPER_RIFLE, "FPSSniperRifle");
    7577
    76   this->loadModel("models/guns/fps_sniper_rifle.obj", 0.1);
     78  this->loadModel("models/guns/fps_sniper_rifle.obj", 0.2);
     79  this->material = new Material();
     80  this->material->setIllum(3);
     81  this->material->setAmbient(1.0, 1.0, 1.0);
     82  this->material->setDiffuseMap("maps/rifle01tex.jpg");
    7783
    7884  this->setStateDuration(WS_SHOOTING, .1);
     
    149155
    150156
     157
     158
     159/**
     160 *  this will draw the weapon
     161 */
     162void FPSSniperRifle::draw () const
     163{
     164  /* draw gun body */
     165  glMatrixMode(GL_MODELVIEW);
     166  glPushMatrix();
     167  glTranslatef (this->getAbsCoor ().x,
     168                this->getAbsCoor ().y,
     169                this->getAbsCoor ().z);
     170
     171  Vector tmpRot = this->getAbsDir().getSpacialAxis();
     172  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     173
     174  if( this->leftRight == W_RIGHT)
     175    glScalef(1.0, 1.0, -1.0);
     176
     177  this->material->select();
     178  static_cast<StaticModel*>(this->getModel())->draw();
     179
     180  glPopMatrix();
     181
     182}
     183
     184
     185
  • trunk/src/world_entities/weapons/fps_sniper_rifle.h

    r8894 r9003  
    3535
    3636
     37class Material;
     38
    3739class FPSSniperRifle : public Weapon
    3840  {
     
    5052    virtual void fire();
    5153
     54    virtual void draw() const;
     55
     56
    5257
    5358  private:
    54     int leftRight;   // this will become an enum
     59    int              leftRight;   //!< this will become an enum
     60    Material*        material;    //!< material
    5561
    5662  };
  • trunk/src/world_entities/world_entity.cc

    r8977 r9003  
    7272
    7373  this->objectListNumber = OM_INIT;
     74  this->lastObjectListNumber = OM_INIT;
    7475  this->objectListIterator = NULL;
    7576
     
    7879    this->collisionHandles[i] = NULL;
    7980  this->bReactive = false;
     81  this->bOnGround = false;
    8082
    8183  // registering default reactions:
     
    613615    }
    614616
    615     if( this->aabbNode != NULL)
    616       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
     617//     if( this->aabbNode != NULL)
     618//       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
    617619
    618620    glPopMatrix();
  • trunk/src/world_entities/world_entity.h

    r8974 r9003  
    9494  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
    9595
     96  /** @returns true if this entity is standing on ground (BSP model) */
     97  bool isOnGround() const { return this->bOnGround; }
     98  /** @param flag: marks if this entity is standing on ground */
     99  void setOnGround(bool flag) { this->bOnGround = flag; }
     100
    96101  virtual void hit(float damage);
    97102  virtual void destroy();
     
    117122
    118123  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
    119   void unhide() { this->toList(this->lastObjectListNumber); }
     124  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
    120125
    121126
     
    194199
    195200  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
    196 
     201  bool                    bOnGround;                       //!< true if this entity is standing on the ground
    197202
    198203  protected:
Note: See TracChangeset for help on using the changeset viewer.