- Timestamp:
- Oct 30, 2008, 11:58:31 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc
r2029 r2069 54 54 55 55 XMLPortParam(DistanceTrigger, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(100.0f); 56 XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode) ;56 XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode).defaultValues("ControllableEntity"); 57 57 } 58 58 … … 81 81 { 82 82 Identifier* targetId = ClassByString(targets); 83 targetMask_.include(targetId); 83 if (!targetId) 84 return; 85 86 this->targetMask_.include(targetId); 87 84 88 // trigger shouldn't react on itself or other triggers 85 t argetMask_.exclude(Class(Trigger), true);89 this->targetMask_.exclude(Class(Trigger), true); 86 90 91 // we only want WorldEntities 92 ClassTreeMask WEMask; 93 WEMask.include(Class(WorldEntity)); 94 this->targetMask_ *= WEMask; 87 95 } 88 96 … … 90 98 { 91 99 Identifier* targetId = ClassByString(targets); 92 t argetMask_.exclude(targetId);100 this->targetMask_.exclude(targetId); 93 101 } 94 102 95 103 bool DistanceTrigger::checkDistance() 96 104 { 97 // Iterate through all WorldEntities98 for ( Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; ++it)105 // Iterate through all objects 106 for (ClassTreeMaskObjectIterator it = this->targetMask_.begin(); it != this->targetMask_.end(); ++it) 99 107 { 100 // check if WorldEntity is a target101 if ( targetMask_.isIncluded(it->getIdentifier()))102 {103 Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition(); 104 if (distanceVec.length() < this->distance_)105 return true;106 }108 WorldEntity* entity = dynamic_cast<WorldEntity*>(*it); 109 if (!entity) 110 continue; 111 112 Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition(); 113 if (distanceVec.length() < this->distance_) 114 return true; 107 115 } 108 116 return false; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc
r2065 r2069 50 50 this->mode_ = TM_EventTriggerAND; 51 51 52 this->bFirstTick_ = true; 52 53 this->bActive_ = false; 53 54 this->bTriggered_ = false; … … 92 93 void Trigger::tick(float dt) 93 94 { 94 95 bool newTriggered = this->isTriggered(); 95 if (this->bFirstTick_) 96 { 97 this->bFirstTick_ = false; 98 this->fireEvent(false); 99 } 100 101 bool newTriggered = this->isTriggered() ^ this->bInvertMode_; 96 102 97 103 // check if new triggering event is really new … … 173 179 // this->bUpdating_ = false; 174 180 175 if (this->bInvertMode_) 176 return !returnval; 177 else 178 return returnval; 181 return returnval; 179 182 } 180 183 return true; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.h
r2029 r2069 35 35 #include "OrxonoxPrereqs.h" 36 36 37 #include "objects/Tickable.h" 37 38 #include "objects/worldentities/PositionableEntity.h" 38 39 #include "tools/BillboardSet.h" … … 47 48 }; 48 49 49 class _OrxonoxExport Trigger : public PositionableEntity 50 class _OrxonoxExport Trigger : public PositionableEntity, public Tickable 50 51 { 51 52 public: … … 111 112 bool bActive_; 112 113 bool bTriggered_; 114 bool bFirstTick_; 113 115 114 116 TriggerMode mode_;
Note: See TracChangeset
for help on using the changeset viewer.