View | Details | Raw Unified | Return to bug 511
Collapse All | Expand All

(-)a/src/mobility/hierarchical-mobility-model.cc (-13 / +62 lines)
 Lines 52-66    Link Here 
52
void 
52
void 
53
HierarchicalMobilityModel::SetChild (Ptr<MobilityModel> model)
53
HierarchicalMobilityModel::SetChild (Ptr<MobilityModel> model)
54
{
54
{
55
  Ptr<MobilityModel> oldChild = m_child;
56
  Vector pos;
57
  if (m_child)
58
    {
59
      pos = GetPosition ();
60
      m_child->TraceDisconnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
61
    }
55
  m_child = model;
62
  m_child = model;
56
  m_child->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
63
  m_child->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
64
65
  // if we had a child before, then we had a valid position before;
66
  // try to preserve the old absolute position.
67
  if (oldChild)
68
    {
69
      SetPosition (pos);
70
    }
57
}
71
}
58
72
59
void 
73
void 
60
HierarchicalMobilityModel::SetParent (Ptr<MobilityModel> model)
74
HierarchicalMobilityModel::SetParent (Ptr<MobilityModel> model)
61
{
75
{
76
  Vector pos;
77
  if (m_child)
78
    {
79
      pos = GetPosition ();
80
    }
81
  if (m_parent)
82
    {
83
      m_parent->TraceDisconnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
84
    }
62
  m_parent = model;
85
  m_parent = model;
63
  m_parent->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
86
  if (m_parent)
87
    {
88
      m_parent->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
89
    }
90
  // try to preserve the old position across parent changes
91
  if (m_child)
92
    {
93
      SetPosition (pos);
94
    }
64
}
95
}
65
96
66
97
 Lines 79-84    Link Here 
79
Vector
110
Vector
80
HierarchicalMobilityModel::DoGetPosition (void) const
111
HierarchicalMobilityModel::DoGetPosition (void) const
81
{
112
{
113
  if (!m_parent)
114
    {
115
      return m_child->GetPosition ();
116
    }
82
  Vector parentPosition = m_parent->GetPosition ();
117
  Vector parentPosition = m_parent->GetPosition ();
83
  Vector childPosition = m_child->GetPosition ();
118
  Vector childPosition = m_child->GetPosition ();
84
  return Vector (parentPosition.x + childPosition.x,
119
  return Vector (parentPosition.x + childPosition.x,
 Lines 88-114    Link Here 
88
void 
123
void 
89
HierarchicalMobilityModel::DoSetPosition (const Vector &position)
124
HierarchicalMobilityModel::DoSetPosition (const Vector &position)
90
{
125
{
91
  if (m_parent == 0 || m_child == 0)
126
  if (m_child == 0)
92
    {
127
    {
93
      return;
128
      return;
94
    }
129
    }
95
  // This implementation of DoSetPosition is really an arbitraty choice.
130
  // This implementation of DoSetPosition is really an arbitraty choice.
96
  // anything else would have been ok.
131
  // anything else would have been ok.
97
  Vector parentPosition = m_parent->GetPosition ();
132
  if (m_parent)
98
  Vector childPosition (position.x - parentPosition.x,
133
    {
99
			  position.y - parentPosition.y,
134
      Vector parentPosition = m_parent->GetPosition ();
100
			  position.z - parentPosition.z);
135
      Vector childPosition (position.x - parentPosition.x,
101
  m_child->SetPosition (childPosition);
136
                            position.y - parentPosition.y,
137
                            position.z - parentPosition.z);
138
      m_child->SetPosition (childPosition);
139
    }
140
  else
141
    {
142
      m_child->SetPosition (position);
143
    }
102
}
144
}
103
Vector
145
Vector
104
HierarchicalMobilityModel::DoGetVelocity (void) const
146
HierarchicalMobilityModel::DoGetVelocity (void) const
105
{
147
{
106
  Vector parentSpeed = m_parent->GetVelocity ();
148
  if (m_parent)
107
  Vector childSpeed = m_child->GetVelocity ();
149
    {
108
  Vector speed (parentSpeed.x + childSpeed.x,
150
      Vector parentSpeed = m_parent->GetVelocity ();
109
               parentSpeed.y + childSpeed.y,
151
      Vector childSpeed = m_child->GetVelocity ();
110
               parentSpeed.z + childSpeed.z);
152
      Vector speed (parentSpeed.x + childSpeed.x,
111
  return speed;
153
                    parentSpeed.y + childSpeed.y,
154
                    parentSpeed.z + childSpeed.z);
155
      return speed;
156
    }
157
  else
158
    {
159
      return m_child->GetVelocity ();
160
    }
112
}
161
}
113
162
114
void 
163
void 

Return to bug 511