From 56394ce390b9f38edbf4ceb9cfd7ce4918d266e5 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sat, 6 Oct 2007 00:20:16 +0000 Subject: [PATCH] adding _transform_limit to assert when the position of the actor node exceeds an arbitrary limit --- panda/src/physics/actorNode.cxx | 24 ++++++++++++++++++++++++ panda/src/physics/actorNode.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/panda/src/physics/actorNode.cxx b/panda/src/physics/actorNode.cxx index c4894bb774..08550a9c37 100644 --- a/panda/src/physics/actorNode.cxx +++ b/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 ©) : _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 diff --git a/panda/src/physics/actorNode.h b/panda/src/physics/actorNode.h index 420a3e7691..ac946ff79f 100644 --- a/panda/src/physics/actorNode.h +++ b/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() {