Changeset 9656 in orxonox.OLD for trunk/src/world_entities/weapons
- Timestamp:
- Aug 4, 2006, 11:01:28 PM (18 years ago)
- Location:
- trunk/src/world_entities/weapons
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/weapons/aim.cc
r9406 r9656 50 50 Aim::~Aim () 51 51 { 52 if (this->material)53 delete this->material;54 55 52 /* if (this->text != NULL) 56 53 delete this->text;*/ … … 70 67 71 68 this->setBindNode(this); 72 this->material = new Material;73 69 this->source = NULL; 74 70 75 this->range = 1000 0;71 this->range = 1000; 76 72 this->angle = M_PI_4; 77 this-> group = OM_GROUP_01;73 this->targetGroup = OM_GROUP_01; 78 74 this->anim = new tAnimation<Aim>(this, &Aim::setSize); 79 75 this->anim->setInfinity(ANIM_INF_CONSTANT); … … 103 99 LoadParam(root, "rotation-speed", this, Aim, setRotationSpeed) 104 100 .describe("the Speed with which the Aim should rotate"); 101 102 LoadParam(root, "target-group", this, Aim, setTargetGroupS); 105 103 } 106 104 … … 108 106 { 109 107 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(); 113 111 entity ++) 114 112 { 115 113 diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() ); 116 114 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) 118 116 { 119 117 //if (this->getParent() != (*entity)) 120 118 { 119 printf("found target::: %d %s::%s\n", (*entity)->getOMListNumber(), (*entity)->getClassCName(), (*entity)->getCName()); 121 120 this->anim->replay(); 122 121 this->setParentSoft(*entity, 5); … … 128 127 //if no target found: 129 128 this->setParent(PNode::getNullParent()); 130 131 132 133 } 134 129 } 130 131 void 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 } 135 139 136 140 /** … … 149 153 void Aim::setTexture(const std::string& textureFile) 150 154 { 151 this->material ->setDiffuseMap(textureFile);155 this->material.setDiffuseMap(textureFile); 152 156 } 153 157 … … 170 174 //only look for target if the aim hasn`t locked a target yet or if the actual target is out of range 171 175 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)) 174 178 { 175 179 this->setParentSoft(PNode::getNullParent(),5); … … 213 217 214 218 glRotatef(this->getAbsDir2D(), 0,0,1); 215 this->material ->select();219 this->material.select(); 216 220 glBegin(GL_TRIANGLE_STRIP); 217 221 glTexCoord2f(0, 0); -
trunk/src/world_entities/weapons/aim.h
r7221 r9656 11 11 #include "object_manager.h" 12 12 13 #include "material.h" 14 13 15 // FORWARD DECLARATION 14 16 class Model; 15 17 class Text; 16 class Material;17 18 class TiXmlElement; 18 19 template<class T> class tAnimation; … … 25 26 * Also the Aim is a Element2D, as it draws a cross onto the Target. 26 27 */ 27 class Aim : public PNode, public Element2D { 28 class Aim : public PNode, public Element2D 29 { 28 30 29 31 public: 30 32 Aim(PNode* source, const TiXmlElement* root = NULL); 31 33 virtual ~Aim(); 32 34 33 void init();34 35 virtual void loadParams(const TiXmlElement* root); 35 36 … … 37 38 38 39 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(); }; 40 41 41 42 void searchTarget(); 42 43 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); 46 48 47 49 void setSize(float size); … … 53 55 virtual void draw() const; 54 56 55 private: 56 Material* material; //!< a material for the Aim. 57 float rotationSpeed; //!< Speed of the Rotation. 58 tAnimation<Aim>* anim; 57 private: 58 void init(); 59 59 60 float range; //!<61 float angle; //!<62 Vector diffVec;63 OM_LIST group;64 60 65 PNode* source; //!< Where this Shot has come from. 61 private: 62 Material material; //!< a material for the Aim. 63 float rotationSpeed; //!< Speed of the Rotation. 64 tAnimation<Aim>* anim; 66 65 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) 68 74 }; 69 75 -
trunk/src/world_entities/weapons/aiming_turret.cc
r9406 r9656 38 38 */ 39 39 AimingTurret::AimingTurret () 40 : Weapon()40 : Weapon(), target(this) 41 41 { 42 42 this->init(); … … 46 46 47 47 AimingTurret::AimingTurret(const TiXmlElement* root) 48 : target(this) 48 49 { 49 50 this->init(); … … 58 59 { 59 60 // model will be deleted from WorldEntity-destructor 60 // delete this->target;61 // delete this->target; 61 62 } 62 63 … … 91 92 //this->getProjectileFactory()->prepare(100); 92 93 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); 97 98 98 99 this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav"); … … 110 111 void AimingTurret::activate() 111 112 { 112 this->target ->setVisibility(true);113 this->target.setVisibility(true); 113 114 } 114 115 115 116 void AimingTurret::deactivate() 116 117 { 117 this->target ->setVisibility(false);118 this->target.setVisibility(false); 118 119 } 119 120 … … 123 124 return; 124 125 Quaternion quat; 125 Vector direction = this->target ->getAbsCoor() - this->getAbsCoor();126 Vector direction = this->target.getAbsCoor() - this->getAbsCoor(); 126 127 127 128 direction.normalize(); 128 129 129 130 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()); 131 133 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)); 133 136 134 137 this->setAbsDirSoft(quat, 5); 135 138 136 this->target ->tick(dt);139 this->target.tick(dt); 137 140 } 138 141 … … 143 146 return; 144 147 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()); 147 150 148 151 pj->setParent(PNode::getNullParent()); -
trunk/src/world_entities/weapons/aiming_turret.h
r8777 r9656 8 8 9 9 #include "weapon.h" 10 10 #include "aim.h" 11 11 /* FORWARD DECLARATION */ 12 class Aim;13 12 14 13 class AimingTurret : public Weapon 15 16 17 18 19 14 { 15 public: 16 AimingTurret (); 17 AimingTurret(const TiXmlElement* root); 18 virtual ~AimingTurret (); 20 19 21 void init(); 22 virtual void loadParams(const TiXmlElement* root); 20 virtual void loadParams(const TiXmlElement* root); 23 21 24 virtual void activate(); 25 virtual void deactivate(); 22 void setTargetGroup(OM_LIST targetGroup) { this->target.setTargetGroup(targetGroup); }; 26 23 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(); 29 29 30 30 31 31 virtual void draw() const; 32 32 33 private: 34 Aim* target; 35 }; 33 private: 34 void init(); 35 36 private: 37 Aim target; 38 }; 36 39 37 40 #endif /* _AIMING_TURRET_H */ -
trunk/src/world_entities/weapons/laser_cannon.cc
r9235 r9656 121 121 return; 122 122 123 // make this to let the onKill(...) fuction get the stuff 124 pj->setOwner(this->getOwner()); 125 123 126 pj->setParent(PNode::getNullParent()); 124 127 -
trunk/src/world_entities/weapons/targeting_turret.cc
r9406 r9656 17 17 #include "targeting_turret.h" 18 18 19 #include "weapon_manager.h" 20 #include "aim.h" 21 #include "world_entities/projectiles/projectile.h" 19 #include "projectiles/projectile.h" 22 20 23 21 #include "model.h" … … 25 23 #include "animation3d.h" 26 24 25 #include "util/loading/load_param.h" 27 26 #include "util/loading/factory.h" 28 27 … … 30 29 31 30 32 33 34 /**35 * standard constructor36 37 creates a new weapon38 */39 TargetingTurret::TargetingTurret ()40 : Weapon()41 {42 this->init();43 44 }45 46 47 31 TargetingTurret::TargetingTurret(const TiXmlElement* root) 32 : target(this) 48 33 { 49 34 this->init(); … … 91 76 //this->getProjectileFactory()->prepare(100); 92 77 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; 98 83 99 84 this->lockedTime = 0; … … 112 97 Weapon::loadParams(root); 113 98 99 LoadParam(root, "target-group", &target, Aim, setTargetGroupS); 100 114 101 } 115 102 … … 122 109 void TargetingTurret::deactivate() 123 110 { 124 this->target ->setVisibility(false);111 this->target.setVisibility(false); 125 112 } 126 113 … … 130 117 return; 131 118 119 this->target.tick(dt); 120 132 121 if( lockedTime >= neededLockTime ) 133 122 { 134 lockedTarget = this->target ->getParent();123 lockedTarget = this->target.getParent(); 135 124 lockedTime = 0; 136 125 } 137 126 138 this->target->tick(dt);139 127 140 if(this->target ->getParent() == PNode::getNullParent())128 if(this->target.getParent() == PNode::getNullParent()) 141 129 lockedTime = 0; 142 130 else … … 159 147 pj->setAbsDir(this->getAbsDir()); 160 148 pj->activate(); 161 162 149 } 163 150 -
trunk/src/world_entities/weapons/targeting_turret.h
r8777 r9656 8 8 9 9 #include "weapon.h" 10 11 /* FORWARD DECLARATION */ 12 class Aim; 10 #include "aim.h" 13 11 14 12 class TargetingTurret : public Weapon 15 { 16 public: 17 TargetingTurret (); 18 TargetingTurret(const TiXmlElement* root); 19 virtual ~TargetingTurret (); 13 { 14 public: 15 TargetingTurret(const TiXmlElement* root = NULL); 16 virtual ~TargetingTurret (); 20 17 21 void init(); 22 virtual void loadParams(const TiXmlElement* root); 18 virtual void loadParams(const TiXmlElement* root); 23 19 24 25 20 virtual void activate(); 21 virtual void deactivate(); 26 22 27 28 23 virtual void tick(float dt); 24 virtual void fire(); 29 25 30 26 virtual void draw() const; 31 27 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 31 private: 32 void init(); 33 34 private: 35 Aim target; 36 PNode* lockedTarget; 37 float lockedTime; 38 float neededLockTime; 39 }; 38 40 39 41 #endif /* _TARGETING_TURRET_H */ -
trunk/src/world_entities/weapons/test_gun.cc
r9002 r9656 177 177 if (pj == NULL) 178 178 return; 179 180 // set the owner 181 pj->setOwner(this->getOwner()); 179 182 180 183 pj->setParent(PNode::getNullParent());
Note: See TracChangeset
for help on using the changeset viewer.