A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
constant-velocity-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2006,2007 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "ns3/simulator.h"
21
#include "ns3/rectangle.h"
22
#include "ns3/box.h"
23
#include "ns3/log.h"
24
#include "
constant-velocity-helper.h
"
25
26
NS_LOG_COMPONENT_DEFINE
(
"ConstantVelocityHelper"
);
27
28
namespace
ns3 {
29
30
ConstantVelocityHelper::ConstantVelocityHelper
()
31
: m_paused (true)
32
{
33
NS_LOG_FUNCTION
(
this
);
34
}
35
ConstantVelocityHelper::ConstantVelocityHelper
(
const
Vector
&position)
36
: m_position (position),
37
m_paused (true)
38
{
39
NS_LOG_FUNCTION
(
this
<< position);
40
}
41
ConstantVelocityHelper::ConstantVelocityHelper
(
const
Vector
&position,
42
const
Vector
&vel)
43
: m_position (position),
44
m_velocity (vel),
45
m_paused (true)
46
{
47
NS_LOG_FUNCTION
(
this
<< position << vel);
48
}
49
void
50
ConstantVelocityHelper::SetPosition
(
const
Vector
&position)
51
{
52
NS_LOG_FUNCTION
(
this
<< position);
53
m_position
= position;
54
m_velocity
=
Vector
(0.0, 0.0, 0.0);
55
m_lastUpdate
=
Simulator::Now
();
56
}
57
58
Vector
59
ConstantVelocityHelper::GetCurrentPosition
(
void
)
const
60
{
61
NS_LOG_FUNCTION
(
this
);
62
return
m_position
;
63
}
64
65
Vector
66
ConstantVelocityHelper::GetVelocity
(
void
)
const
67
{
68
NS_LOG_FUNCTION
(
this
);
69
return
m_paused
?
Vector
(0.0, 0.0, 0.0) :
m_velocity
;
70
}
71
void
72
ConstantVelocityHelper::SetVelocity
(
const
Vector
&vel)
73
{
74
NS_LOG_FUNCTION
(
this
<< vel);
75
m_velocity
= vel;
76
m_lastUpdate
=
Simulator::Now
();
77
}
78
79
void
80
ConstantVelocityHelper::Update
(
void
)
const
81
{
82
NS_LOG_FUNCTION
(
this
);
83
Time
now =
Simulator::Now
();
84
NS_ASSERT
(
m_lastUpdate
<= now);
85
Time
deltaTime = now -
m_lastUpdate
;
86
m_lastUpdate = now;
87
if
(
m_paused
)
88
{
89
return
;
90
}
91
double
deltaS = deltaTime.
GetSeconds
();
92
m_position
.
x
+=
m_velocity
.
x
* deltaS;
93
m_position
.
y
+=
m_velocity
.
y
* deltaS;
94
m_position
.
z
+=
m_velocity
.
z
* deltaS;
95
}
96
97
void
98
ConstantVelocityHelper::UpdateWithBounds
(
const
Rectangle
&bounds)
const
99
{
100
NS_LOG_FUNCTION
(
this
<< bounds);
101
Update
();
102
m_position
.
x
= std::min (bounds.
xMax
,
m_position
.
x
);
103
m_position
.
x
= std::max (bounds.
xMin
,
m_position
.
x
);
104
m_position
.
y
= std::min (bounds.
yMax
,
m_position
.
y
);
105
m_position
.
y
= std::max (bounds.
yMin
,
m_position
.
y
);
106
}
107
108
void
109
ConstantVelocityHelper::UpdateWithBounds
(
const
Box
&bounds)
const
110
{
111
NS_LOG_FUNCTION
(
this
<< bounds);
112
Update
();
113
m_position
.
x
= std::min (bounds.
xMax
,
m_position
.
x
);
114
m_position
.
x
= std::max (bounds.
xMin
,
m_position
.
x
);
115
m_position
.
y
= std::min (bounds.
yMax
,
m_position
.
y
);
116
m_position
.
y
= std::max (bounds.
yMin
,
m_position
.
y
);
117
m_position
.
z
= std::min (bounds.
zMax
,
m_position
.
z
);
118
m_position
.
z
= std::max (bounds.
zMin
,
m_position
.
z
);
119
}
120
121
void
122
ConstantVelocityHelper::Pause
(
void
)
123
{
124
NS_LOG_FUNCTION
(
this
);
125
m_paused
=
true
;
126
}
127
128
void
129
ConstantVelocityHelper::Unpause
(
void
)
130
{
131
NS_LOG_FUNCTION
(
this
);
132
m_paused
=
false
;
133
}
134
135
}
// namespace ns3
ns3::Vector3D::x
double x
x coordinate of vector
Definition:
vector.h:49
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::Box::zMin
double zMin
Definition:
box.h:97
ns3::ConstantVelocityHelper::GetCurrentPosition
Vector GetCurrentPosition(void) const
Definition:
constant-velocity-helper.cc:59
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::Rectangle::yMax
double yMax
Definition:
rectangle.h:91
ns3::Box::xMax
double xMax
Definition:
box.h:91
ns3::ConstantVelocityHelper::m_velocity
Vector m_velocity
Definition:
constant-velocity-helper.h:57
ns3::Vector3D
a 3d vector
Definition:
vector.h:31
ns3::Rectangle::xMin
double xMin
Definition:
rectangle.h:85
ns3::Box
a 3d box
Definition:
box.h:33
ns3::Box::yMax
double yMax
Definition:
box.h:95
ns3::Time::GetSeconds
double GetSeconds(void) const
Definition:
nstime.h:274
constant-velocity-helper.h
ns3::ConstantVelocityHelper::Update
void Update(void) const
Definition:
constant-velocity-helper.cc:80
ns3::Vector
Vector3D Vector
Definition:
vector.h:118
ns3::Rectangle::xMax
double xMax
Definition:
rectangle.h:87
ns3::Rectangle::yMin
double yMin
Definition:
rectangle.h:89
ns3::Box::yMin
double yMin
Definition:
box.h:93
ns3::ConstantVelocityHelper::SetVelocity
void SetVelocity(const Vector &vel)
Definition:
constant-velocity-helper.cc:72
ns3::Vector3D::y
double y
y coordinate of vector
Definition:
vector.h:53
ns3::Box::zMax
double zMax
Definition:
box.h:99
ns3::Simulator::Now
static Time Now(void)
Return the "current simulation time".
Definition:
simulator.cc:180
ns3::ConstantVelocityHelper::m_position
Vector m_position
Definition:
constant-velocity-helper.h:56
ns3::ConstantVelocityHelper::GetVelocity
Vector GetVelocity(void) const
Definition:
constant-velocity-helper.cc:66
ns3::ConstantVelocityHelper::UpdateWithBounds
void UpdateWithBounds(const Rectangle &rectangle) const
Definition:
constant-velocity-helper.cc:98
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("ConstantVelocityHelper")
ns3::ConstantVelocityHelper::Unpause
void Unpause(void)
Definition:
constant-velocity-helper.cc:129
ns3::ConstantVelocityHelper::ConstantVelocityHelper
ConstantVelocityHelper()
Definition:
constant-velocity-helper.cc:30
ns3::ConstantVelocityHelper::m_paused
bool m_paused
Definition:
constant-velocity-helper.h:58
ns3::ConstantVelocityHelper::SetPosition
void SetPosition(const Vector &position)
Definition:
constant-velocity-helper.cc:50
ns3::ConstantVelocityHelper::m_lastUpdate
Time m_lastUpdate
Definition:
constant-velocity-helper.h:55
ns3::ConstantVelocityHelper::Pause
void Pause(void)
Definition:
constant-velocity-helper.cc:122
ns3::Rectangle
a 2d rectangle
Definition:
rectangle.h:33
ns3::Box::xMin
double xMin
Definition:
box.h:89
ns3::Vector3D::z
double z
z coordinate of vector
Definition:
vector.h:57
src
mobility
model
constant-velocity-helper.cc
Generated on Sat Apr 19 2014 14:07:04 for ns-3 by
1.8.6