[Orxonox-commit 2979] r7677 - in code/trunk: data/levels src/modules/objects

dafrick at orxonox.net dafrick at orxonox.net
Fri Nov 26 13:25:56 CET 2010


Author: dafrick
Date: 2010-11-26 13:25:56 +0100 (Fri, 26 Nov 2010)
New Revision: 7677

Modified:
   code/trunk/data/levels/The Time Machine.oxw
   code/trunk/src/modules/objects/ForceField.cc
   code/trunk/src/modules/objects/ForceField.h
Log:
Adding yet another class of ForceFields and using it in The Time Machine.


Modified: code/trunk/data/levels/The Time Machine.oxw
===================================================================
--- code/trunk/data/levels/The Time Machine.oxw	2010-11-26 07:44:48 UTC (rev 7676)
+++ code/trunk/data/levels/The Time Machine.oxw	2010-11-26 12:25:56 UTC (rev 7677)
@@ -12,7 +12,6 @@
     include("templates/spaceship_pirate.oxt")
 ?>
 
-
 <!--*****************************************************************************************************************************************************************************************-->
 <!--Including Template for triggering on player-->
 
@@ -72,7 +71,7 @@
         ambientlight="0.8,0.8,0.8"
         skybox="Orxonox/skypanoramagen2"
     >
-    
+
         <Light type=directional position="0,0,0" direction="0, 0, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 1.0, 0.9" />
 
 <!--CREATING SPAWNPOINTS_____________________________________________________________________________________________________________________________________________________________________-->
@@ -267,6 +266,7 @@
         <Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
     
 <!--TIME MACHINE____________________________________________________________________________________________________________________________________________________________________________-->
+<ForceField mode="invertedSphere" position="0,0,0" velocity=50000 diameter=6500 length=500 />
         <StaticEntity>
             <attached>
                 <MovableEntity position="0,0,0">

Modified: code/trunk/src/modules/objects/ForceField.cc
===================================================================
--- code/trunk/src/modules/objects/ForceField.cc	2010-11-26 07:44:48 UTC (rev 7676)
+++ code/trunk/src/modules/objects/ForceField.cc	2010-11-26 12:25:56 UTC (rev 7677)
@@ -43,6 +43,7 @@
 
     /*static*/ const std::string ForceField::modeTube_s = "tube";
     /*static*/ const std::string ForceField::modeSphere_s = "sphere";
+    /*static*/ const std::string ForceField::modeInvertedSphere_s = "invertedSphere";
 
     /**
     @brief
@@ -78,7 +79,7 @@
 
         XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
         XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
-        XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
+        XMLPortParam(ForceField, "length", setLength  , getLength  , xmlelement, mode).defaultValues(2000);
         XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode);
     }
 
@@ -101,10 +102,9 @@
                 direction.normalise();
 
                 // Vector from the center of the force field to the object its acting on.
-                // TODO: This could probably be simplified.
                 Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction));
 
-                // The object is outside of the length of the ForceField.
+                // The object is outside a ball around the center with radius length/2 of the ForceField.
                 if(distanceVector.length() > this->halfLength_)
                     continue;
 
@@ -136,6 +136,23 @@
                 }
             }
         }
+        else if(this->mode_ == forceFieldMode::invertedSphere)
+        {
+            // Iterate over all objects that could possibly be affected by the ForceField.
+            for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
+            {
+                Vector3 distanceVector = this->getWorldPosition() - it->getWorldPosition();
+                float distance = distanceVector.length();
+                // If the object is within 'radius' distance and no more than 'length' away from the boundary of the sphere.
+                float range = this->radius_ - this->halfLength_*2;
+                if (distance < this->radius_ && distance > range)
+                {
+                    distanceVector.normalise();
+                    // 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.
+                    it->applyCentralForce((distance-range)/range * this->velocity_ * distanceVector);
+                }
+            }
+        }
     }
 
     /**
@@ -150,6 +167,8 @@
             this->mode_ = forceFieldMode::tube;
         else if(mode == ForceField::modeSphere_s)
             this->mode_ = forceFieldMode::sphere;
+        else if(mode == ForceField::modeInvertedSphere_s)
+            this->mode_ = forceFieldMode::invertedSphere;
         else
         {
             COUT(2) << "Wrong mode '" << mode << "' in ForceField. Setting to 'tube'." << std::endl;
@@ -171,6 +190,8 @@
                 return ForceField::modeTube_s;
             case forceFieldMode::sphere:
                 return ForceField::modeSphere_s;
+            case forceFieldMode::invertedSphere:
+                return ForceField::modeInvertedSphere_s;
             default:
                 return ForceField::modeTube_s;
         }

Modified: code/trunk/src/modules/objects/ForceField.h
===================================================================
--- code/trunk/src/modules/objects/ForceField.h	2010-11-26 07:44:48 UTC (rev 7676)
+++ code/trunk/src/modules/objects/ForceField.h	2010-11-26 12:25:56 UTC (rev 7677)
@@ -53,7 +53,8 @@
     {
         enum Value {
             tube, //!< The ForceField has a tube shape.
-            sphere //!< The ForceField has a spherical shape.
+            sphere, //!< The ForceField has a spherical shape.
+            invertedSphere //!< The ForceField has a spherical shape but "inverted" behavior.
         };
     }
 
@@ -66,9 +67,10 @@
         - @b diameter The diameter of the ForceField. Default is 500.
         - @b length The length of the ForceField. Default is 2000.
         - @b mode The mode the ForceField is in. For mode:
-            - <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.
+            - <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.
             - <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>.
             Default is <em>tube</em>.
+            - <em>invertedSphere</em> 
 
     @author
         Aurelian Jaggi
@@ -133,6 +135,7 @@
             //! Strings to represent the modes.
             static const std::string modeTube_s;
             static const std::string modeSphere_s;
+            static const std::string modeInvertedSphere_s;
 
             float velocity_; //!< The velocity of the ForceField.
             float radius_; //!< The radius of the ForceField.




More information about the Orxonox-commit mailing list