Changeset 7677 for code/trunk/src/modules
- Timestamp:
- Nov 26, 2010, 1:25:56 PM (14 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/ForceField.cc
r7676 r7677 44 44 /*static*/ const std::string ForceField::modeTube_s = "tube"; 45 45 /*static*/ const std::string ForceField::modeSphere_s = "sphere"; 46 /*static*/ const std::string ForceField::modeInvertedSphere_s = "invertedSphere"; 46 47 47 48 /** … … 79 80 XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100); 80 81 XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500); 81 XMLPortParam(ForceField, "length" 82 XMLPortParam(ForceField, "length", setLength , getLength , xmlelement, mode).defaultValues(2000); 82 83 XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode); 83 84 } … … 102 103 103 104 // Vector from the center of the force field to the object its acting on. 104 // TODO: This could probably be simplified.105 105 Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction)); 106 106 107 // The object is outside of the lengthof the ForceField.107 // The object is outside a ball around the center with radius length/2 of the ForceField. 108 108 if(distanceVector.length() > this->halfLength_) 109 109 continue; … … 137 137 } 138 138 } 139 else if(this->mode_ == forceFieldMode::invertedSphere) 140 { 141 // Iterate over all objects that could possibly be affected by the ForceField. 142 for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it) 143 { 144 Vector3 distanceVector = this->getWorldPosition() - it->getWorldPosition(); 145 float distance = distanceVector.length(); 146 // If the object is within 'radius' distance and no more than 'length' away from the boundary of the sphere. 147 float range = this->radius_ - this->halfLength_*2; 148 if (distance < this->radius_ && distance > range) 149 { 150 distanceVector.normalise(); 151 // Apply a force proportional to the velocity, with highest force at the boundary of the sphere, linear decreasing until reaching a distance of 'radius-length' from the origin, where the force reaches zero. 152 it->applyCentralForce((distance-range)/range * this->velocity_ * distanceVector); 153 } 154 } 155 } 139 156 } 140 157 … … 151 168 else if(mode == ForceField::modeSphere_s) 152 169 this->mode_ = forceFieldMode::sphere; 170 else if(mode == ForceField::modeInvertedSphere_s) 171 this->mode_ = forceFieldMode::invertedSphere; 153 172 else 154 173 { … … 172 191 case forceFieldMode::sphere: 173 192 return ForceField::modeSphere_s; 193 case forceFieldMode::invertedSphere: 194 return ForceField::modeInvertedSphere_s; 174 195 default: 175 196 return ForceField::modeTube_s; -
code/trunk/src/modules/objects/ForceField.h
r7676 r7677 54 54 enum Value { 55 55 tube, //!< The ForceField has a tube shape. 56 sphere //!< The ForceField has a spherical shape. 56 sphere, //!< The ForceField has a spherical shape. 57 invertedSphere //!< The ForceField has a spherical shape but "inverted" behavior. 57 58 }; 58 59 } … … 67 68 - @b length The length of the ForceField. Default is 2000. 68 69 - @b mode The mode the ForceField is in. For mode: 69 - <em>tube</em> A ForceField which exerts force only in the direction it is oriented. The force is only exerted on objects that are in a tube of length <em>length</em> and diameter <em>diameter</em> . The magintude of the force is proportional to the <em>velocity</em>, being highest when an object is in the middle of the tube (radius-wise), linearly decreasing with greater radii and finally reaching zero, when the object is <code>diameter/2</code> away from the orientation vector.70 - <em>tube</em> A ForceField which exerts force only in the direction it is oriented. The force is only exerted on objects that are in a tube of length <em>length</em> and diameter <em>diameter</em> (with rounded start and end faces, so in fact the <em>length</em> parameter specifies a ball with <code>origin + length/2</code> as the center and <code>length/2</code> as the radius). The magintude of the force is proportional to the <em>velocity</em>, being highest when an object is in the middle of the tube (radius-wise), linearly decreasing with greater radii and finally reaching zero, when the object is <code>diameter/2</code> away from the orientation vector. 70 71 - <em>sphere</em> A Force Field which exerts force radially away from itself, with the greatest magnitude (proportional to <em>velocity</em>) being in the origin of the ForceField, linearly decreasing with respect to the distance to the origin and finally reaching zero at distance <code>diameter/2</code>. 71 72 Default is <em>tube</em>. 73 - <em>invertedSphere</em> 72 74 73 75 @author … … 134 136 static const std::string modeTube_s; 135 137 static const std::string modeSphere_s; 138 static const std::string modeInvertedSphere_s; 136 139 137 140 float velocity_; //!< The velocity of the ForceField.
Note: See TracChangeset
for help on using the changeset viewer.