Browse Source

adding _transform_limit to assert when the position of the actor node exceeds an arbitrary limit

Josh Wilson 18 years ago
parent
commit
56394ce390
2 changed files with 27 additions and 0 deletions
  1. 24 0
      panda/src/physics/actorNode.cxx
  2. 3 0
      panda/src/physics/actorNode.h

+ 24 - 0
panda/src/physics/actorNode.cxx

@@ -40,6 +40,7 @@ ActorNode(const string &name) :
     _mass_center->set_name(name);
   #endif
   _ok_to_callback = true;
+  _transform_limit = 0.0;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -53,6 +54,7 @@ ActorNode(const ActorNode &copy) :
   _contact_vector = LVector3f::zero();
   _ok_to_callback = true;
   _mass_center = get_physical(0)->get_phys_body();
+  _transform_limit = copy._transform_limit;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -77,10 +79,31 @@ update_transform() {
 
   // lock the callback so that this doesn't call transform_changed.
   _ok_to_callback = false;
+  if (_transform_limit > 0.0) {
+    test_transform(TransformState::make_mat(lcs));
+  }
   set_transform(TransformState::make_mat(lcs));
   _ok_to_callback = true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function : test_transform
+//       Access : private
+//  Description : this tests the transform to make sure it's within
+//                the specified limits.  It's done so we can assert
+//                to see when an invalid transform is being applied.
+////////////////////////////////////////////////////////////////////
+void ActorNode::
+test_transform(const TransformState *ts) const {
+  LPoint3f pos(ts->get_pos());
+  nassertv(pos[0] < _transform_limit);
+  nassertv(pos[0] > -_transform_limit);
+  nassertv(pos[1] < _transform_limit);
+  nassertv(pos[1] > -_transform_limit);
+  nassertv(pos[2] < _transform_limit);
+  nassertv(pos[2] > -_transform_limit);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function : transform_changed
 //       Access : private, virtual
@@ -110,6 +133,7 @@ transform_changed() {
   _mass_center->set_position(transform->get_pos());
 }
 
+
 ////////////////////////////////////////////////////////////////////
 //     Function : write
 //       Access : Public

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

@@ -46,16 +46,19 @@ PUBLISHED:
   // i.e. copy from PhysicsObject to PandaNode
   void update_transform();
   
+  void set_transform_limit(float limit) { _transform_limit = limit; };
   virtual void write(ostream &out, unsigned int indent=0) const;
 
 private:
   PhysicsObject *_mass_center;
   LVector3f _contact_vector;
   bool _ok_to_callback;
+  float _transform_limit;
 
   // node hook if the client changes the node's transform.
   // i.e. copy from PandaNode to PhysicsObject
   virtual void transform_changed();
+  void test_transform(const TransformState *ts) const;
 
 public:
   static TypeHandle get_class_type() {