Changeset 7676 for code/trunk/src/modules/objects/ForceField.cc
- Timestamp:
- Nov 26, 2010, 8:44:48 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/ForceField.cc
r7674 r7676 28 28 29 29 /** 30 @file ForceField.cc31 @brief Implementation of the ForceField class.30 @file ForceField.cc 31 @brief Implementation of the ForceField class. 32 32 */ 33 33 … … 41 41 { 42 42 CreateFactory(ForceField); 43 43 44 44 /*static*/ const std::string ForceField::modeTube_s = "tube"; 45 45 /*static*/ const std::string ForceField::modeSphere_s = "sphere"; 46 46 47 /** 48 @brief 49 Constructor. Registers the object and initializes some values. 50 */ 47 51 ForceField::ForceField(BaseObject* creator) : StaticEntity(creator) 48 52 { … … 51 55 //Standard Values 52 56 this->setDirection(Vector3::ZERO); 53 this-> velocity_ = 100;54 this-> diameter_ = 500;55 this-> length_ = 5000;57 this->setVelocity(100); 58 this->setDiameter(500); 59 this->setLength(2000); 56 60 this->mode_ = forceFieldMode::tube; 57 61 } 58 62 63 /** 64 @brief 65 Destructor. 66 */ 59 67 ForceField::~ForceField() 60 68 { 61 69 } 62 70 71 /** 72 @brief 73 Creates a ForceField object through XML. 74 */ 63 75 void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode) 64 76 { 65 77 SUPER(ForceField, XMLPort, xmlelement, mode); 66 78 67 //For correct xml import use: position, direction, velocity, scale68 79 XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100); 69 80 XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500); 70 81 XMLPortParam(ForceField, "length" , setLength , getLength , xmlelement, mode).defaultValues(2000); 71 82 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;73 83 } 74 84 85 /** 86 @brief 87 A method that is called every tick. 88 Implements the behavior of teh ForceField. 89 @param dt 90 The amount of time that elapsed since the last tick. 91 */ 75 92 void ForceField::tick(float dt) 76 93 { … … 87 104 // TODO: This could probably be simplified. 88 105 Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction)); 89 106 90 107 // The object is outside of the length of the ForceField. 91 108 if(distanceVector.length() > this->halfLength_) … … 94 111 // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector) 95 112 float distanceFromDirectionVector = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(direction)).length(); 96 97 // If the object in a tube of radius diameter/2around the direction of orientation.113 114 // If the object in a tube of radius 'radius' around the direction of orientation. 98 115 if(distanceFromDirectionVector >= this->radius_) 99 116 continue; … … 111 128 Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition(); 112 129 float distance = distanceVector.length(); 130 // If the object is within 'radius' distance. 113 131 if (distance < this->radius_) 114 132 { 115 133 distanceVector.normalise(); 134 // Apply a force proportional to the velocity, with highest force at the origin of the sphere, linear decreasing until reaching a distance of 'radius' from the origin, where the force reaches zero. 116 135 it->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector); 117 136 } … … 119 138 } 120 139 } 121 140 141 /** 142 @brief 143 Set the mode of the ForceField. 144 @param mode 145 The mode as a string. 146 */ 122 147 void ForceField::setMode(const std::string& mode) 123 148 { … … 132 157 } 133 158 } 134 135 inline const std::string& ForceField::getMode(void) 159 160 /** 161 @brief 162 Get the mode of the ForceField. 163 @return 164 Returns the mode of the ForceField as a string. 165 */ 166 const std::string& ForceField::getMode(void) 136 167 { 137 168 switch(this->mode_) … … 145 176 } 146 177 } 178 147 179 } 148 149 150 151 152
Note: See TracChangeset
for help on using the changeset viewer.