Browse Source

added Vector

Dave Schuyler 22 years ago
parent
commit
bf7c3c3508

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

@@ -36,7 +36,7 @@ PUBLISHED:
 
 private:
   virtual void child_integrate(Physical *physical,
-                               pvector< PT(AngularForce) >& forces,
+                               AngularForceVector& forces,
                                float dt);
 };
 

+ 1 - 1
panda/src/physics/angularIntegrator.cxx

@@ -42,7 +42,7 @@ AngularIntegrator::
 // Description : high-level integration.  API.
 ////////////////////////////////////////////////////////////////////
 void AngularIntegrator::
-integrate(Physical *physical, pvector< PT(AngularForce) >& forces,
+integrate(Physical *physical, AngularForceVector& forces,
           float dt) {
   // intercept in case we want to censor/adjust values
   if (dt > _max_angular_dt)

+ 2 - 2
panda/src/physics/angularIntegrator.h

@@ -32,7 +32,7 @@ class EXPCL_PANDAPHYSICS AngularIntegrator : public BaseIntegrator {
 public:
   virtual ~AngularIntegrator();
 
-  void integrate(Physical *physical, pvector< PT(AngularForce) > &forces,
+  void integrate(Physical *physical, AngularForceVector &forces,
                  float dt);
   
   virtual void output(ostream &out) const;
@@ -46,7 +46,7 @@ private:
 
   // this allows baseAngularIntegrator to censor/modify data that the
   // actual integration function receives.
-  virtual void child_integrate(Physical *physical, pvector< PT(AngularForce) > &forces,
+  virtual void child_integrate(Physical *physical, AngularForceVector &forces,
                                float dt) = 0;
 };
 

+ 6 - 7
panda/src/physics/baseIntegrator.cxx

@@ -49,7 +49,7 @@ BaseIntegrator::
 ////////////////////////////////////////////////////////////////////
 void BaseIntegrator::
 precompute_linear_matrices(Physical *physical,
-                           const pvector< PT(LinearForce) > &forces) {
+                           const LinearForceVector &forces) {
   nassertv(physical);
   // make sure the physical's in the scene graph, somewhere.
   PhysicalNode *physical_node = physical->get_physical_node();
@@ -79,8 +79,7 @@ precompute_linear_matrices(Physical *physical,
     _precomputed_linear_matrices.push_back(physical_np.get_mat(force_node));
   }
 
-  const pvector< PT(LinearForce) > &force_vector =
-    physical->get_linear_forces();
+  const LinearForceVector &force_vector = physical->get_linear_forces();
 
   // tally the local xforms
   for (i = 0; i < local_force_vec_size; ++i) {
@@ -102,7 +101,7 @@ precompute_linear_matrices(Physical *physical,
 ////////////////////////////////////////////////////////////////////
 void BaseIntegrator::
 precompute_angular_matrices(Physical *physical,
-                            const pvector< PT(AngularForce) > &forces) {
+                            const AngularForceVector &forces) {
   nassertv(physical);
   // make sure the physical's in the scene graph, somewhere.
   PhysicalNode *physical_node = physical->get_physical_node();
@@ -124,7 +123,7 @@ precompute_angular_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);
 
@@ -132,11 +131,11 @@ precompute_angular_matrices(Physical *physical,
     _precomputed_angular_matrices.push_back(physical_np.get_mat(force_node));
   }
 
-  const pvector< PT(AngularForce) > &force_vector =
+  const AngularForceVector &force_vector =
     physical->get_angular_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);
 

+ 4 - 2
panda/src/physics/baseIntegrator.h

@@ -40,6 +40,8 @@ class Physical;
 class EXPCL_PANDAPHYSICS BaseIntegrator : public ReferenceCount {
 public:
   typedef pvector<LMatrix4f> MatrixVector;
+  typedef pvector<PT(LinearForce)> LinearForceVector;
+  typedef pvector<PT(AngularForce)> AngularForceVector;
 
   virtual ~BaseIntegrator();
   
@@ -57,9 +59,9 @@ protected:
   INLINE const MatrixVector &get_precomputed_angular_matrices() const;
 
   void precompute_linear_matrices(Physical *physical,
-                                  const pvector< PT(LinearForce) > &forces);
+                                  const LinearForceVector &forces);
   void precompute_angular_matrices(Physical *physical,
-                                   const pvector< PT(AngularForce) > &forces);
+                                   const AngularForceVector &forces);
 
 private:
   // since the wrt for each physicsobject between its physicalnode

+ 5 - 5
panda/src/physics/linearEulerIntegrator.cxx

@@ -57,7 +57,7 @@ LinearEulerIntegrator::
 ////////////////////////////////////////////////////////////////////
 void LinearEulerIntegrator::
 child_integrate(Physical *physical,
-                pvector< PT(LinearForce) >& forces,
+                LinearForceVector& forces,
                 float dt) {
   // perform the precomputation.  Note that the vector returned by
   // get_precomputed_matrices() has the matrices loaded in order of force
@@ -77,10 +77,10 @@ child_integrate(Physical *physical,
   // velocity of each physicsobject in the set.  Accordingly, we have
   // to grunt our way through each one.  wrt caching of the xform matrix
   // should help.
-  pvector< PT(PhysicsObject) >::const_iterator current_object_iter;
+  PhysicsObject::Vector::const_iterator current_object_iter;
   current_object_iter = physical->get_object_vector().begin();
   for (; current_object_iter != physical->get_object_vector().end();
-       current_object_iter++) {
+       ++current_object_iter) {
     PhysicsObject *current_object = *current_object_iter;
 
     // bail out if this object doesn't exist or doesn't want to be
@@ -93,7 +93,7 @@ child_integrate(Physical *physical,
       continue;
     }
     
-    LVector3f md_accum_vec;
+    LVector3f md_accum_vec; // mass dependent accumulation vector.
     LVector3f non_md_accum_vec;
     LVector3f accel_vec;
     LVector3f vel_vec;
@@ -107,7 +107,7 @@ child_integrate(Physical *physical,
     //    LMatrix4f force_to_object_xform;
 
     ForceNode *force_node;
-    pvector< PT(LinearForce) >::const_iterator f_cur;
+    LinearForceVector::const_iterator f_cur;
 
     // global forces
     f_cur = forces.begin();

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

@@ -36,7 +36,7 @@ PUBLISHED:
 
 private:
   virtual void child_integrate(Physical *physical,
-                               pvector< PT(LinearForce) >& forces,
+                               LinearForceVector& forces,
                                float dt);
 };
 

+ 2 - 2
panda/src/physics/linearIntegrator.cxx

@@ -46,7 +46,7 @@ LinearIntegrator::
 //               virtual.
 ////////////////////////////////////////////////////////////////////
 void LinearIntegrator::
-integrate(Physical *physical, pvector< PT(LinearForce) > &forces,
+integrate(Physical *physical, LinearForceVector &forces,
           float dt) {
 /* <-- darren, 2000.10.06
   // cap dt so physics don't go flying off on lags
@@ -54,7 +54,7 @@ integrate(Physical *physical, pvector< PT(LinearForce) > &forces,
     dt = _max_linear_dt;
 */
 
-  pvector< PT(PhysicsObject) >::const_iterator current_object_iter;
+  PhysicsObject::Vector::const_iterator current_object_iter;
   current_object_iter = physical->get_object_vector().begin();
   for (; current_object_iter != physical->get_object_vector().end();
        current_object_iter++) {

+ 2 - 2
panda/src/physics/linearIntegrator.h

@@ -33,7 +33,7 @@ class EXPCL_PANDAPHYSICS LinearIntegrator : public BaseIntegrator {
 public:
   virtual ~LinearIntegrator();
 
-  void integrate(Physical *physical, pvector< PT(LinearForce) > &forces,
+  void integrate(Physical *physical, LinearForceVector &forces,
                  float dt);
   
   virtual void output(ostream &out) const;
@@ -48,7 +48,7 @@ private:
   // this allows baseLinearIntegrator to censor/modify data that the
   // actual integration function receives.
   virtual void child_integrate(Physical *physical, 
-                               pvector< PT(LinearForce) > &forces,
+                               LinearForceVector &forces,
                                float dt) = 0;
 };
 

+ 5 - 5
panda/src/physics/physical.I

@@ -78,7 +78,7 @@ add_angular_force(AngularForce *f) {
 ////////////////////////////////////////////////////////////////////
 INLINE void Physical::
 remove_linear_force(LinearForce *f) {
-  pvector< PT(LinearForce) >::iterator found;
+  LinearForceVector::iterator found;
 
   // this is a PT because the templates don't like what should be
   // perfectly allowable, which is to search for bf directly.
@@ -98,7 +98,7 @@ remove_linear_force(LinearForce *f) {
 ////////////////////////////////////////////////////////////////////
 INLINE void Physical::
 remove_angular_force(AngularForce *f) {
-  pvector< PT(AngularForce) >::iterator found;
+  AngularForceVector::iterator found;
 
   PT(AngularForce) pt_af = f;
   found = find(_angular_forces.begin(), _angular_forces.end(), pt_af);
@@ -150,7 +150,7 @@ get_physical_node() const {
 //    Function : get_object_vector
 //      Access : Public
 ////////////////////////////////////////////////////////////////////
-INLINE const pvector< PT(PhysicsObject) > &Physical::
+INLINE const PhysicsObject::Vector &Physical::
 get_object_vector() const {
   return _physics_objects;
 }
@@ -159,7 +159,7 @@ get_object_vector() const {
 //    Function : get_linear_forces
 //      Access : Public
 ////////////////////////////////////////////////////////////////////
-INLINE const pvector< PT(LinearForce) > &Physical::
+INLINE const Physical::LinearForceVector &Physical::
 get_linear_forces() const {
   return _linear_forces;
 }
@@ -168,7 +168,7 @@ get_linear_forces() const {
 //    Function : get_angular_forces
 //      Access : Public
 ////////////////////////////////////////////////////////////////////
-INLINE const pvector< PT(AngularForce) > &Physical::
+INLINE const Physical::AngularForceVector &Physical::
 get_angular_forces() const {
   return _angular_forces;
 }

+ 7 - 7
panda/src/physics/physical.cxx

@@ -74,23 +74,23 @@ Physical(const Physical& copy) {
   _physics_manager = (PhysicsManager *) NULL;
 
   // copy the forces.
-  pvector< PT(LinearForce) >::const_iterator lf_cur;
-  pvector< PT(LinearForce) >::const_iterator lf_end = copy._linear_forces.end();
+  LinearForceVector::const_iterator lf_cur;
+  LinearForceVector::const_iterator lf_end = copy._linear_forces.end();
 
   for (lf_cur = copy._linear_forces.begin(); lf_cur != lf_end; lf_cur++) {
     _linear_forces.push_back((*lf_cur)->make_copy());
   }
 
-  pvector< PT(AngularForce) >::const_iterator af_cur;
-  pvector< PT(AngularForce) >::const_iterator af_end = copy._angular_forces.end();
+  AngularForceVector::const_iterator af_cur;
+  AngularForceVector::const_iterator af_end = copy._angular_forces.end();
 
   for (af_cur = copy._angular_forces.begin(); af_cur != af_end; af_cur++) {
     _angular_forces.push_back((*af_cur)->make_copy());
   }
 
   // copy the physics objects
-  pvector< PT(PhysicsObject) >::const_iterator p_cur;
-  pvector< PT(PhysicsObject) >::const_iterator p_end = copy._physics_objects.end();
+  PhysicsObject::Vector::const_iterator p_cur;
+  PhysicsObject::Vector::const_iterator p_end = copy._physics_objects.end();
 
   for (p_cur = copy._physics_objects.begin(); p_cur != p_end; p_cur++) {
     // oooh so polymorphic.
@@ -144,7 +144,7 @@ write_physics_objects(ostream &out, unsigned int indent) const {
   #ifndef NDEBUG //[
   out.width(indent);
   out<<""<<"_physics_objects ("<<_physics_objects.size()<<" objects)\n";
-  for (PhysicsObjectVector::const_iterator i=_physics_objects.begin();
+  for (PhysicsObject::Vector::const_iterator i=_physics_objects.begin();
        i != _physics_objects.end();
        ++i) {
     (*i)->write(out, indent+2);

+ 7 - 6
panda/src/physics/physical.h

@@ -40,6 +40,11 @@ class PhysicsManager;
 //               it from this.
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDAPHYSICS Physical : public TypedReferenceCount {
+public:
+  //typedef pvector<PT(PhysicsObject)> PhysicsObjectVector;
+  typedef pvector<PT(LinearForce)> LinearForceVector;
+  typedef pvector<PT(AngularForce)> AngularForceVector;
+
 PUBLISHED:
   Physical(int total_objects = 1, bool pre_alloc = false);
   Physical(const Physical& copy);
@@ -75,11 +80,7 @@ PUBLISHED:
   virtual void write(ostream &out, unsigned int indent=0) const;
 
 public:
-  typedef pvector< PT(PhysicsObject) > PhysicsObjectVector;
-  typedef pvector< PT(LinearForce) > LinearForceVector;
-  typedef pvector< PT(AngularForce) > AngularForceVector;
-
-  INLINE const PhysicsObjectVector &get_object_vector() const;
+  INLINE const PhysicsObject::Vector &get_object_vector() const;
   INLINE const LinearForceVector &get_linear_forces() const;
   INLINE const AngularForceVector &get_angular_forces() const;
 
@@ -89,7 +90,7 @@ public:
 protected:
   float _viscosity;
   // containers
-  PhysicsObjectVector _physics_objects;
+  PhysicsObject::Vector _physics_objects;
   LinearForceVector _linear_forces;
   AngularForceVector _angular_forces;
 

+ 3 - 0
panda/src/physics/physicsObject.h

@@ -30,6 +30,9 @@
 //               NOT derive from this.  Derive from Physical instead.
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDAPHYSICS PhysicsObject : public TypedReferenceCount {
+public:
+  typedef pvector<PT(PhysicsObject)> Vector;
+
 PUBLISHED:
   PhysicsObject();
   PhysicsObject(const PhysicsObject &copy);

+ 3 - 3
panda/src/physics/test_physics.cxx

@@ -58,7 +58,7 @@ int main(int, char **) {
   b.add_linear_force(new LinearJitterForce(0.1f));
   
   int i=0;
-  for (Physical::PhysicsObjectVector::const_iterator co=b.get_object_vector().begin();
+  for (PhysicsObject::Vector::const_iterator co=b.get_object_vector().begin();
        co != b.get_object_vector().end();
        ++i, ++co) {
     (*co)->set_position(i * 2.0f, float(i), 0.0f);
@@ -71,7 +71,7 @@ int main(int, char **) {
   physics_manager.add_linear_force(new LinearVectorForce(0.0f, 0.0f, -9.8f, 1.0f, false));
 
   cout << "Object vector:" << endl;
-  for (Physical::PhysicsObjectVector::const_iterator co=b.get_object_vector().begin();
+  for (PhysicsObject::Vector::const_iterator co=b.get_object_vector().begin();
        co != b.get_object_vector().end();
        ++co) {
     cout << "vel: " << (*co)->get_velocity() << "  ";
@@ -81,7 +81,7 @@ int main(int, char **) {
   physics_manager.do_physics(1.0f);
   cout << "Physics have been applied." << endl;
 
-  for (Physical::PhysicsObjectVector::const_iterator co=b.get_object_vector().begin();
+  for (PhysicsObject::Vector::const_iterator co=b.get_object_vector().begin();
        co != b.get_object_vector().end();
        ++co) {
     cout << "vel: " << (*co)->get_velocity() << "  ";