Browse Source

hooking physics to collisions

Dave Schuyler 22 years ago
parent
commit
7946536511

+ 10 - 6
panda/src/physics/Sources.pp

@@ -4,7 +4,7 @@
 #begin lib_target
   #define TARGET physics
   #define LOCAL_LIBS \
-    pgraph linmath
+    pgraph linmath collide
     
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx    
  
@@ -22,8 +22,10 @@
      linearSinkForce.h linearSourceForce.h \
      linearUserDefinedForce.I linearUserDefinedForce.h \
      linearVectorForce.I linearVectorForce.h physical.I \
-     physical.h physicalNode.I physicalNode.h physicsManager.I \
-     physicsManager.h physicsObject.I physicsObject.h
+     physical.h physicalNode.I physicalNode.h \
+     physicsCollisionHandler.I physicsCollisionHandler.h \
+     physicsManager.I physicsManager.h \
+     physicsObject.I physicsObject.h
 
   #define INCLUDED_SOURCES \
      actorNode.cxx angularEulerIntegrator.cxx angularForce.cxx \
@@ -36,7 +38,7 @@
      linearRandomForce.cxx linearSinkForce.cxx \
      linearSourceForce.cxx linearUserDefinedForce.cxx \
      linearVectorForce.cxx physical.cxx physicalNode.cxx \
-     physicsManager.cxx physicsObject.cxx 
+     physicsCollisionHandler.cxx physicsManager.cxx physicsObject.cxx 
 
   #define INSTALL_HEADERS \
     actorNode.I actorNode.h angularEulerIntegrator.h angularForce.h \
@@ -51,7 +53,9 @@
     linearRandomForce.h linearSinkForce.h linearSourceForce.h \
     linearUserDefinedForce.I linearUserDefinedForce.h \
     linearVectorForce.I linearVectorForce.h physical.I physical.h \
-    physicalNode.I physicalNode.h physicsManager.I physicsManager.h \
+    physicalNode.I physicalNode.h \
+    physicsCollisionHandler.I physicsCollisionHandler.h \
+    physicsManager.I physicsManager.h \
     physicsObject.I physicsObject.h
 
   #define IGATESCAN all
@@ -61,7 +65,7 @@
 #begin test_bin_target
   #define TARGET test_physics
   #define LOCAL_LIBS \
-    linmath physics
+    linmath physics collide
 
   #define SOURCES \
     test_physics.cxx

+ 3 - 1
panda/src/physics/actorNode.cxx

@@ -31,7 +31,7 @@ TypeHandle ActorNode::_type_handle;
 ////////////////////////////////////////////////////////////////////
 ActorNode::
 ActorNode(const string &name) :
