Panda3D
physicsManager.h
1 // Filename: physicsManager.h
2 // Created by: charles (14Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PHYSICSMANAGER_H
16 #define PHYSICSMANAGER_H
17 
18 #include "pandabase.h"
19 #include "pointerTo.h"
20 
21 #include "physical.h"
22 #include "linearForce.h"
23 #include "angularForce.h"
24 #include "linearIntegrator.h"
25 #include "angularIntegrator.h"
26 #include "physicalNode.h"
27 
28 #include "plist.h"
29 #include "pvector.h"
30 
31 #include "configVariableInt.h"
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : PhysicsManager
35 // Description : Physics don't get much higher-level than this.
36 // Attach as many Physicals (particle systems, etc..)
37 // as you want, pick an integrator and go.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDAPHYSICS PhysicsManager {
40 public:
41  // NOTE that the physicals container is NOT reference counted.
42  // this does indeed mean that you are NOT supposed to use this
43  // as a primary storage container for the physicals. This is so
44  // because physicals, on their death, ask to be removed from their
45  // current physicsmanager, if one exists, relieving the client from
46  // the task and also allowing for dynamically created and destroyed
47  // physicals.
51 
52 PUBLISHED:
54  virtual ~PhysicsManager();
55 
56  INLINE void attach_linear_integrator(LinearIntegrator *i);
57  INLINE void attach_angular_integrator(AngularIntegrator *i);
58  INLINE void attach_physical(Physical *p);
59  INLINE void attach_physicalnode(PhysicalNode *p); // use attach_physical_node instead.
60  INLINE void attach_physical_node(PhysicalNode *p);
61  INLINE void add_linear_force(LinearForce *f);
62  INLINE void add_angular_force(AngularForce *f);
63  INLINE void clear_linear_forces();
64  INLINE void clear_angular_forces();
65  INLINE void clear_physicals();
66 
67  INLINE void set_viscosity(PN_stdfloat viscosity);
68  INLINE PN_stdfloat get_viscosity() const;
69 
70  void remove_physical(Physical *p);
71  void remove_physical_node(PhysicalNode *p);
72  void remove_linear_force(LinearForce *f);
73  void remove_angular_force(AngularForce *f);
74  void do_physics(PN_stdfloat dt);
75  void do_physics(PN_stdfloat dt, Physical *p);
76  void init_random_seed();
77 
78  virtual void output(ostream &out) const;
79  virtual void write_physicals(ostream &out, unsigned int indent=0) const;
80  virtual void write_linear_forces(ostream &out, unsigned int indent=0) const;
81  virtual void write_angular_forces(ostream &out, unsigned int indent=0) const;
82  virtual void write(ostream &out, unsigned int indent=0) const;
83 
84  virtual void debug_output(ostream &out, unsigned int indent=0) const;
85 
86 public:
87  friend class Physical;
88  static ConfigVariableInt _random_seed;
89 
90 private:
91  PN_stdfloat _viscosity;
92  PhysicalsVector _physicals;
93  LinearForceVector _linear_forces;
94  AngularForceVector _angular_forces;
95 
96  PT(LinearIntegrator) _linear_integrator;
97  PT(AngularIntegrator) _angular_integrator;
98 };
99 
100 #include "physicsManager.I"
101 
102 #endif // PHYSICSMANAGER_H
Pure virtual base class for physical modeling.
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:25
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:31
Physics don't get much higher-level than this.
Defines a set of physically modeled attributes.
Definition: physical.h:40
pure virtual parent of all quat-based forces.
Definition: angularForce.h:24
Pure virtual base class for physical modeling.
This is a convenience class to specialize ConfigVariable as an integer type.