Rectangle movement model. See NED file for more info. More...
#include <RectangleMobility.h>
Inherits BaseMobility.
Public Member Functions | |
virtual void | initialize (int) |
Initializes mobility model parameters. | |
Protected Member Functions | |
virtual void | makeMove () |
Move the host. | |
virtual void | fixIfHostGetsOutside () |
Should be redefined in subclasses. | |
void | calculateXY () |
Maps d to (x,y) coordinates. | |
Protected Attributes | |
double | x1 |
double | y1 |
double | x2 |
double | y2 |
rectangle bounds | |
double | d |
distance from (x1,y1), measured clockwise on the perimeter | |
double | corner1 |
double | corner2 |
double | corner3 |
double | corner4 |
Coord | targetPos |
Target position of the host. |
Rectangle movement model. See NED file for more info.
NOTE: Does not yet support 3-dimensional movement.
Definition at line 33 of file RectangleMobility.h.
void RectangleMobility::fixIfHostGetsOutside | ( | ) | [protected, virtual] |
Should be redefined in subclasses.
Should invoke handleIfOutside() and pass the references to the parameters to be modified.
Additional action after border handling (such as choosing a new target position if the BorderPolicy is PLACERANDOMLY) should be implemented here.
Reimplemented from BaseMobility.
Definition at line 93 of file RectangleMobility.cc.
References BaseMobility::handleIfOutside(), BaseMobility::RAISEERROR, targetPos, BaseWorldUtility::use2D(), and BaseMobility::world.
Referenced by makeMove().
{ Coord dummy(world->use2D()); double dum; handleIfOutside( RAISEERROR, targetPos, dummy, dummy, dum ); }
void RectangleMobility::initialize | ( | int | stage | ) | [virtual] |
Initializes mobility model parameters.
Reads the parameters. If the host is not stationary it calculates a random position and schedules a timer to trigger the first movement
Reimplemented from BaseMobility.
Definition at line 32 of file RectangleMobility.cc.
References calculateXY(), d, BaseMobility::move, Move::setSpeed(), Move::setStart(), targetPos, BaseWorldUtility::use2D(), BaseMobility::world, and y2.
{ BaseMobility::initialize(stage); debugEV << "initializing RectangleMobility stage " << stage << endl; if (stage == 0) { x1 = par("x1"); y1 = par("y1"); x2 = par("x2"); y2 = par("y2"); move.setSpeed(par("speed")); // calculate helper vars double dx = x2-x1; double dy = y2-y1; corner1 = dx; corner2 = corner1 + dy; corner3 = corner2 + dx; corner4 = corner3 + dy; // determine start position double startPos = par("startPos"); startPos = fmod(startPos,4); if (startPos<1) d = startPos*dx; // top side else if (startPos<2) d = corner1 + (startPos-1)*dy; // right side else if (startPos<3) d = corner2 + (startPos-2)*dx; // bottom side else d = corner3 + (startPos-3)*dy; // left side calculateXY(); move.setStart(targetPos); WATCH(d); } else { if(!world->use2D()) { opp_warning("This mobility module does not yet support 3 dimensional movement."\ "Movements will probably be incorrect."); } } }