00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ns3/simulator.h"
00021 #include "ns3/rectangle.h"
00022 #include "static-speed-helper.h"
00023
00024 namespace ns3 {
00025
00026 StaticSpeedHelper::StaticSpeedHelper ()
00027 : m_paused (true)
00028 {}
00029 StaticSpeedHelper::StaticSpeedHelper (const Vector &position)
00030 : m_position (position),
00031 m_paused (true)
00032 {}
00033 StaticSpeedHelper::StaticSpeedHelper (const Vector &position,
00034 const Vector &vel)
00035 : m_position (position),
00036 m_velocity (vel),
00037 m_paused (true)
00038 {}
00039 void
00040 StaticSpeedHelper::SetPosition (const Vector &position)
00041 {
00042 m_position = position;
00043 m_velocity = Vector (0.0, 0.0, 0.0);
00044 m_lastUpdate = Simulator::Now ();
00045 }
00046
00047 Vector
00048 StaticSpeedHelper::GetCurrentPosition (void) const
00049 {
00050 return m_position;
00051 }
00052
00053 Vector
00054 StaticSpeedHelper::GetVelocity (void) const
00055 {
00056 return m_paused? Vector (0.0, 0.0, 0.0) : m_velocity;
00057 }
00058 void
00059 StaticSpeedHelper::SetVelocity (const Vector &vel)
00060 {
00061 m_velocity = vel;
00062 m_lastUpdate = Simulator::Now ();
00063 }
00064
00065 void
00066 StaticSpeedHelper::Update (void) const
00067 {
00068 Time now = Simulator::Now ();
00069 NS_ASSERT (m_lastUpdate <= now);
00070 Time deltaTime = now - m_lastUpdate;
00071 m_lastUpdate = now;
00072 if (m_paused)
00073 {
00074 return;
00075 }
00076 double deltaS = deltaTime.GetSeconds ();
00077 m_position.x += m_velocity.x * deltaS;
00078 m_position.y += m_velocity.y * deltaS;
00079 m_position.z += m_velocity.z * deltaS;
00080 }
00081
00082 void
00083 StaticSpeedHelper::UpdateWithBounds (const Rectangle &bounds) const
00084 {
00085 Update ();
00086 m_position.x = std::min (bounds.xMax, m_position.x);
00087 m_position.x = std::max (bounds.xMin, m_position.x);
00088 m_position.y = std::min (bounds.yMax, m_position.y);
00089 m_position.y = std::max (bounds.yMin, m_position.y);
00090 }
00091
00092 void
00093 StaticSpeedHelper::Pause (void)
00094 {
00095 m_paused = true;
00096 }
00097
00098 void
00099 StaticSpeedHelper::Unpause (void)
00100 {
00101 m_paused = false;
00102 }
00103
00104 }