3 * Copyright 2005 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_SIMULATION_H
24 #define INCLUDED_SIMULATION_H
35 point(double x = 0, double y = 0) : d_x(x), d_y(y) {}
37 double x() const { return d_x; }
38 double y() const { return d_y; }
40 void set_x(double x) { d_x = x; }
41 void set_y(double y) { d_y = y; }
44 add(const point &p1, const point &p2)
46 return point(p1.x() + p2.x(),
51 sub(const point &p1, const point &p2)
53 return point(p1.x() - p2.x(), p1.y() - p2.y());
57 distance(const point &p1, const point &p2)
59 point d = point::sub(p1, p2);
60 return std::sqrt(d.x()*d.x() + d.y()*d.y());
71 dyn_object(point pos=point(0,0), point vel=point(0,0), const std::string name="")
72 : d_pos(pos), d_vel(vel), d_name(name) {}
74 virtual ~dyn_object() {}
76 point pos() const { return d_pos; }
77 point vel() const { return d_vel; }
78 std::string name() const { return d_name; }
80 void set_pos(point pos) { d_pos = pos; }
81 void set_vel(point vel) { d_vel = vel; }
83 virtual bool update(double delta_t);
86 distance(const dyn_object &o1, const dyn_object &o2)
88 return point::distance(o1.pos(), o2.pos());
98 std::vector<dyn_object *> d_obj;
101 simulation(double timestep = 1.0, double now = 0.0)
102 : d_timestep(timestep), d_now(now) {}
103 virtual ~simulation();
104 virtual bool update();
105 virtual bool run(long long nsteps);
107 void add_object(dyn_object *obj);
108 double now() const { return d_now; }
109 double timestep() const { return d_timestep; }
112 std::ostream& operator<<(std::ostream& out, const dyn_object& o);
113 std::ostream& operator<<(std::ostream& out, const point& p);
115 #endif /* INCLUDED_SIMULATION_H */