Panda3D
|
00001 // Filename: physicsManager.h 00002 // Created by: charles (14Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PHYSICSMANAGER_H 00016 #define PHYSICSMANAGER_H 00017 00018 #include "pandabase.h" 00019 #include "pointerTo.h" 00020 00021 #include "physical.h" 00022 #include "linearForce.h" 00023 #include "angularForce.h" 00024 #include "linearIntegrator.h" 00025 #include "angularIntegrator.h" 00026 #include "physicalNode.h" 00027 00028 #include "plist.h" 00029 #include "pvector.h" 00030 00031 #include "configVariableInt.h" 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Class : PhysicsManager 00035 // Description : Physics don't get much higher-level than this. 00036 // Attach as many Physicals (particle systems, etc..) 00037 // as you want, pick an integrator and go. 00038 //////////////////////////////////////////////////////////////////// 00039 class EXPCL_PANDAPHYSICS PhysicsManager { 00040 public: 00041 // NOTE that the physicals container is NOT reference counted. 00042 // this does indeed mean that you are NOT supposed to use this 00043 // as a primary storage container for the physicals. This is so 00044 // because physicals, on their death, ask to be removed from their 00045 // current physicsmanager, if one exists, relieving the client from 00046 // the task and also allowing for dynamically created and destroyed 00047 // physicals. 00048 typedef pvector<Physical *> PhysicalsVector; 00049 typedef pvector<PT(LinearForce)> LinearForceVector; 00050 typedef pvector<PT(AngularForce)> AngularForceVector; 00051 00052 PUBLISHED: 00053 PhysicsManager(); 00054 virtual ~PhysicsManager(); 00055 00056 INLINE void attach_linear_integrator(LinearIntegrator *i); 00057 INLINE void attach_angular_integrator(AngularIntegrator *i); 00058 INLINE void attach_physical(Physical *p); 00059 INLINE void attach_physicalnode(PhysicalNode *p); // use attach_physical_node instead. 00060 INLINE void attach_physical_node(PhysicalNode *p); 00061 INLINE void add_linear_force(LinearForce *f); 00062 INLINE void add_angular_force(AngularForce *f); 00063 INLINE void clear_linear_forces(); 00064 INLINE void clear_angular_forces(); 00065 INLINE void clear_physicals(); 00066 00067 INLINE void set_viscosity(PN_stdfloat viscosity); 00068 INLINE PN_stdfloat get_viscosity() const; 00069 00070 void remove_physical(Physical *p); 00071 void remove_physical_node(PhysicalNode *p); 00072 void remove_linear_force(LinearForce *f); 00073 void remove_angular_force(AngularForce *f); 00074 void do_physics(PN_stdfloat dt); 00075 void do_physics(PN_stdfloat dt, Physical *p); 00076 void init_random_seed(); 00077 00078 virtual void output(ostream &out) const; 00079 virtual void write_physicals(ostream &out, unsigned int indent=0) const; 00080 virtual void write_linear_forces(ostream &out, unsigned int indent=0) const; 00081 virtual void write_angular_forces(ostream &out, unsigned int indent=0) const; 00082 virtual void write(ostream &out, unsigned int indent=0) const; 00083 00084 virtual void debug_output(ostream &out, unsigned int indent=0) const; 00085 00086 public: 00087 friend class Physical; 00088 static ConfigVariableInt _random_seed; 00089 00090 private: 00091 PN_stdfloat _viscosity; 00092 PhysicalsVector _physicals; 00093 LinearForceVector _linear_forces; 00094 AngularForceVector _angular_forces; 00095 00096 PT(LinearIntegrator) _linear_integrator; 00097 PT(AngularIntegrator) _angular_integrator; 00098 }; 00099 00100 #include "physicsManager.I" 00101 00102 #endif // PHYSICSMANAGER_H