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 "box.h"
22#include "rectangle.h"
23
24#include "ns3/log.h"
25#include "ns3/simulator.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("ConstantVelocityHelper");
31
33 : m_paused(true)
34{
35 NS_LOG_FUNCTION(this);
36}
37
39 : m_position(position),
40 m_paused(true)
41{
42 NS_LOG_FUNCTION(this << position);
43}
44
45ConstantVelocityHelper::ConstantVelocityHelper(const Vector& position, const Vector& vel)
46 : m_position(position),
47 m_velocity(vel),
48 m_paused(true)
49{
50 NS_LOG_FUNCTION(this << position << vel);
51}
52
53void
55{
56 NS_LOG_FUNCTION(this << position);
57 m_position = position;
58 m_velocity = Vector(0.0, 0.0, 0.0);
60}
61
62Vector
64{
65 NS_LOG_FUNCTION(this);
66 return m_position;
67}
68
69Vector
71{
72 NS_LOG_FUNCTION(this);
73 return m_paused ? Vector(0.0, 0.0, 0.0) : m_velocity;
74}
75
76void
78{
79 NS_LOG_FUNCTION(this << vel);
80 m_velocity = vel;
82}
83
84void
86{
87 NS_LOG_FUNCTION(this);
88 Time now = Simulator::Now();
89 NS_ASSERT(m_lastUpdate <= now);
90 Time deltaTime = now - m_lastUpdate;
91 m_lastUpdate = now;
92 if (m_paused)
93 {
94 return;
95 }
96 double deltaS = deltaTime.GetSeconds();
97 m_position.x += m_velocity.x * deltaS;
98 m_position.y += m_velocity.y * deltaS;
99 m_position.z += m_velocity.z * deltaS;
100}
101
102void
104{
105 NS_LOG_FUNCTION(this << bounds);
106 Update();
107 m_position.x = std::min(bounds.xMax, m_position.x);
108 m_position.x = std::max(bounds.xMin, m_position.x);
109 m_position.y = std::min(bounds.yMax, m_position.y);
110 m_position.y = std::max(bounds.yMin, m_position.y);
111}
112
113void
115{
116 NS_LOG_FUNCTION(this << bounds);
117 Update();
118 m_position.x = std::min(bounds.xMax, m_position.x);
119 m_position.x = std::max(bounds.xMin, m_position.x);
120 m_position.y = std::min(bounds.yMax, m_position.y);
121 m_position.y = std::max(bounds.yMin, m_position.y);
122 m_position.z = std::min(bounds.zMax, m_position.z);
123 m_position.z = std::max(bounds.zMin, m_position.z);
124}
125
126void
128{
129 NS_LOG_FUNCTION(this);
130 m_paused = true;
131}
132
133void
135{
136 NS_LOG_FUNCTION(this);
137 m_paused = false;
138}
139
140} // 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:118
double xMax
The x coordinate of the right bound of the rectangle.
Definition: rectangle.h:116
double xMin
The x coordinate of the left bound of the rectangle.
Definition: rectangle.h:115
double yMin
The y coordinate of the bottom bound of the rectangle.
Definition: rectangle.h:117
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
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:403
#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.