Changeset 7674 for code/trunk/src/modules
- Timestamp:
- Nov 26, 2010, 12:01:53 AM (14 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/ForceField.cc
r7673 r7674 42 42 CreateFactory(ForceField); 43 43 44 /*static*/ const std::string modeStringNormal_s = "tube";45 /*static*/ const std::string modeStringSphere_s = "sphere";44 /*static*/ const std::string ForceField::modeTube_s = "tube"; 45 /*static*/ const std::string ForceField::modeSphere_s = "sphere"; 46 46 47 47 ForceField::ForceField(BaseObject* creator) : StaticEntity(creator) … … 54 54 this->diameter_ = 500; 55 55 this->length_ = 5000; 56 this->mode_ = ForceFieldMode::tube;56 this->mode_ = forceFieldMode::tube; 57 57 } 58 58 … … 70 70 XMLPortParam(ForceField, "length" , setLength , getLength , xmlelement, mode).defaultValues(2000); 71 71 XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode); 72 COUT(0) << "ForceField created " << this->velocity_ << " " << this->diameter_ << " " << this->radius_ << " " << this->length_ << " " << this->halfLength_ << " " << this->getMode() << std::endl; 72 73 } 73 74 74 75 void ForceField::tick(float dt) 75 76 { 76 // Iterate over all objects that could possibly be affected by the ForceField. 77 for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it) 77 if(this->mode_ == forceFieldMode::tube) 78 78 { 79 if(this->mode_ == ForceFieldMode::tube) 79 // Iterate over all objects that could possibly be affected by the ForceField. 80 for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it) 80 81 { 81 82 // The direction of the orientation of the force field. … … 89 90 // The object is outside of the length of the ForceField. 90 91 if(distanceVector.length() > this->halfLength_) 91 return;92 continue; 92 93 93 94 // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector) … … 96 97 // If the object in a tube of radius diameter/2 around the direction of orientation. 97 98 if(distanceFromDirectionVector >= this->radius_) 98 return;99 continue; 99 100 100 101 // Apply a force to the object in the direction of the orientation. 101 102 // The force is highest when the object is directly on the direction vector, with a linear decrease, finally reaching zero, when distanceFromDirectionVector = radius. 102 it->applyCentralForce(( (this->radius_ - distanceFromDirectionVector)/(this->radius_))* this->velocity_ * direction);103 it->applyCentralForce((this->radius_ - distanceFromDirectionVector)/this->radius_ * this->velocity_ * direction); 103 104 } 104 else if(this->mode_ == ForceFieldMode::sphere) 105 } 106 else if(this->mode_ == forceFieldMode::sphere) 107 { 108 // Iterate over all objects that could possibly be affected by the ForceField. 109 for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it) 105 110 { 106 111 Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition(); … … 117 122 void ForceField::setMode(const std::string& mode) 118 123 { 119 if(mode == ForceField::mode StringTube_s)120 this->mode_ = ForceFieldMode::tube;121 else if(mode == ForceField::modeS tringSphere_s)122 this->mode_ = ForceFieldMode::sphere;124 if(mode == ForceField::modeTube_s) 125 this->mode_ = forceFieldMode::tube; 126 else if(mode == ForceField::modeSphere_s) 127 this->mode_ = forceFieldMode::sphere; 123 128 else 124 129 { 125 130 COUT(2) << "Wrong mode '" << mode << "' in ForceField. Setting to 'tube'." << std::endl; 126 this->mode_ = ForceFieldMode::tube;131 this->mode_ = forceFieldMode::tube; 127 132 } 128 133 } … … 132 137 switch(this->mode_) 133 138 { 134 case ForceFieldMode::tube:135 return ForceField::mode StringTube_s;136 case ForceFieldMode::sphere:137 return ForceField::modeS tringSphere_s;139 case forceFieldMode::tube: 140 return ForceField::modeTube_s; 141 case forceFieldMode::sphere: 142 return ForceField::modeSphere_s; 138 143 default: 139 return ForceField::mode StringTube_s;144 return ForceField::modeTube_s; 140 145 } 141 146 } -
code/trunk/src/modules/objects/ForceField.h
r7673 r7674 56 56 @inGroup Objects 57 57 */ 58 namespace ForceFieldMode58 namespace forceFieldMode 59 59 { 60 60 enum Value { … … 116 116 117 117 private: 118 static const std::string mode StringTube_s;119 static const std::string modeS tringSphere_s;118 static const std::string modeTube_s; 119 static const std::string modeSphere_s; 120 120 121 121 float velocity_; … … 124 124 float length_; 125 125 float halfLength_; 126 ForceFieldMode::Value mode_;126 forceFieldMode::Value mode_; 127 127 }; 128 128 }
Note: See TracChangeset
for help on using the changeset viewer.