Nsound  0.9.4
MeshJunction.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: MeshJunction.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2008 Nick Hilton
6 //
7 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
8 //
9 //-----------------------------------------------------------------------------
10 
11 //-----------------------------------------------------------------------------
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------------
28 
29 #include <Nsound/MeshJunction.h>
30 
31 #include <iostream>
32 
33 using namespace Nsound;
34 
35 using std::cout;
36 using std::cerr;
37 using std::endl;
38 
39 //-----------------------------------------------------------------------------
42  const float64 & leak_gain,
43  const float64 & tau,
44  const float64 & delta,
45  const float64 & gamma)
46  :
47  leak_gain_(leak_gain),
48  velocity_(0.0),
49  velocity_north_(0.0),
50  velocity_south_(0.0),
51  velocity_east_(0.0),
52  velocity_west_(0.0),
53  previous_velocity_(0.0),
54  previous_velocity_north_(0.0),
55  previous_velocity_south_(0.0),
56  previous_velocity_east_(0.0),
57  previous_velocity_west_(0.0),
58  vc_(0.0),
59  yj_(0.0),
60  yc_(0.0),
61  neighbor_north_(NULL),
62  neighbor_south_(NULL),
63  neighbor_east_(NULL),
64  neighbor_west_(NULL)
65 {
66  yj_ = 2.0 * ( (delta * delta) / (tau * tau * gamma * gamma) );
67  yc_ = 2.0 * ( (delta * delta) / (tau * tau * gamma * gamma) - 2.0);
68 
69  // Ensure the leak gain is negative.
70  if(leak_gain_ > 0.0)
71  {
72  leak_gain_ *= -1.0;
73  }
74 
75 //~ cout << "T = " << t << endl
76 //~ << "delta = " << delta << endl
77 //~ << "gamma = " << gamma << endl
78 //~ << "yj = " << yj_ << endl
79 //~ << "yc = " << yc_ << endl;
80 }
81 
82 //-----------------------------------------------------------------------------
85  :
86  leak_gain_(0.0),
87  velocity_(0.0),
88  velocity_north_(0.0),
89  velocity_south_(0.0),
90  velocity_east_(0.0),
91  velocity_west_(0.0),
92  previous_velocity_(0.0),
93  previous_velocity_north_(0.0),
94  previous_velocity_south_(0.0),
95  previous_velocity_east_(0.0),
96  previous_velocity_west_(0.0),
97  vc_(0.0),
98  yj_(0.0),
99  yc_(0.0),
100  neighbor_north_(NULL),
101  neighbor_south_(NULL),
102  neighbor_east_(NULL),
103  neighbor_west_(NULL)
104 {
105  *this = copy;
106  // This operator can not assign neighbor pointers.
107 }
108 
109 //-----------------------------------------------------------------------------
112 {
113 }
114 
115 void
118 {
119  velocity_ =
129 }
130 
131 float64
133 getVelocity() const
134 {
135  return velocity_;
136 }
137 
138 //-----------------------------------------------------------------------------
139 MeshJunction &
142 {
143  if(this == & rhs)
144  {
145  return *this;
146  }
147 
148  leak_gain_ = rhs.leak_gain_;
149 
150  velocity_ = rhs.velocity_;
151 
156 
162 
163  vc_ = rhs.vc_;
164  yj_ = rhs.yj_;
165  yc_ = rhs.yc_;
166 
167  // This operator can not assign neighbor pointers.
168 
169  return *this;
170 }
171 
172 void
175 {
176  neighbor_north_ = ptr;
177 }
178 
179 void
182 {
183  neighbor_south_ = ptr;
184 }
185 
186 void
189 {
190  neighbor_east_ = ptr;
191 }
192 
193 void
196 {
197  neighbor_west_ = ptr;
198 }
199 
200 void
202 strike(const float64 & velocity)
203 {
204  velocity_ += velocity;
205 
206  velocity_north_ += yj_ / 8.0 * velocity;
207  velocity_south_ += yj_ / 8.0 * velocity;
208  velocity_east_ += yj_ / 8.0 * velocity;
209  velocity_west_ += yj_ / 8.0 * velocity;
210 }
211 
212 void
215 {
221 }
222 
223 void
226 {
231  + yc_ * vc_);
232 
233  if(neighbor_north_)
234  {
236  }
237 
238  if(neighbor_south_)
239  {
241  }
242 
243  if(neighbor_west_)
244  {
246  }
247 
248  if(neighbor_east_)
249  {
251  }
252 
253  vc_ = velocity_ - vc_;
254 
255  updateBoundry();
256 
257 }
258 
259 
260 void
263 {
264  if(neighbor_north_ == NULL)
265  {
266  float64 vtemp = velocity_north_;
267 
269 
270  if(neighbor_south_)
271  {
273  }
274 
275  }
276 
277  if(neighbor_south_ == NULL)
278  {
279  float64 vtemp = velocity_south_;
280 
282 
283  if(neighbor_north_)
284  {
286  }
287 
288  }
289 
290  if(neighbor_east_ == NULL)
291  {
292  float64 vtemp = velocity_east_;
293 
295 
296  if(neighbor_west_)
297  {
299  }
300 
301  }
302 
303  if(neighbor_west_ == NULL)
304  {
305  float64 vtemp = velocity_west_;
306 
308 
309  if(neighbor_east_)
310  {
312  }
313 
314  }
315 }
316 
float64 velocity_south_
Velocity going north.
Definition: MeshJunction.h:107
float64 previous_velocity_south_
Definition: MeshJunction.h:113
void updateVelocity()
updates junction velocity.
MeshJunction(const float64 &leak_gain, const float64 &tau, const float64 &delta, const float64 &gamma)
Constructor.
Definition: MeshJunction.cc:41
float64 previous_velocity_east_
Definition: MeshJunction.h:114
void strike(const float64 &velocity)
Adds velocity to this junction.
float64 leak_gain_
updates junction velocity.
Definition: MeshJunction.h:102
MeshJunction * neighbor_west_
Definition: MeshJunction.h:124
MeshJunction * neighbor_south_
Definition: MeshJunction.h:122
void setNeighborNorth(MeshJunction *ptr)
float64 velocity_east_
Velocity going south.
Definition: MeshJunction.h:108
float64 velocity_
Leak gain.
Definition: MeshJunction.h:104
double float64
Definition: Nsound.h:146
void setNeighborEast(MeshJunction *ptr)
void setNeighborSouth(MeshJunction *ptr)
float64 velocity_west_
Velocity going east.
Definition: MeshJunction.h:109
MeshJunction & operator=(const MeshJunction &rhs)
This operator can not assign neighbor pointers.
MeshJunction * neighbor_east_
Definition: MeshJunction.h:123
float64 previous_velocity_west_
Definition: MeshJunction.h:115
void setNeighborWest(MeshJunction *ptr)
float64 getVelocity() const
float64 previous_velocity_north_
Definition: MeshJunction.h:112
float64 velocity_north_
This junction's velocity.
Definition: MeshJunction.h:106
void saveState()
Saves previous south and east velocities.
~MeshJunction()
Deconstructor.
void clear()
Clears all velicityes in the junctino.
float64 previous_velocity_
Velocity going west.
Definition: MeshJunction.h:111
MeshJunction * neighbor_north_
Definition: MeshJunction.h:121