|
|
| 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License version 2 as |
| 5 |
* published by the Free Software Foundation; |
| 6 |
* |
| 7 |
* This program is distributed in the hope that it will be useful, |
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
* GNU General Public License for more details. |
| 11 |
* |
| 12 |
* You should have received a copy of the GNU General Public License |
| 13 |
* along with this program; if not, write to the Free Software |
| 14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 15 |
* |
| 16 |
* Author: Gustavo Carneiro <gjc@inescporto.pt> |
| 17 |
*/ |
| 18 |
#include "constant-acceleration-mobility-model.h" |
| 19 |
#include "ns3/simulator.h" |
| 20 |
|
| 21 |
namespace ns3 { |
| 22 |
|
| 23 |
NS_OBJECT_ENSURE_REGISTERED (ConstantAccelerationMobilityModel); |
| 24 |
|
| 25 |
TypeId ConstantAccelerationMobilityModel::GetTypeId (void) |
| 26 |
{ |
| 27 |
static TypeId tid = TypeId ("ns3::ConstantAccelerationMobilityModel") |
| 28 |
.SetParent<MobilityModel> () |
| 29 |
.AddConstructor<ConstantAccelerationMobilityModel> (); |
| 30 |
return tid; |
| 31 |
} |
| 32 |
|
| 33 |
ConstantAccelerationMobilityModel::ConstantAccelerationMobilityModel () |
| 34 |
{} |
| 35 |
|
| 36 |
ConstantAccelerationMobilityModel::~ConstantAccelerationMobilityModel () |
| 37 |
{} |
| 38 |
|
| 39 |
inline Vector |
| 40 |
ConstantAccelerationMobilityModel::DoGetVelocity (void) const |
| 41 |
{ |
| 42 |
double t = (Simulator::Now () - m_baseTime).GetSeconds (); |
| 43 |
return Vector (m_baseVelocity.x + m_acceleration.x*t, |
| 44 |
m_baseVelocity.y + m_acceleration.y*t, |
| 45 |
m_baseVelocity.z + m_acceleration.z*t); |
| 46 |
} |
| 47 |
|
| 48 |
inline Vector |
| 49 |
ConstantAccelerationMobilityModel::DoGetPosition (void) const |
| 50 |
{ |
| 51 |
double t = (Simulator::Now () - m_baseTime).GetSeconds (); |
| 52 |
double half_t_square = t*t*0.5; |
| 53 |
return Vector (m_basePosition.x + m_baseVelocity.x*t + m_acceleration.x*half_t_square, |
| 54 |
m_basePosition.y + m_baseVelocity.y*t + m_acceleration.y*half_t_square, |
| 55 |
m_basePosition.z + m_baseVelocity.z*t + m_acceleration.z*half_t_square); |
| 56 |
} |
| 57 |
|
| 58 |
void |
| 59 |
ConstantAccelerationMobilityModel::DoSetPosition (const Vector &position) |
| 60 |
{ |
| 61 |
m_baseVelocity = DoGetVelocity (); |
| 62 |
m_baseTime = Simulator::Now (); |
| 63 |
m_basePosition = position; |
| 64 |
NotifyCourseChange (); |
| 65 |
} |
| 66 |
|
| 67 |
void |
| 68 |
ConstantAccelerationMobilityModel::SetVelocityAndAcceleration (const Vector &velocity, |
| 69 |
const Vector &acceleration) |
| 70 |
{ |
| 71 |
m_basePosition = DoGetPosition (); |
| 72 |
m_baseTime = Simulator::Now (); |
| 73 |
m_baseVelocity = velocity; |
| 74 |
m_acceleration = acceleration; |
| 75 |
NotifyCourseChange (); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
}; // namespace ns3 |