- Timestamp:
- Jan 10, 2016, 1:54:11 PM (8 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/src/modules/objects/ForceField.cc
r9945 r11054 118 118 { 119 119 // Iterate over all objects that could possibly be affected by the ForceField. 120 for ( ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)120 for (MobileEntity* mobileEntity : ObjectList<MobileEntity>()) 121 121 { 122 122 // The direction of the orientation of the force field. … … 125 125 126 126 // Vector from the center of the force field to the object its acting on. 127 Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction));127 Vector3 distanceVector = mobileEntity->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction)); 128 128 129 129 // The object is outside a ball around the center with radius length/2 of the ForceField. … … 132 132 133 133 // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector) 134 float distanceFromDirectionVector = (( it->getWorldPosition() - this->getWorldPosition()).crossProduct(direction)).length();134 float distanceFromDirectionVector = ((mobileEntity->getWorldPosition() - this->getWorldPosition()).crossProduct(direction)).length(); 135 135 136 136 // If the object in a tube of radius 'radius' around the direction of orientation. … … 140 140 // Apply a force to the object in the direction of the orientation. 141 141 // The force is highest when the object is directly on the direction vector, with a linear decrease, finally reaching zero, when distanceFromDirectionVector = radius. 142 it->applyCentralForce((this->radius_ - distanceFromDirectionVector)/this->radius_ * this->velocity_ * direction);142 mobileEntity->applyCentralForce((this->radius_ - distanceFromDirectionVector)/this->radius_ * this->velocity_ * direction); 143 143 } 144 144 } … … 146 146 { 147 147 // Iterate over all objects that could possibly be affected by the ForceField. 148 for ( ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)149 { 150 Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();148 for (MobileEntity* mobileEntity : ObjectList<MobileEntity>()) 149 { 150 Vector3 distanceVector = mobileEntity->getWorldPosition() - this->getWorldPosition(); 151 151 float distance = distanceVector.length(); 152 152 // If the object is within 'radius' distance. … … 155 155 distanceVector.normalise(); 156 156 // 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. 157 it->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector);157 mobileEntity->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector); 158 158 } 159 159 } … … 162 162 { 163 163 // Iterate over all objects that could possibly be affected by the ForceField. 164 for ( ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)165 { 166 Vector3 distanceVector = this->getWorldPosition() - it->getWorldPosition();164 for (MobileEntity* mobileEntity : ObjectList<MobileEntity>()) 165 { 166 Vector3 distanceVector = this->getWorldPosition() - mobileEntity->getWorldPosition(); 167 167 float distance = distanceVector.length(); 168 168 // If the object is within 'radius' distance and no more than 'length' away from the boundary of the sphere. … … 172 172 distanceVector.normalise(); 173 173 // 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. 174 it->applyCentralForce((distance-range)/range * this->velocity_ * distanceVector);174 mobileEntity->applyCentralForce((distance-range)/range * this->velocity_ * distanceVector); 175 175 } 176 176 } … … 179 179 { 180 180 // Iterate over all objects that could possibly be affected by the ForceField. 181 for ( ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)182 { 183 Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();181 for (MobileEntity* mobileEntity : ObjectList<MobileEntity>()) 182 { 183 Vector3 distanceVector = mobileEntity->getWorldPosition() - this->getWorldPosition(); 184 184 float distance = distanceVector.length(); 185 185 // If the object is within 'radius' distance and especially further away than massRadius_ … … 197 197 198 198 // Note: this so called force is actually an acceleration! 199 it->applyCentralForce((-1) * (ForceField::attenFactor_ * ForceField::gravConstant_ * this->getMass()) / (distance * distance) * distanceVector);199 mobileEntity->applyCentralForce((-1) * (ForceField::attenFactor_ * ForceField::gravConstant_ * this->getMass()) / (distance * distance) * distanceVector); 200 200 } 201 201 } … … 204 204 { 205 205 // Iterate over all objects that could possibly be affected by the ForceField. 206 for ( ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)207 { 208 Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();206 for (MobileEntity* mobileEntity : ObjectList<MobileEntity>()) 207 { 208 Vector3 distanceVector = mobileEntity->getWorldPosition() - this->getWorldPosition(); 209 209 float distance = distanceVector.length(); 210 210 if (distance < this->radius_ && distance > this->massRadius_) … … 212 212 // Add a Acceleration in forceDirection_. 213 213 // Vector3(0,0,0) is the direction, where the force should work. 214 it->addAcceleration(forceDirection_ , Vector3(0,0,0));214 mobileEntity->addAcceleration(forceDirection_ , Vector3(0,0,0)); 215 215 } 216 216 }
Note: See TracChangeset
for help on using the changeset viewer.