Imported vanilla contents from upstream
[construo.git] / particle.hxx
blob216af2d2fe4477223968e0c427782f5c1ebf1000
1 // $Id: particle.hxx,v 1.16 2003/07/27 18:46:11 grumbel Exp $
2 //
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef HEADER_CONSTRUO_PARTICLE_HXX
21 #define HEADER_CONSTRUO_PARTICLE_HXX
23 #include <iostream>
24 #include "lisp_writer.hxx"
25 #include "construo.hxx"
26 #include "zoom_graphic_context.hxx"
27 #include "vector2d.hxx"
29 class Particle
31 private:
32 /** Id of the particle */
33 int id;
35 public:
36 /** position of the particle */
37 Vector2d pos;
39 /** velocity of the particle */
40 Vector2d velocity;
42 private:
43 /** the mass of the particle as 1/mass (FIXME: is this still the
44 case?!) */
45 float mass;
46 public:
47 /** If true the particle will have a fixed position which cannot be
48 changed, if false the particle reacts to forces as normal. */
49 bool fixed;
51 /** totale force acting on particle (used as temp-var in update() to
52 collect the forces)*/
53 Vector2d totale_force;
55 /** Number of connection this particle has to other springs */
56 int spring_links;
58 /** The id of the particle, used for de/serialisation and copying of
59 the World. The id is uniq only for a single world. */
60 inline int get_id () const {
61 return id;
64 void add_force (const Vector2d& force)
66 if (fixed) return;
67 totale_force += force;
70 void clear_force ()
72 totale_force = Vector2d ();
75 void set_fixed (bool f) {
76 fixed = f;
79 bool get_fixed () {
80 return fixed;
83 inline float get_mass () const { return mass; }
85 void update (float delta);
86 void draw (ZoomGraphicContext* gc);
88 /** draws the particle in highlight mode (aka if mouse is over it) */
89 void draw_highlight (ZoomGraphicContext* gc);
91 /** draws additional infos to this stop */
92 void draw_infos (ZoomGraphicContext* gc);
94 void draw_velocity_vector (ZoomGraphicContext* gc);
96 lisp_object_t* serialize();
98 friend class ParticleFactory;
100 private:
101 // Nobody beside the ParticleFactory can create particles
102 Particle (int id_, const Vector2d& arg_pos, const Vector2d& arg_velocity, float mass_, bool fixed_);
103 Particle (const Particle&);
106 #endif
108 /* EOF */