A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
constant-velocity-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
20
21#include "ns3/box.h"
22#include "ns3/log.h"
23#include "ns3/rectangle.h"
24#include "ns3/simulator.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("ConstantVelocityHelper");
30
32 : m_paused(true)
33{
34 NS_LOG_FUNCTION(this);
35}
36
38 : m_position(position),
39 m_paused(true)
40{
41 NS_LOG_FUNCTION(this << position);
42}
43
44ConstantVelocityHelper::ConstantVelocityHelper(const Vector& position, const Vector& vel)
45 : m_position(position),
46 m_velocity(vel),
47 m_paused(true)
48{
49 NS_LOG_FUNCTION(this << position << vel);
50}
51
52void
54{
55 NS_LOG_FUNCTION(this << position);
56 m_position = position;
57 m_velocity = Vector(0.0, 0.0, 0.0);
59}
60
61Vector
63{
64 NS_LOG_FUNCTION(this);
65 return m_position;
66}
67
68Vector
70{
71 NS_LOG_FUNCTION(this);
72 return m_paused ? Vector(0.0, 0.0, 0.0) : m_velocity;
73}
74
75void
77{
78 NS_LOG_FUNCTION(this << vel);
79 m_velocity = vel;
81}
82
83void
85{
86 NS_LOG_FUNCTION(this);
87 Time now = Simulator::Now();
88 NS_ASSERT(m_lastUpdate <= now);
89 Time deltaTime = now - m_lastUpdate;
90 m_lastUpdate = now;
91 if (m_paused)
92 {
93 return;
94 }
95 double deltaS = deltaTime.GetSeconds();
96 m_position.x += m_velocity.x * deltaS;
97 m_position.y += m_velocity.y * deltaS;
98 m_position.z += m_velocity.z * deltaS;
99}
100
101void
103{
104 NS_LOG_FUNCTION(this << bounds);
105 Update();
106 m_position.x = std::min(bounds.xMax, m_position.x);
107 m_position.x = std::max(bounds.xMin, m_position.x);
108 m_position.y = std::min(bounds.yMax, m_position.y);
109 m_position.y = std::max(bounds.yMin, m_position.y);
110}
111
112void
114{
115 NS_LOG_FUNCTION(this << bounds);
116 Update();
117 m_position.x = std::min(bounds.xMax, m_position.x);
118 m_position.x = std::max(bounds.xMin, m_position.x);
119 m_position.y = std::min(bounds.yMax, m_position.y);
120 m_position.y = std::max(bounds.yMin, m_position.y);
121 m_position.z = std::min(bounds.zMax, m_position.z);
122 m_position.z = std::max(bounds.zMin, m_position.z);
123}
124
125void
127{
128 NS_LOG_FUNCTION(this);
129 m_paused = true;
130}
131
132void
134{
135 NS_LOG_FUNCTION(this);
136 m_paused = false;
137}
138
139} // namespace ns3
a 3d box
Definition: box.h:35
double yMax
The y coordinate of the top bound of the box.
Definition: box.h:116
double xMin
The x coordinate of the left bound of the box.
Definition: box.h:110
double yMin
The y coordinate of the bottom bound of the box.
Definition: box.h:114
double xMax
The x coordinate of the right bound of the box.
Definition: box.h:112
double zMin
The z coordinate of the down bound of the box.
Definition: box.h:118
double zMax
The z coordinate of the up bound of the box.
Definition: box.h:120
Time m_lastUpdate
time of last update
Vector GetCurrentPosition() const
Get current position vector.
Vector m_position
state variable for current position
Vector GetVelocity() const
Get velocity; if paused, will return a zero vector.
void Update() const
Update position, if not paused, from last position and time of last update.
void UpdateWithBounds(const Rectangle &rectangle) const
Update position, if not paused, from last position and time of last update.
void Unpause()
Resume mobility from current position at current velocity.
void SetPosition(const Vector &position)
Set position vector.
void SetVelocity(const Vector &vel)
Set new velocity vector.
void Pause()
Pause mobility at current position.
Vector m_velocity
state variable for velocity
bool m_paused
state variable for paused
a 2d rectangle
Definition: rectangle.h:35
double yMax
The y coordinate of the top bound of the rectangle.
Definition: rectangle.h:92
double xMax
The x coordinate of the right bound of the rectangle.
Definition: rectangle.h:90
double xMin
The x coordinate of the left bound of the rectangle.
Definition: rectangle.h:89
double yMin
The y coordinate of the bottom bound of the rectangle.
Definition: rectangle.h:91
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.