From ad4be177e2486453a36b2bbff1bb4ee3b04b2f65 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Fri, 25 Jul 2003 22:02:18 +0000 Subject: [PATCH] added viscosity --- panda/src/physics/physical.I | 21 ++++++++++++++++++ panda/src/physics/physical.cxx | 39 +++++++++++++++++----------------- panda/src/physics/physical.h | 6 +++++- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/panda/src/physics/physical.I b/panda/src/physics/physical.I index 8e74175a40..b1d7bfdce9 100644 --- a/panda/src/physics/physical.I +++ b/panda/src/physics/physical.I @@ -210,3 +210,24 @@ get_angular_force(int index) const { nassertr(index >= 0 && index < (int)_angular_forces.size(), NULL); return _angular_forces[index]; } + +//////////////////////////////////////////////////////////////////// +// Function : set_viscosity +// Access : Public +// Description : Set the local viscosity. +//////////////////////////////////////////////////////////////////// +INLINE void Physical:: +set_viscosity(float viscosity) { + _viscosity=viscosity; +} + +//////////////////////////////////////////////////////////////////// +// Function : get_viscosity +// Access : Public +// Description : Get the local viscosity. +//////////////////////////////////////////////////////////////////// +INLINE float Physical:: +get_viscosity() const { + //zzzzzzzzzzzzzzzz return max(_viscosity, get_physics_manager()->get_viscosity()); + return _viscosity; +} diff --git a/panda/src/physics/physical.cxx b/panda/src/physics/physical.cxx index 2dda7f7675..00fff9365b 100644 --- a/panda/src/physics/physical.cxx +++ b/panda/src/physics/physical.cxx @@ -23,40 +23,39 @@ TypeHandle Physical::_type_handle; -// the idea here is that most physicals will NOT be collections of -// sets (i.e. particle systems and whatever else). Because of this, -// the default constructor, unless otherwise specified, will -// automatically allocate and initialize one PhysicalObject. -// this makes it easier for high-level work. - -// pre-alloc is ONLY for multiple-object physicals, and if true, -// fills the physics_object vector with dead nodes, pre-allocating -// for the speed end of the speed-vs-overhead deal. - //////////////////////////////////////////////////////////////////// // Function : Physical // Access : Public // Description : Default Constructor +// +// The idea here is that most physicals will NOT +// be collections of sets (i.e. particle systems +// and whatever else). Because of this, the default +// constructor, unless otherwise specified, will +// automatically allocate and initialize one +// PhysicalObject. This makes it easier for +// high-level work. +// +// pre-alloc is ONLY for multiple-object physicals, +// and if true, fills the physics_object vector +// with dead nodes, pre-allocating for the speed +// end of the speed-vs-overhead deal. //////////////////////////////////////////////////////////////////// Physical:: -Physical(int ttl_objects, bool pre_alloc) { +Physical(int total_objects, bool pre_alloc) { + _viscosity=0.0; _physical_node = (PhysicalNode *) NULL; _physics_manager = (PhysicsManager *) NULL; - if (ttl_objects == 1) { + if (total_objects == 1) { _phys_body = new PhysicsObject; add_physics_object(_phys_body); - } - else { - int i; + } else { _phys_body = (PhysicsObject *) NULL; - // allocate each object. if (pre_alloc == true) { - PhysicsObject *po; - - for (i = 0; i < ttl_objects; i++) { - po = new PhysicsObject; + for (int i = 0; i < total_objects; ++i) { + PhysicsObject *po = new PhysicsObject; add_physics_object(po); } } diff --git a/panda/src/physics/physical.h b/panda/src/physics/physical.h index 4d9fe9c0c8..d1864046d6 100644 --- a/panda/src/physics/physical.h +++ b/panda/src/physics/physical.h @@ -41,7 +41,7 @@ class PhysicsManager; //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSICS Physical : public TypedReferenceCount { PUBLISHED: - Physical(int ttl_objects = 1, bool pre_alloc = false); + Physical(int total_objects = 1, bool pre_alloc = false); Physical(const Physical& copy); virtual ~Physical(); @@ -64,6 +64,9 @@ PUBLISHED: INLINE PT(LinearForce) get_linear_force(int index) const; INLINE int get_num_angular_forces() const; INLINE PT(AngularForce) get_angular_force(int index) const; + + INLINE void set_viscosity(float viscosity); + INLINE float get_viscosity() const; virtual void output(ostream &out) const; virtual void write_physics_objects(ostream &out, unsigned int indent=0) const; @@ -84,6 +87,7 @@ public: friend class PhysicalNode; protected: + float _viscosity; // containers PhysicsObjectVector _physics_objects; LinearForceVector _linear_forces;