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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
9
10#include "box.h"
11#include "rectangle.h"
12
13#include "ns3/log.h"
14#include "ns3/simulator.h"
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("ConstantVelocityHelper");
20
26
28 : m_position(position),
29 m_paused(true)
30{
31 NS_LOG_FUNCTION(this << position);
32}
33
34ConstantVelocityHelper::ConstantVelocityHelper(const Vector& position, const Vector& vel)
35 : m_position(position),
36 m_velocity(vel),
37 m_paused(true)
38{
39 NS_LOG_FUNCTION(this << position << vel);
40}
41
42void
44{
45 NS_LOG_FUNCTION(this << position);
46 m_position = position;
47 m_velocity = Vector(0.0, 0.0, 0.0);
49}
50
51Vector
57
58Vector
60{
61 NS_LOG_FUNCTION(this);
62 return m_paused ? Vector(0.0, 0.0, 0.0) : m_velocity;
63}
64
65void
67{
68 NS_LOG_FUNCTION(this << vel);
69 m_velocity = vel;
71}
72
73void
75{
76 NS_LOG_FUNCTION(this);
77 Time now = Simulator::Now();
78 NS_ASSERT(m_lastUpdate <= now);
79 Time deltaTime = now - m_lastUpdate;
80 m_lastUpdate = now;
81 if (m_paused)
82 {
83 return;
84 }
85 double deltaS = deltaTime.GetSeconds();
86 m_position.x += m_velocity.x * deltaS;
87 m_position.y += m_velocity.y * deltaS;
88 m_position.z += m_velocity.z * deltaS;
89}
90
91void
93{
94 NS_LOG_FUNCTION(this << bounds);
95 Update();
96 m_position.x = std::min(bounds.xMax, m_position.x);
97 m_position.x = std::max(bounds.xMin, m_position.x);
98 m_position.y = std::min(bounds.yMax, m_position.y);
99 m_position.y = std::max(bounds.yMin, m_position.y);
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 m_position.z = std::min(bounds.zMax, m_position.z);
112 m_position.z = std::max(bounds.zMin, m_position.z);
113}
114
115void
117{
118 NS_LOG_FUNCTION(this);
119 m_paused = true;
120}
121
122void
124{
125 NS_LOG_FUNCTION(this);
126 m_paused = false;
127}
128
129} // namespace ns3
a 3d box
Definition box.h:24
double yMax
The y coordinate of the top bound of the box.
Definition box.h:105
double xMin
The x coordinate of the left bound of the box.
Definition box.h:99
double yMin
The y coordinate of the bottom bound of the box.
Definition box.h:103
double xMax
The x coordinate of the right bound of the box.
Definition box.h:101
double zMin
The z coordinate of the down bound of the box.
Definition box.h:107
double zMax
The z coordinate of the up bound of the box.
Definition box.h:109
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:24
double yMax
The y coordinate of the top bound of the rectangle.
Definition rectangle.h:107
double xMax
The x coordinate of the right bound of the rectangle.
Definition rectangle.h:105
double xMin
The x coordinate of the left bound of the rectangle.
Definition rectangle.h:104
double yMin
The y coordinate of the bottom bound of the rectangle.
Definition rectangle.h:106
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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.