#include <RectangleMobility.h>
Inheritance diagram for RectangleMobility:

Protected Member Functions | |
| virtual void | initialize (int) |
| Initializes mobility model parameters. | |
| virtual void | handleSelfMsg (cMessage *msg) |
| Called upon arrival of a self messages. | |
| void | move () |
| Move the host. | |
| void | calculateXY () |
| Maps d to (x,y) coordinates. | |
Protected Attributes | |
| double | x1 |
| double | y1 |
| double | x2 |
| double | y2 |
| rectangle bounds | |
| double | speed |
| speed of the host | |
| double | updateInterval |
| time interval to update the hosts position | |
| bool | stationary |
| if true, the host doesn't move | |
| double | d |
| distance from (x1,y1), measured clockwise on the perimeter | |
| double | corner1 |
| double | corner2 |
| double | corner3 |
| double | corner4 |
|
|
Maps d to (x,y) coordinates.
00101 {
00102 if (d < corner1)
00103 {
00104 // top side
00105 pos.x = x1 + d;
00106 pos.y = y1;
00107 }
00108 else if (d < corner2)
00109 {
00110 // right side
00111 pos.x = x2;
00112 pos.y = y1 + d - corner1;
00113 }
00114 else if (d < corner3)
00115 {
00116 // bottom side
00117 pos.x = x2 - d + corner2;
00118 pos.y = y2;
00119 }
00120 else
00121 {
00122 // left side
00123 pos.x = x1;
00124 pos.y = y2 - d + corner3;
00125 }
00126 }
|
|
|
Called upon arrival of a self messages. The only self message possible is to indicate a new movement. If host is stationary this function is never called. Reimplemented from BasicMobility. 00084 {
00085 move();
00086 updatePosition();
00087 scheduleAt(simTime() + updateInterval, msg);
00088 }
|
|
|
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 BasicMobility. 00032 {
00033 BasicMobility::initialize(stage);
00034
00035 EV << "initializing RectangleMobility stage " << stage << endl;
00036
00037 if (stage == 1)
00038 {
00039 x1 = par("x1");
00040 y1 = par("y1");
00041 x2 = par("x2");
00042 y2 = par("y2");
00043 updateInterval = par("updateInterval");
00044 speed = par("speed");
00045
00046 // if the initial speed is lower than 0, the node is stationary
00047 stationary = (speed == 0);
00048
00049 // calculate helper vars
00050 double dx = x2-x1;
00051 double dy = y2-y1;
00052 corner1 = dx;
00053 corner2 = corner1 + dy;
00054 corner3 = corner2 + dx;
00055 corner4 = corner3 + dy;
00056
00057 // determine start position
00058 double startPos = par("startPos");
00059 startPos = fmod(startPos,4);
00060 if (startPos<1)
00061 d = startPos*dx; // top side
00062 else if (startPos<2)
00063 d = corner1 + (startPos-1)*dy; // right side
00064 else if (startPos<3)
00065 d = corner2 + (startPos-2)*dx; // bottom side
00066 else
00067 d = corner3 + (startPos-3)*dy; // left side
00068 calculateXY();
00069 WATCH(d);
00070 updatePosition();
00071
00072 // host moves the first time after some random delay to avoid synchronized movements
00073 if (!stationary)
00074 scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
00075 }
00076 }
|
|
|
Move the host.
00091 {
00092 d += speed * updateInterval;
00093 while (d<0) d+=corner4;
00094 while (d>=corner4) d-=corner4;
00095
00096 calculateXY();
00097 EV << " xpos= " << pos.x << " ypos=" << pos.y << " speed=" << speed << endl;
00098 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
distance from (x1,y1), measured clockwise on the perimeter
|
|
|
speed of the host
|
|
|
if true, the host doesn't move
|
|
|
time interval to update the hosts position
|
|
|
|
|
|
|
|
|
|
|
|
rectangle bounds
|
1.4.1