Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9656 in orxonox.OLD for trunk/src/world_entities/weapons


Ignore:
Timestamp:
Aug 4, 2006, 11:01:28 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy bache back with no conflicts

Location:
trunk/src/world_entities/weapons
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/weapons/aim.cc

    r9406 r9656  
    5050Aim::~Aim ()
    5151{
    52   if (this->material)
    53     delete this->material;
    54 
    5552/*  if (this->text != NULL)
    5653    delete this->text;*/
     
    7067
    7168  this->setBindNode(this);
    72   this->material = new Material;
    7369  this->source = NULL;
    7470
    75   this->range = 10000;
     71  this->range = 1000;
    7672  this->angle = M_PI_4;
    77   this->group = OM_GROUP_01;
     73  this->targetGroup = OM_GROUP_01;
    7874  this->anim = new tAnimation<Aim>(this, &Aim::setSize);
    7975  this->anim->setInfinity(ANIM_INF_CONSTANT);
     
    10399  LoadParam(root, "rotation-speed", this, Aim, setRotationSpeed)
    104100      .describe("the Speed with which the Aim should rotate");
     101
     102  LoadParam(root, "target-group", this, Aim, setTargetGroupS);
    105103}
    106104
     
    108106{
    109107  ObjectManager::EntityList::iterator entity;
    110 
    111   for (entity = State::getObjectManager()->getObjectList(group).begin();
    112        entity != State::getObjectManager()->getObjectList(group).end();
     108  //printf("%d\n", this->targetGroup);
     109  for (entity = State::getObjectManager()->getObjectList(this->targetGroup).begin();
     110       entity != State::getObjectManager()->getObjectList(this->targetGroup).end();
    113111       entity ++)
    114112  {
    115113    diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() );
    116114
    117     if ( diffVec.len() < range &&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) )  < angle)
     115    if ( diffVec.len() < range )//&&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) )  < angle)
    118116    {
    119117      //if (this->getParent() != (*entity))
    120118      {
     119        printf("found target::: %d %s::%s\n", (*entity)->getOMListNumber(), (*entity)->getClassCName(), (*entity)->getCName());
    121120        this->anim->replay();
    122121        this->setParentSoft(*entity, 5);
     
    128127   //if no target found:
    129128   this->setParent(PNode::getNullParent());
    130 
    131 
    132 
    133 }
    134 
     129}
     130
     131void Aim::setTargetGroupS(const std::string& groupName)
     132{
     133  OM_LIST id = ObjectManager::StringToOMList(groupName);
     134  if (id != OM_NULL)
     135    this->setTargetGroup(id);
     136  else
     137    PRINTF(2)("List %s not found for targetting\n", groupName.c_str());
     138}
    135139
    136140/**
     
    149153void Aim::setTexture(const std::string& textureFile)
    150154{
    151   this->material->setDiffuseMap(textureFile);
     155  this->material.setDiffuseMap(textureFile);
    152156}
    153157
     
    170174//only look for target if the aim hasn`t locked a target yet or if the actual target is out of range
    171175   if(this->getParent() == PNode::getNullParent() ||
    172       diffVec.len() > range ||
    173      ( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle))
     176      diffVec.len() > range )// ||
     177     //( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle))
    174178    {
    175179     this->setParentSoft(PNode::getNullParent(),5);
     
    213217
    214218  glRotatef(this->getAbsDir2D(), 0,0,1);
    215   this->material->select();
     219  this->material.select();
    216220  glBegin(GL_TRIANGLE_STRIP);
    217221  glTexCoord2f(0, 0);
  • trunk/src/world_entities/weapons/aim.h

    r7221 r9656  
    1111#include "object_manager.h"
    1212
     13#include "material.h"
     14
    1315// FORWARD DECLARATION
    1416class Model;
    1517class Text;
    16 class Material;
    1718class TiXmlElement;
    1819template<class T> class tAnimation;
     
    2526 * Also the Aim is a Element2D, as it draws a cross onto the Target.
    2627 */
    27 class Aim : public PNode, public Element2D {
     28class Aim : public PNode, public Element2D
     29{
    2830
    29  public:
     31public:
    3032  Aim(PNode* source, const TiXmlElement* root = NULL);
    3133  virtual ~Aim();
    3234
    33   void init();
    3435  virtual void loadParams(const TiXmlElement* root);
    3536
     
    3738
    3839  inline void selectTarget(PNode* target) { this->setParent(target); };
    39   inline PNode* getTarget(PNode* target) { return this->getParent(); };
     40  inline PNode* getTarget(PNode* target) const { return this->getParent(); };
    4041
    4142  void searchTarget();
    4243
    43   void setRange(float range){this->range = range;};
    44   void setAngle(float angle){this->angle = angle;};
    45   void setGroup(OM_LIST group){this->group = group;};
     44  void setRange(float range) {this->range = range;};
     45  void setAngle(float angle) {this->angle = angle;};
     46  void setTargetGroup(OM_LIST group) { this->targetGroup = group; };
     47  void setTargetGroupS(const std::string& grounName);
    4648
    4749  void setSize(float size);
     
    5355  virtual void draw() const;
    5456
    55  private:
    56    Material*        material;             //!< a material for the Aim.
    57    float            rotationSpeed;        //!< Speed of the Rotation.
    58    tAnimation<Aim>* anim;
     57private:
     58  void init();
    5959
    60    float            range;                //!<
    61    float            angle;                //!<
    62    Vector           diffVec;
    63    OM_LIST          group;
    6460
    65    PNode*           source;               //!< Where this Shot has come from.
     61private:
     62  Material         material;             //!< a material for the Aim.
     63  float            rotationSpeed;        //!< Speed of the Rotation.
     64  tAnimation<Aim>* anim;
    6665
    67    Text*            text;                 //!< A Text to display onto this Node. (distance to Target)
     66  float            range;                //!<
     67  float            angle;                //!<
     68  Vector           diffVec;
     69  OM_LIST          targetGroup;
     70
     71  PNode*           source;               //!< Where this Shot has come from.
     72
     73  //   Text             text;                 //!< A Text to display onto this Node. (distance to Target)
    6874};
    6975
  • trunk/src/world_entities/weapons/aiming_turret.cc

    r9406 r9656  
    3838*/
    3939AimingTurret::AimingTurret ()
    40   : Weapon()
     40    : Weapon(), target(this)
    4141{
    4242  this->init();
     
    4646
    4747AimingTurret::AimingTurret(const TiXmlElement* root)
     48    : target(this)
    4849{
    4950  this->init();
     
    5859{
    5960  // model will be deleted from WorldEntity-destructor
    60 //  delete this->target;
     61  //  delete this->target;
    6162}
    6263
     
    9192  //this->getProjectileFactory()->prepare(100);
    9293
    93   this->target = new Aim(this);
    94   this->target->setVisibility(false);
    95   this->target->setRange(400);
    96   this->target->setAngle(M_PI_2);
     94  this->target.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | PNODE_PROHIBIT_CHILD_DELETE);
     95  this->target.setVisibility(false);
     96  this->target.setRange(400);
     97  this->target.setAngle(M_PI_2);
    9798
    9899  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav");
     
    110111void AimingTurret::activate()
    111112{
    112   this->target->setVisibility(true);
     113  this->target.setVisibility(true);
    113114}
    114115
    115116void AimingTurret::deactivate()
    116117{
    117   this->target->setVisibility(false);
     118  this->target.setVisibility(false);
    118119}
    119120
     
    123124    return;
    124125  Quaternion quat;
    125   Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
     126  Vector direction = this->target.getAbsCoor() - this->getAbsCoor();
    126127
    127128  direction.normalize();
    128129
    129130  if (likely (this->getParent() != NULL))
    130     quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
     131    //quat = Quaternion(direction, this->getParent()->getAbsDirY()) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
     132    quat = Quaternion ( M_PI_2, this->getParent()->getAbsDirY()) * Quaternion::lookAt(this->getAbsCoor(), this->target.getAbsCoor(), this->getParent()->getAbsDirY());
    131133  else
    132     quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
     134    //quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
     135    quat = Quaternion ( M_PI_2, Vector(0,1,0)) * Quaternion::lookAt(this->getAbsCoor(), this->target.getAbsCoor(), Vector(0,1,0));
    133136
    134137  this->setAbsDirSoft(quat, 5);
    135138
    136   this->target->tick(dt);
     139  this->target.tick(dt);
    137140}
    138141
     
    143146    return;
    144147
    145   pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
    146             /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
     148  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDirX()*250.0 + VECTOR_RAND(4)
     149                                          /*target.getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
    147150
    148151  pj->setParent(PNode::getNullParent());
  • trunk/src/world_entities/weapons/aiming_turret.h

    r8777 r9656  
    88
    99#include "weapon.h"
    10 
     10#include "aim.h"
    1111/* FORWARD DECLARATION */
    12 class Aim;
    1312
    1413class AimingTurret : public Weapon
    15   {
    16   public:
    17     AimingTurret ();
    18     AimingTurret(const TiXmlElement* root);
    19     virtual ~AimingTurret ();
     14{
     15public:
     16  AimingTurret ();
     17  AimingTurret(const TiXmlElement* root);
     18  virtual ~AimingTurret ();
    2019
    21     void init();
    22     virtual void loadParams(const TiXmlElement* root);
     20  virtual void loadParams(const TiXmlElement* root);
    2321
    24     virtual void activate();
    25     virtual void deactivate();
     22  void setTargetGroup(OM_LIST targetGroup) { this->target.setTargetGroup(targetGroup); };
    2623
    27     virtual void tick(float dt);
    28     virtual void fire();
     24  virtual void activate();
     25  virtual void deactivate();
     26
     27  virtual void tick(float dt);
     28  virtual void fire();
    2929
    3030
    31     virtual void draw() const;
     31  virtual void draw() const;
    3232
    33   private:
    34     Aim*          target;
    35   };
     33private:
     34  void init();
     35
     36private:
     37  Aim           target;
     38};
    3639
    3740#endif /* _AIMING_TURRET_H */
  • trunk/src/world_entities/weapons/laser_cannon.cc

    r9235 r9656  
    121121    return;
    122122
     123  // make this to let the onKill(...) fuction get the stuff
     124  pj->setOwner(this->getOwner());
     125
    123126  pj->setParent(PNode::getNullParent());
    124127
  • trunk/src/world_entities/weapons/targeting_turret.cc

    r9406 r9656  
    1717#include "targeting_turret.h"
    1818
    19 #include "weapon_manager.h"
    20 #include "aim.h"
    21 #include "world_entities/projectiles/projectile.h"
     19#include "projectiles/projectile.h"
    2220
    2321#include "model.h"
     
    2523#include "animation3d.h"
    2624
     25#include "util/loading/load_param.h"
    2726#include "util/loading/factory.h"
    2827
     
    3029
    3130
    32 
    33 
    34 /**
    35  *  standard constructor
    36 
    37    creates a new weapon
    38 */
    39 TargetingTurret::TargetingTurret ()
    40   : Weapon()
    41 {
    42   this->init();
    43 
    44 }
    45 
    46 
    4731TargetingTurret::TargetingTurret(const TiXmlElement* root)
     32  : target(this)
    4833{
    4934  this->init();
     
    9176  //this->getProjectileFactory()->prepare(100);
    9277
    93   this->target = new Aim(this);
    94   this->target->setVisibility(false);
    95   this->target->setRange(1000);
    96   this->target->setAngle(M_PI_4);
    97   this->lockedTarget = this->target;
     78  this->target.setVisibility(false);
     79  this->target.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | PNODE_PROHIBIT_CHILD_DELETE);
     80  this->target.setRange(1000);
     81  this->target.setAngle(M_PI_4);
     82  this->lockedTarget = &this->target;
    9883
    9984  this->lockedTime = 0;
     
    11297  Weapon::loadParams(root);
    11398
     99  LoadParam(root, "target-group", &target, Aim, setTargetGroupS);
     100
    114101}
    115102
     
    122109void TargetingTurret::deactivate()
    123110{
    124   this->target->setVisibility(false);
     111  this->target.setVisibility(false);
    125112}
    126113
     
    130117    return;
    131118
     119  this->target.tick(dt);
     120
    132121  if( lockedTime >= neededLockTime )
    133122   {
    134     lockedTarget = this->target->getParent();
     123    lockedTarget = this->target.getParent();
    135124    lockedTime = 0;
    136125   }
    137126
    138   this->target->tick(dt);
    139127
    140   if(this->target->getParent() == PNode::getNullParent())
     128  if(this->target.getParent() == PNode::getNullParent())
    141129   lockedTime = 0;
    142130  else
     
    159147  pj->setAbsDir(this->getAbsDir());
    160148  pj->activate();
    161 
    162149}
    163150
  • trunk/src/world_entities/weapons/targeting_turret.h

    r8777 r9656  
    88
    99#include "weapon.h"
    10 
    11 /* FORWARD DECLARATION */
    12 class Aim;
     10#include "aim.h"
    1311
    1412class TargetingTurret : public Weapon
    15   {
    16   public:
    17     TargetingTurret ();
    18     TargetingTurret(const TiXmlElement* root);
    19     virtual ~TargetingTurret ();
     13{
     14public:
     15  TargetingTurret(const TiXmlElement* root = NULL);
     16  virtual ~TargetingTurret ();
    2017
    21     void init();
    22     virtual void loadParams(const TiXmlElement* root);
     18  virtual void loadParams(const TiXmlElement* root);
    2319
    24     virtual void activate();
    25     virtual void deactivate();
     20  virtual void activate();
     21  virtual void deactivate();
    2622
    27     virtual void tick(float dt);
    28     virtual void fire();
     23  virtual void tick(float dt);
     24  virtual void fire();
    2925
    30     virtual void draw() const;
     26  virtual void draw() const;
    3127
    32   private:
    33     Aim*           target;
    34     PNode*         lockedTarget;
    35     float          lockedTime;
    36     float          neededLockTime;
    37   };
     28  void setTargetGroup(OM_LIST targetGroup) { this->target.setTargetGroup(targetGroup); };
     29  const PNode* getLockedTarget() const { return lockedTarget; };
     30
     31private:
     32  void init();
     33
     34private:
     35  Aim            target;
     36  PNode*         lockedTarget;
     37  float          lockedTime;
     38  float          neededLockTime;
     39};
    3840
    3941#endif /* _TARGETING_TURRET_H */
  • trunk/src/world_entities/weapons/test_gun.cc

    r9002 r9656  
    177177  if (pj == NULL)
    178178    return;
     179
     180  // set the owner
     181  pj->setOwner(this->getOwner());
    179182
    180183  pj->setParent(PNode::getNullParent());
Note: See TracChangeset for help on using the changeset viewer.