-  PhysicalNode(name) {
+    PhysicalNode(name) {
   add_physical(new Physical(1, true));
   _mass_center = get_physical(0)->get_phys_body();
   _mass_center->set_active(true);
@@ -64,6 +64,7 @@ ActorNode::
 //       Access : public
 //  Description : this sets the transform generated by the contained
 //                Physical, moving the node and subsequent geometry.
+//                i.e. copy from PhysicsObject to PandaNode
 ////////////////////////////////////////////////////////////////////
 void ActorNode::
 update_transform() {
@@ -81,6 +82,7 @@ update_transform() {
 //  Description : node hook.  This function handles outside
 //                (non-physics) actions on the actor
 //                and updates the internal representation of the node.
+//                i.e. copy from PandaNode to PhysicsObject
 ////////////////////////////////////////////////////////////////////
 void ActorNode::
 transform_changed() {

+ 9 - 6
panda/src/physics/actorNode.h

@@ -32,25 +32,28 @@
 //               object's position (shoves).
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDAPHYSICS ActorNode : public PhysicalNode {
-public:
+PUBLISHED:
   ActorNode(const string &name = "");
   ActorNode(const ActorNode &copy);
   virtual ~ActorNode();
+  
+  PhysicsObject *get_physics_object() { return _mass_center; }
 
-  // update the parent arc with PhysicsObject information
+  // update the parent scene graph node with PhysicsObject information
+  // i.e. copy from PhysicsObject to PandaNode
   void update_transform();
   
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, unsigned int indent=0) const;
 
 private:
-  // node hook if the client changes the node's transform.
-  virtual void transform_changed();
-
   PhysicsObject *_mass_center;
-
   bool _ok_to_callback;
 
+  // node hook if the client changes the node's transform.
+  // i.e. copy from PandaNode to PhysicsObject
+  virtual void transform_changed();
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 5 - 3
panda/src/physics/baseIntegrator.cxx

@@ -50,9 +50,10 @@ BaseIntegrator::
 void BaseIntegrator::
 precompute_linear_matrices(Physical *physical,
                            const pvector< PT(LinearForce) > &forces) {
+  nassertv(physical);
   // make sure the physical's in the scene graph, somewhere.
   PhysicalNode *physical_node = physical->get_physical_node();
-  nassertv(physical_node != NULL);
+  nassertv(physical_node);
 
   // by global forces, we mean forces not contained in the physical
   int global_force_vec_size = forces.size();
@@ -70,7 +71,7 @@ precompute_linear_matrices(Physical *physical,
   NodePath physical_np(physical_node);
 
   // tally the global xforms
-  for (i = 0; i < global_force_vec_size; i++) {
+  for (i = 0; i < global_force_vec_size; ++i) {
     force_node = forces[i]->get_force_node();
     nassertv(force_node != (ForceNode *) NULL);
 
@@ -82,7 +83,7 @@ precompute_linear_matrices(Physical *physical,
     physical->get_linear_forces();
 
   // tally the local xforms
-  for (i = 0; i < local_force_vec_size; i++) {
+  for (i = 0; i < local_force_vec_size; ++i) {
     force_node = force_vector[i]->get_force_node();
     nassertv(force_node != (ForceNode *) NULL);
 
@@ -102,6 +103,7 @@ precompute_linear_matrices(Physical *physical,
 void BaseIntegrator::
 precompute_angular_matrices(Physical *physical,
                             const pvector< PT(AngularForce) > &forces) {
+  nassertv(physical);
   // make sure the physical's in the scene graph, somewhere.
   PhysicalNode *physical_node = physical->get_physical_node();
   nassertv(physical_node != NULL);

+ 1 - 1
panda/src/physics/forceNode.I

@@ -41,7 +41,7 @@ get_force(int index) const {
 //    Access : public
 ////////////////////////////////////////////////////////////////////
 INLINE int ForceNode::
-get_num_forces(void) const {
+get_num_forces() const {
   return _forces.size();
 }
 

+ 33 - 15
panda/src/physics/linearEulerIntegrator.cxx

@@ -82,14 +82,21 @@ child_integrate(Physical *physical,
 
     // bail out if this object doesn't exist or doesn't want to be
     // processed.
-    if (current_object == (PhysicsObject *) NULL)
+    if (current_object == (PhysicsObject *) NULL) {
       continue;
-
-    if (current_object->get_active() == false)
+    }
+    
+    if (current_object->get_active() == false) {
       continue;
-
+    }
+    
+    LVector3f md_accum_vec;
+    LVector3f non_md_accum_vec;
+    LVector3f accel_vec;
+    LVector3f vel_vec;
+    
+    
     // reset the accumulation vectors for this object
-    LVector3f md_accum_vec, non_md_accum_vec, accel_vec, vel_vec;
     md_accum_vec.set(0.0f, 0.0f, 0.0f);
     non_md_accum_vec.set(0.0f, 0.0f, 0.0f);
 
@@ -103,44 +110,46 @@ child_integrate(Physical *physical,
     // global forces
     f_cur = forces.begin();
     int index = 0;
-    for (; f_cur != forces.end(); f_cur++) {
+    for (; f_cur != forces.end(); ++f_cur) {
       LinearForce *cur_force = *f_cur;
 
       // make sure the force is turned on.
-      if (cur_force->get_active() == false)
+      if (cur_force->get_active() == false) {
         continue;
-
+      }
       force_node = cur_force->get_force_node();
 
       // now we go from force space to our object's space.
       f = cur_force->get_vector(current_object) * matrices[index++];
 
       // tally it into the accum vectors.
-      if (cur_force->get_mass_dependent() == true)
+      if (cur_force->get_mass_dependent() == true) {
         md_accum_vec += f;
-      else
+      } else {
         non_md_accum_vec += f;
+      }
     }
 
     // local forces
     f_cur = physical->get_linear_forces().begin();
-    for (; f_cur != physical->get_linear_forces().end(); f_cur++) {
+    for (; f_cur != physical->get_linear_forces().end(); ++f_cur) {
       LinearForce *cur_force = *f_cur;
 
       // make sure the force is turned on.
-      if (cur_force->get_active() == false)
+      if (cur_force->get_active() == false) {
         continue;
-
+      }
       force_node = cur_force->get_force_node();
 
       // go from force space to object space
       f = cur_force->get_vector(current_object) * matrices[index++];
 
       // tally it into the accum vectors
-      if (cur_force->get_mass_dependent() == true)
+      if (cur_force->get_mass_dependent() == true) {
         md_accum_vec += f;
-      else
+      } else {
         non_md_accum_vec += f;
+      }
     }
 
     // get this object's physical info
@@ -155,6 +164,7 @@ child_integrate(Physical *physical,
     accel_vec = md_accum_vec / mass;
     accel_vec += non_md_accum_vec;
 
+    #if 0 //[
     // step the position and velocity
     vel_vec += accel_vec * dt;
 
@@ -167,6 +177,14 @@ child_integrate(Physical *physical,
     }
 
     pos += vel_vec * dt;
+    #else //][
+    assert(current_object->get_position()==current_object->get_last_position());
+    
+    // x = x + v * t + 0.5 * a * t * t
+    pos += vel_vec * dt + 0.5 * accel_vec * dt * dt;
+    // v = v + a * t
+    vel_vec += accel_vec * dt;
+    #endif //]
 
     // and store them back.
     current_object->set_position(pos);

+ 1 - 1
panda/src/physics/linearForce.h

@@ -34,7 +34,7 @@ PUBLISHED:
   INLINE void set_mass_dependent(bool m);
 
   INLINE float get_amplitude() const;
-  INLINE bool get_mass_dependent(void) const;
+  INLINE bool get_mass_dependent() const;
 
   INLINE void set_vector_masks(bool x, bool y, bool z);
 

+ 13 - 1
panda/src/physics/linearVectorForce.I

@@ -42,6 +42,18 @@ set_vector(float x, float y, float z) {
 // Description :
 ////////////////////////////////////////////////////////////////////
 INLINE LVector3f LinearVectorForce::
-get_local_vector(void) const {
+get_local_vector() const {
   return _fvec;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: LinearVectorForce::LinearVectorForce += LinearVectorForce
+//       Access: Public
+//  Description: Performs a memberwise addition between two LinearVectorForces.
+////////////////////////////////////////////////////////////////////
+LinearVectorForce& LinearVectorForce::
+operator += (const LinearVectorForce &other) {
+  _fvec+=other._fvec;
+  // Should something happen with _amplitude?
+  return *this;
+}

+ 4 - 1
panda/src/physics/linearVectorForce.h

@@ -32,7 +32,7 @@ PUBLISHED:
   LinearVectorForce(const LinearVectorForce &copy);
   LinearVectorForce(float x = 0.0f, float y = 0.0f, float z = 0.0f,
               float a = 1.0f, bool mass = false);
-  virtual ~LinearVectorForce(void);
+  virtual ~LinearVectorForce();
 
   INLINE void set_vector(const LVector3f& v);
   INLINE void set_vector(float x, float y, float z);
@@ -42,6 +42,9 @@ PUBLISHED:
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, unsigned int indent=0) const;
 
+public:
+  INLINE LinearVectorForce& operator += (const LinearVectorForce &other);
+
 private:
   LVector3f _fvec;
 

+ 3 - 3
panda/src/physics/physical.h

@@ -66,9 +66,9 @@ PUBLISHED:
   INLINE PT(AngularForce) get_angular_force(int index) const;
   
   virtual void output(ostream &out) const;
-  void write_physics_objects(ostream &out, unsigned int indent=0) const;
-  void write_linear_forces(ostream &out, unsigned int indent=0) const;
-  void write_angular_forces(ostream &out, unsigned int indent=0) const;
+  virtual void write_physics_objects(ostream &out, unsigned int indent=0) const;
+  virtual void write_linear_forces(ostream &out, unsigned int indent=0) const;
+  virtual void write_angular_forces(ostream &out, unsigned int indent=0) const;
   virtual void write(ostream &out, unsigned int indent=0) const;
 
 public:

+ 17 - 0
panda/src/physics/physicsCollisionHandler.I

@@ -0,0 +1,17 @@
+// Filename: physicsCollisionHandler.I
+// Created by:  drose (16Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////

+ 109 - 0
panda/src/physics/physicsCollisionHandler.cxx

@@ -0,0 +1,109 @@
+// Filename: physicsCollisionHandler.cxx
+// Created by:  drose (16Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "physicsCollisionHandler.h"
+#include "collisionNode.h"
+#include "collisionEntry.h"
+#include "collisionPolygon.h"
+#include "config_collide.h"
+#include "dcast.h"
+
+TypeHandle PhysicsCollisionHandler::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: PhysicsCollisionHandler::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+PhysicsCollisionHandler::
+PhysicsCollisionHandler() {
+  set_horizontal(false);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PhysicsCollisionHandler::Destructor
+//       Access: Public, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
+PhysicsCollisionHandler::
+~PhysicsCollisionHandler() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PhysicsCollisionHandler::apply_linear_force
+//       Access: Protected, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void PhysicsCollisionHandler::
+apply_linear_force(ColliderDef &def, const LVector3f &force) {
+  CollisionHandlerPusher::apply_linear_force(def, force);
+  if (force == LVector3f::zero()) {
+    return;
+  }
+  
+  if (def._node) {
+    ActorNode *actor=DCAST(ActorNode, def._node);
+    float friction=1.0f;
+    LVector3f vel=actor->get_physics_object()->get_velocity();
+    LVector3f old_vel=vel;
+    LVector3f adjustment=force;
+    adjustment.normalize();
+    adjustment*=adjustment.dot(vel);
+    #if 0 //[
+    float initialVelMag=vel.length();
+    float temp=((vel-c)*friction).length();
+    if ((vel-c)[2]) {
+      cerr<<"\n\napply_linear_force"
+          <<"\n  vel "<<vel<<" mag "<<initialVelMag
+          <<"\n  force "<<force<<" mag "<<force.length()
+          <<"\n  unitForce "<<unitForce<<" mag "<<unitForce.length()
+          <<"\n  c "<<c<<" mag "<<c.length()
+          <<"\n  vel "<<vel-c<<" mag "<<(vel-c).length()
+          <<"\n  friction "<<friction
+          <<"\n  vel "<<((vel-c)*friction)<<" mag "<<temp
+          <<"\n  initialVelMag > "<<(initialVelMag>temp)  
+          <<endl;
+      if (initialVelMag<temp) {
+        cerr<<"\n*************************************"<<endl;
+      }
+    }
+    #endif //]
+    float angle=adjustment.dot(vel);
+    vel-=adjustment;
+    if (angle<=0.0f) {
+      // ...avoid amplifying the velocity by checking to see
+      // that the adjustment and the velocity are more than 
+      // right-angles (i.e. obtuse angle).
+      float almostStationary=1.0f;
+      if (vel.dot(vel)>almostStationary) {
+        friction*=0.01f; cerr<<"not almostStationary"<<endl;
+      }
+      //vel*=1.0f-friction;
+    }
+    
+    LVector3f new_vel=vel;
+    if (vel.length() > old_vel.length()) {
+      cerr<<"\nvel.length() > old_vel.length()  "<<vel.length()<<" > "<<old_vel.length()<<endl;
+    }
+    if (vel.length() > 10.0f) {
+      cerr<<"\nvel.length() > 10.0f  "<<vel.length()<<endl;
+    }
+    
+    actor->get_physics_object()->set_velocity(vel);
+  }
+}

+ 63 - 0
panda/src/physics/physicsCollisionHandler.h

@@ -0,0 +1,63 @@
+// Filename: physicsCollisionHandler.h
+// Created by:  drose (16Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef PHYSICSCOLLISIONHANDLER_H
+#define PHYSICSCOLLISIONHANDLER_H
+
+#include "pandabase.h"
+
+#include "collisionHandlerPusher.h"
+
+///////////////////////////////////////////////////////////////////
+//       Class : PhysicsCollisionHandler
+// Description : A specialized kind of CollisionHandler that simply
+//               pushes back on things that attempt to move into solid
+//               walls.  This also puts forces onto the physics objects
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAPHYSICS PhysicsCollisionHandler : public CollisionHandlerPusher {
+PUBLISHED:
+  PhysicsCollisionHandler();
+  virtual ~PhysicsCollisionHandler();
+
+protected:
+  virtual void apply_linear_force(ColliderDef &def, const LVector3f &force);
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CollisionHandlerPusher::init_type();
+    register_type(_type_handle, "PhysicsCollisionHandler",
+                  CollisionHandlerPusher::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "physicsCollisionHandler.I"
+
+#endif
+
+
+

+ 9 - 3
panda/src/physics/physicsManager.I

@@ -23,6 +23,7 @@
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
 attach_physical(Physical *p) {
+  nassertv(p);
   p->_physics_manager = this;
   pvector< Physical * >::iterator found;
   found = find(_physicals.begin(), _physicals.end(), p);
@@ -37,6 +38,7 @@ attach_physical(Physical *p) {
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
 add_linear_force(LinearForce *f) {
+  nassertv(f);
   pvector< PT(LinearForce) >::iterator found;
   PT(LinearForce) ptlf = f;
   found = find(_linear_forces.begin(), _linear_forces.end(), ptlf);
@@ -51,6 +53,7 @@ add_linear_force(LinearForce *f) {
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
 attach_physicalnode(PhysicalNode *p) {
+  nassertv(p);
   for (int i = 0; i < p->get_num_physicals(); i++)
     attach_physical(p->get_physical(i));
 }
@@ -61,7 +64,7 @@ attach_physicalnode(PhysicalNode *p) {
 // Description : Resets the physics manager force vector
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
-clear_linear_forces(void) {
+clear_linear_forces() {
   _linear_forces.erase(_linear_forces.begin(), _linear_forces.end());
 }
 
@@ -72,6 +75,7 @@ clear_linear_forces(void) {
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
 add_angular_force(AngularForce *f) {
+  nassertv(f);
   pvector< PT(AngularForce) >::iterator found;
   PT(AngularForce) ptaf = f;
   found = find(_angular_forces.begin(), _angular_forces.end(), ptaf);
@@ -85,7 +89,7 @@ add_angular_force(AngularForce *f) {
 // Description : Resets the physics manager force vector
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
-clear_angular_forces(void) {
+clear_angular_forces() {
   _angular_forces.erase(_angular_forces.begin(), _angular_forces.end());
 }
 
@@ -95,7 +99,7 @@ clear_angular_forces(void) {
 // Description : Resets the physics manager objects vector
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
-clear_physicals(void) {
+clear_physicals() {
   _physicals.erase(_physicals.begin(), _physicals.end());
 }
 
@@ -106,6 +110,7 @@ clear_physicals(void) {
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
 attach_linear_integrator(LinearIntegrator *i) {
+  nassertv(i);
   _linear_integrator = i;
 }
 
@@ -116,5 +121,6 @@ attach_linear_integrator(LinearIntegrator *i) {
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsManager::
 attach_angular_integrator(AngularIntegrator *i) {
+  nassertv(i);
   _angular_integrator = i;
 }

+ 7 - 2
panda/src/physics/physicsManager.cxx

@@ -32,6 +32,7 @@ PhysicsManager::
 PhysicsManager() {
   _linear_integrator.clear();
   _angular_integrator.clear();
+  _viscosity=0;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -50,14 +51,15 @@ PhysicsManager::
 ////////////////////////////////////////////////////////////////////
 void PhysicsManager::
 remove_linear_force(LinearForce *f) {
+  nassertv(f);
   pvector< PT(LinearForce) >::iterator found;
 
   PT(LinearForce) ptbf = f;
   found = find(_linear_forces.begin(), _linear_forces.end(), ptbf);
 
-  if (found == _linear_forces.end())
+  if (found == _linear_forces.end()) {
     return;
-
+  }
   _linear_forces.erase(found);
 }
 
@@ -68,6 +70,7 @@ remove_linear_force(LinearForce *f) {
 ////////////////////////////////////////////////////////////////////
 void PhysicsManager::
 remove_angular_force(AngularForce *f) {
+  nassertv(f);
   pvector< PT(AngularForce) >::iterator found;
 
   PT(BaseForce) ptbf = f;
@@ -86,6 +89,7 @@ remove_angular_force(AngularForce *f) {
 ////////////////////////////////////////////////////////////////////
 void PhysicsManager::
 remove_physical(Physical *p) {
+  nassertv(p);
   pvector< Physical * >::iterator found;
 
   found = find(_physicals.begin(), _physicals.end(), p);
@@ -108,6 +112,7 @@ do_physics(float dt) {
   pvector< Physical * >::iterator p_cur = _physicals.begin();
   for (; p_cur != _physicals.end(); ++p_cur) {
     Physical *physical = *p_cur;
+    nassertv(physical);
 
     // do linear
     if (_linear_integrator.is_null() == false) {

+ 5 - 0
panda/src/physics/physicsManager.h

@@ -53,6 +53,9 @@ PUBLISHED:
   INLINE void clear_angular_forces();
   INLINE void clear_physicals();
 
+  //INLINE void set_viscosity(float viscosity);
+  //float get_viscosity() const;
+  
   void remove_physical(Physical *p);
   void remove_linear_force(LinearForce *f);
   void remove_angular_force(AngularForce *f);
@@ -68,6 +71,8 @@ public:
   friend class Physical;
 
 private:
+  float _viscosity;
+  
   // NOTE that the physicals container is NOT reference counted.
   // this does indeed mean that you are NOT supposed to use this
   // as a primary storage container for the physicals.  This is so

+ 36 - 3
panda/src/physics/physicsObject.I

@@ -47,16 +47,29 @@ set_position(float x, float y, float z) {
 }
 
 ////////////////////////////////////////////////////////////////////
-//    Function : set_position_HandOfGod
+//    Function : reset_position
 //      Access : Public
 // Description : use this to place an object in a completely new
 //               position, that has nothing to do with its last
-//               position (moved by the Hand Of God, or "HOG")
+//               position
 ////////////////////////////////////////////////////////////////////
 INLINE void PhysicsObject::
-set_position_HandOfGod(const LPoint3f &pos) {
+reset_position(const LPoint3f &pos) {
   _position = pos;
   _last_position = pos;
+  _velocity.set(0.0f, 0.0f, 0.0f);
+}
+
+////////////////////////////////////////////////////////////////////
+//    Function : reset_orientation
+//      Access : Public
+// Description : set the orientation while clearing the rotation
+//               velocity.
+////////////////////////////////////////////////////////////////////
+INLINE void PhysicsObject::
+reset_orientation(const LOrientationf &orientation) {
+  _orientation = orientation;
+  _rotation.set(0.0f, 0.0f, 0.0f);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -89,6 +102,16 @@ set_velocity(float x, float y, float z) {
   _velocity.set(x, y, z);
 }
 
+////////////////////////////////////////////////////////////////////
+//    Function : add_impulse
+//      Access : Public
+// Description : Adds an impulse force.
+////////////////////////////////////////////////////////////////////
+INLINE void PhysicsObject::
+add_impulse(const LVector3f &impulse) {
+  _velocity+=impulse;
+}
+
 ////////////////////////////////////////////////////////////////////
 //    Function : set_active
 //      Access : Public
@@ -149,6 +172,16 @@ get_velocity() const {
   return _velocity;
 }
 
+////////////////////////////////////////////////////////////////////
+//    Function : get_implicit_velocity
+//      Access : Public
+// Description : Velocity Query
+////////////////////////////////////////////////////////////////////
+INLINE LVector3f PhysicsObject::
+get_implicit_velocity() const {
+  return _position-_last_position;
+}
+
 ////////////////////////////////////////////////////////////////////
 //    Function : get_active
 //      Access : Public

+ 4 - 4
panda/src/physics/physicsObject.cxx

@@ -97,10 +97,9 @@ make_copy() const {
 LMatrix4f PhysicsObject::
 get_lcs() const {
   LMatrix4f m = LMatrix4f::translate_mat(_position);
-
-  if (_oriented == true)
-    _orientation.extract_to_matrix(m);
-
+  if (_oriented == true) {
+    m=m*_orientation;
+  }
   return m;
 }
 
@@ -142,6 +141,7 @@ write(ostream &out, unsigned int indent) const {
   out.width(indent+2); out<<""; out<<"_position "<<_position<<"\n";
   out.width(indent+2); out<<""; out<<"_last_position "<<_last_position<<"\n";
   out.width(indent+2); out<<""; out<<"_velocity "<<_velocity<<"\n";
+  out.width(indent+2); out<<""; out<<"(implicit velocity "<<get_implicit_velocity()<<")\n";
   out.width(indent+2); out<<""; out<<"_orientation "<<_orientation<<"\n";
   out.width(indent+2); out<<""; out<<"_rotation "<<_rotation<<"\n";
   out.width(indent+2); out<<""; out<<"_terminal_velocity "<<_terminal_velocity<<"\n";

+ 12 - 7
panda/src/physics/physicsObject.h

@@ -38,6 +38,9 @@ PUBLISHED:
 
   static const float _default_terminal_velocity;
 
+  INLINE void set_active(bool flag);
+  INLINE bool get_active() const;
+
   INLINE void set_mass(float);
   INLINE float get_mass() const;
 
@@ -45,7 +48,7 @@ PUBLISHED:
   INLINE void set_position(float x, float y, float z);
   INLINE LPoint3f get_position() const;
 
-  INLINE void set_position_HandOfGod(const LPoint3f &pos);
+  INLINE void reset_position(const LPoint3f &pos);
 
   INLINE void set_last_position(const LPoint3f &pos);
   INLINE LPoint3f get_last_position() const;
@@ -53,23 +56,25 @@ PUBLISHED:
   INLINE void set_velocity(const LVector3f &vel);
   INLINE void set_velocity(float x, float y, float z);
   INLINE LVector3f get_velocity() const;
+  INLINE LVector3f get_implicit_velocity() const;
 
-  INLINE void set_active(bool flag);
-  INLINE bool get_active() const;
-
-  INLINE void set_oriented(bool flag);
-  INLINE bool get_oriented() const;
+  INLINE void add_impulse(const LVector3f &impulse);
 
   INLINE void set_terminal_velocity(float tv);
   INLINE float get_terminal_velocity() const;
 
+  INLINE void set_oriented(bool flag);
+  INLINE bool get_oriented() const;
+
   INLINE void set_orientation(const LOrientationf &orientation);
   INLINE LOrientationf get_orientation() const;
 
+  INLINE void reset_orientation(const LOrientationf &orientation);
+
   INLINE void set_rotation(const LVector3f &rotation);
   INLINE LVector3f get_rotation() const;
 
-  virtual LMatrix4f get_inertial_tensor(void) const;
+  virtual LMatrix4f get_inertial_tensor() const;
   virtual LMatrix4f get_lcs() const;
   virtual PhysicsObject *make_copy() const;
   

+ 1 - 0
panda/src/physics/physics_composite2.cxx

@@ -9,5 +9,6 @@
 #include "forceNode.cxx"
 #include "physical.cxx"
 #include "physicalNode.cxx"
+#include "physicsCollisionHandler.cxx"
 #include "physicsManager.cxx"
 #include "physicsObject.cxx"