Explorar o código

added viscosity

Dave Schuyler %!s(int64=22) %!d(string=hai) anos
pai
achega
ad4be177e2
Modificáronse 3 ficheiros con 45 adicións e 21 borrados
  1. 21 0
      panda/src/physics/physical.I
  2. 19 20
      panda/src/physics/physical.cxx
  3. 5 1
      panda/src/physics/physical.h

+ 21 - 0
panda/src/physics/physical.I

@@ -210,3 +210,24 @@ get_angular_force(int index) const {
   nassertr(index >= 0 && index < (int)_angular_forces.size(), NULL);
   nassertr(index >= 0 && index < (int)_angular_forces.size(), NULL);
   return _angular_forces[index];
   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;
+}

+ 19 - 20
panda/src/physics/physical.cxx

@@ -23,40 +23,39 @@
 
 
 TypeHandle Physical::_type_handle;
 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
 //     Function : Physical
 //       Access : Public
 //       Access : Public
 //  Description : Default Constructor
 //  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::
-Physical(int ttl_objects, bool pre_alloc) {
+Physical(int total_objects, bool pre_alloc) {
+  _viscosity=0.0;
   _physical_node = (PhysicalNode *) NULL;
   _physical_node = (PhysicalNode *) NULL;
   _physics_manager = (PhysicsManager *) NULL;
   _physics_manager = (PhysicsManager *) NULL;
 
 
-  if (ttl_objects == 1) {
+  if (total_objects == 1) {
     _phys_body = new PhysicsObject;
     _phys_body = new PhysicsObject;
     add_physics_object(_phys_body);
     add_physics_object(_phys_body);
-  }
-  else {
-    int i;
+  } else {
     _phys_body = (PhysicsObject *) NULL;
     _phys_body = (PhysicsObject *) NULL;
-
     // allocate each object.
     // allocate each object.
     if (pre_alloc == true) {
     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);
         add_physics_object(po);
       }
       }
     }
     }

+ 5 - 1
panda/src/physics/physical.h

@@ -41,7 +41,7 @@ class PhysicsManager;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDAPHYSICS Physical : public TypedReferenceCount {
 class EXPCL_PANDAPHYSICS Physical : public TypedReferenceCount {
 PUBLISHED:
 PUBLISHED:
-  Physical(int ttl_objects = 1, bool pre_alloc = false);
+  Physical(int total_objects = 1, bool pre_alloc = false);
   Physical(const Physical& copy);
   Physical(const Physical& copy);
 
 
   virtual ~Physical();
   virtual ~Physical();
@@ -64,6 +64,9 @@ PUBLISHED:
   INLINE PT(LinearForce) get_linear_force(int index) const;
   INLINE PT(LinearForce) get_linear_force(int index) const;
   INLINE int get_num_angular_forces() const;
   INLINE int get_num_angular_forces() const;
   INLINE PT(AngularForce) get_angular_force(int index) 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 output(ostream &out) const;
   virtual void write_physics_objects(ostream &out, unsigned int indent=0) const;
   virtual void write_physics_objects(ostream &out, unsigned int indent=0) const;
@@ -84,6 +87,7 @@ public:
   friend class PhysicalNode;
   friend class PhysicalNode;
 
 
 protected:
 protected:
+  float _viscosity;
   // containers
   // containers
   PhysicsObjectVector _physics_objects;
   PhysicsObjectVector _physics_objects;
   LinearForceVector _linear_forces;
   LinearForceVector _linear_forces;