Changeset 7676
- Timestamp:
- Nov 26, 2010, 8:44:48 AM (14 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 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 -
code/trunk/src/modules/objects/ForceField.h
r7674 r7676 33 33 */ 34 34 35 /**36 @file ForceField.h37 @brief Definition of the ForceField class.38 @inGroup Objects39 */40 41 35 #ifndef _ForceField_H__ 42 36 #define _ForceField_H__ … … 53 47 @brief 54 48 The mode of the ForceField. 55 56 @in Group Objects49 50 @ingroup Objects 57 51 */ 58 52 namespace forceFieldMode … … 61 55 tube, //!< The ForceField has a tube shape. 62 56 sphere //!< The ForceField has a spherical shape. 63 64 57 }; 65 58 } … … 68 61 @brief 69 62 Implements a force field, that applies a force to any @ref orxonox::MoblieEnity "MobileEntity" that enters its range. 70 63 71 64 The following parameters can be set to specify the behavior of the ForceField. 72 - @b velocity The amount of force the ForceField excerts. 73 - @b diameter The diameter of the ForceField. 74 - @b length The length of the ForceField. 65 - @b velocity The amount of force the ForceField excerts. Default is 100. 66 - @b diameter The diameter of the ForceField. Default is 500. 67 - @b length The length of the ForceField. Default is 2000. 75 68 - @b mode The mode the ForceField is in. For mode: 76 -- <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. 77 -- <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>. 78 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>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 Default is <em>tube</em>. 72 79 73 @author 80 74 Aurelian Jaggi 81 75 82 76 @author 83 77 Damian 'Mozork' Frick 84 85 @in Group Objects78 79 @ingroup Objects 86 80 */ 87 81 class _ObjectsExport ForceField : public StaticEntity, public Tickable … … 90 84 ForceField(BaseObject* creator); 91 85 virtual ~ForceField(); 92 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);93 virtual void tick(float dt);94 86 87 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML. 88 virtual void tick(float dt); //!< A method that is called every tick. 89 90 /** 91 @brief Set the velocity of the ForceField. 92 @param vel The velocity to be set. 93 */ 95 94 inline void setVelocity(float vel) 96 95 { this->velocity_ = vel; } 97 96 /** 97 @brief Get the velocity of the ForceField. 98 @return Returns the velocity of the ForceField. 99 */ 98 100 inline float getVelocity() 99 101 { return this->velocity_; } 100 102 103 /** 104 @brief Set the diameter of the ForceField. 105 @param diam The diameter to be set. 106 */ 101 107 inline void setDiameter(float diam) 102 { this->diameter_ = diam; this->radius_ = diam/2; } 108 { this->radius_ = diam/2; } 109 /** 110 @brief Get the diameter of the ForceField. 111 @return Returns the diameter of the ForceField. 112 */ 113 inline float getDiameter() 114 { return this->radius_*2; } 103 115 104 inline float getDiameter() 105 { return this->diameter_; } 116 /** 117 @brief Set the length of the ForceField. 118 @param l The length to be set. 119 */ 120 inline void setLength(float l) 121 { this->halfLength_ = l/2; } 122 /** 123 @brief Get the length of the ForceField. 124 @return Returns the length of the ForceField. 125 */ 126 inline float getLength() 127 { return this->halfLength_*2; } 106 128 107 inline void setLength(float l) 108 { this->length_ = l; this->halfLength_ = l/2; } 109 110 inline float getLength() 111 { return this->length_; } 112 113 void setMode(const std::string& mode); 114 115 inline const std::string& getMode(void); 129 void setMode(const std::string& mode); //!< Set the mode of the ForceField. 130 const std::string& getMode(void); //!< Get the mode of the ForceField. 116 131 117 132 private: 133 //! Strings to represent the modes. 118 134 static const std::string modeTube_s; 119 135 static const std::string modeSphere_s; 120 121 float velocity_; 122 float diameter_; 123 float radius_; 124 float length_; 125 float halfLength_; 126 forceFieldMode::Value mode_; 136 137 float velocity_; //!< The velocity of the ForceField. 138 float radius_; //!< The radius of the ForceField. 139 float halfLength_; //!< Half of the length of the ForceField. 140 forceFieldMode::Value mode_; //!< The mode of the ForceField. 127 141 }; 128 142 } 129 143 130 144 #endif 131
Note: See TracChangeset
for help on using the changeset viewer.