Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7677


Ignore:
Timestamp:
Nov 26, 2010, 1:25:56 PM (13 years ago)
Author:
dafrick
Message:

Adding yet another class of ForceFields and using it in The Time Machine.

Location:
code/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/levels/The Time Machine.oxw

    r7675 r7677  
    1212    include("templates/spaceship_pirate.oxt")
    1313?>
    14 
    1514
    1615<!--*****************************************************************************************************************************************************************************************-->
     
    7372        skybox="Orxonox/skypanoramagen2"
    7473    >
    75    
     74
    7675        <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" />
    7776
     
    268267   
    269268<!--TIME MACHINE____________________________________________________________________________________________________________________________________________________________________________-->
     269<ForceField mode="invertedSphere" position="0,0,0" velocity=50000 diameter=6500 length=500 />
    270270        <StaticEntity>
    271271            <attached>
  • code/trunk/src/modules/objects/ForceField.cc

    r7676 r7677  
    4444    /*static*/ const std::string ForceField::modeTube_s = "tube";
    4545    /*static*/ const std::string ForceField::modeSphere_s = "sphere";
     46    /*static*/ const std::string ForceField::modeInvertedSphere_s = "invertedSphere";
    4647
    4748    /**
     
    7980        XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
    8081        XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
    81         XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
     82        XMLPortParam(ForceField, "length", setLength  , getLength  , xmlelement, mode).defaultValues(2000);
    8283        XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode);
    8384    }
     
    102103
    103104                // Vector from the center of the force field to the object its acting on.
    104                 // TODO: This could probably be simplified.
    105105                Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction));
    106106
    107                 // The object is outside of the length of the ForceField.
     107                // The object is outside a ball around the center with radius length/2 of the ForceField.
    108108                if(distanceVector.length() > this->halfLength_)
    109109                    continue;
     
    137137            }
    138138        }
     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        }
    139156    }
    140157
     
    151168        else if(mode == ForceField::modeSphere_s)
    152169            this->mode_ = forceFieldMode::sphere;
     170        else if(mode == ForceField::modeInvertedSphere_s)
     171            this->mode_ = forceFieldMode::invertedSphere;
    153172        else
    154173        {
     
    172191            case forceFieldMode::sphere:
    173192                return ForceField::modeSphere_s;
     193            case forceFieldMode::invertedSphere:
     194                return ForceField::modeInvertedSphere_s;
    174195            default:
    175196                return ForceField::modeTube_s;
  • code/trunk/src/modules/objects/ForceField.h

    r7676 r7677  
    5454        enum Value {
    5555            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.
    5758        };
    5859    }
     
    6768        - @b length The length of the ForceField. Default is 2000.
    6869        - @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.
    7071            - <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>.
    7172            Default is <em>tube</em>.
     73            - <em>invertedSphere</em>
    7274
    7375    @author
     
    134136            static const std::string modeTube_s;
    135137            static const std::string modeSphere_s;
     138            static const std::string modeInvertedSphere_s;
    136139
    137140            float velocity_; //!< The velocity of the ForceField.
Note: See TracChangeset for help on using the changeset viewer.