Jelajahi Sumber

adding _transform_limit to modelNodes as well

Josh Wilson 18 tahun lalu
induk
melakukan
998c7017a2

+ 3 - 1
panda/src/pgraph/modelNode.I

@@ -28,6 +28,7 @@ ModelNode(const string &name) :
 {
   _preserve_transform = PT_none;
   _preserve_attributes = 0;
+  _transform_limit = 0;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -103,6 +104,7 @@ INLINE ModelNode::
 ModelNode(const ModelNode &copy) :
   PandaNode(copy),
   _preserve_transform(copy._preserve_transform),
-  _preserve_attributes(copy._preserve_attributes)
+  _preserve_attributes(copy._preserve_attributes),
+  _transform_limit(copy._transform_limit)
 {
 }

+ 38 - 0
panda/src/pgraph/modelNode.cxx

@@ -136,6 +136,44 @@ register_with_read_factory() {
   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
 }
 
+////////////////////////////////////////////////////////////////////
+//     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 ModelNode::
+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
+//  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 ModelNode::
+transform_changed() {
+  PandaNode::transform_changed();
+  // get the transform
+  CPT(TransformState) transform = get_transform();
+
+  if (_transform_limit > 0.0) {
+    test_transform(transform);
+  }
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ModelNode::write_datagram
 //       Access: Public, Virtual

+ 9 - 0
panda/src/pgraph/modelNode.h

@@ -65,6 +65,8 @@ PUBLISHED:
   INLINE void set_preserve_attributes(int attrib_mask);
   INLINE int get_preserve_attributes() const;
 
+  void set_transform_limit(float limit) { _transform_limit = limit; };
+
 private:
   PreserveTransform _preserve_transform;
   int _preserve_attributes;
@@ -77,6 +79,13 @@ protected:
   static TypedWritable *make_from_bam(const FactoryParams &params);
   void fillin(DatagramIterator &scan, BamReader *manager);
 
+  virtual void transform_changed();
+  void test_transform(const TransformState *ts) const;
+
+  float _transform_limit;
+
+
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

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

@@ -79,9 +79,6 @@ 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;
 }
@@ -124,6 +121,10 @@ transform_changed() {
   // get the transform
   CPT(TransformState) transform = get_transform();
 
+  if (_transform_limit > 0.0) {
+    test_transform(transform);
+  }
+
   // extract the orientation
   if (_mass_center->get_oriented() == true) {
     _mass_center->set_orientation(transform->get_quat());