From afe8501ff7875cac4ea526d5081bf367cba39bd3 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Sat, 12 Jul 2003 01:24:35 +0000 Subject: [PATCH] added contact_vector --- panda/src/physics/actorNode.I | 20 ++++ panda/src/physics/actorNode.h | 4 + panda/src/physics/physicsCollisionHandler.cxx | 100 +++++++++--------- 3 files changed, 74 insertions(+), 50 deletions(-) diff --git a/panda/src/physics/actorNode.I b/panda/src/physics/actorNode.I index 46c95804a0..5439900faf 100644 --- a/panda/src/physics/actorNode.I +++ b/panda/src/physics/actorNode.I @@ -15,3 +15,23 @@ // panda3d@yahoogroups.com . // //////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function : set_contact_vector +// Access : Public +// Description : +//////////////////////////////////////////////////////////////////// +INLINE void ActorNode:: +set_contact_vector(const LVector3f &contact_vector) { + _contact_vector=contact_vector; +} + +//////////////////////////////////////////////////////////////////// +// Function : get_contact_vector +// Access : Public +// Description : +//////////////////////////////////////////////////////////////////// +INLINE const LVector3f &ActorNode:: +get_contact_vector() const { + return _contact_vector; +} diff --git a/panda/src/physics/actorNode.h b/panda/src/physics/actorNode.h index 0e50416d68..a7eb79f360 100644 --- a/panda/src/physics/actorNode.h +++ b/panda/src/physics/actorNode.h @@ -38,6 +38,9 @@ PUBLISHED: virtual ~ActorNode(); PhysicsObject *get_physics_object() { return _mass_center; } + + void set_contact_vector(const LVector3f &contact_vector); + const LVector3f &get_contact_vector() const; // update the parent scene graph node with PhysicsObject information // i.e. copy from PhysicsObject to PandaNode @@ -48,6 +51,7 @@ PUBLISHED: private: PhysicsObject *_mass_center; + LVector3f _contact_vector; bool _ok_to_callback; // node hook if the client changes the node's transform. diff --git a/panda/src/physics/physicsCollisionHandler.cxx b/panda/src/physics/physicsCollisionHandler.cxx index 62eea9b0aa..a29eb9b53d 100755 --- a/panda/src/physics/physicsCollisionHandler.cxx +++ b/panda/src/physics/physicsCollisionHandler.cxx @@ -55,55 +55,55 @@ apply_linear_force(ColliderDef &def, const LVector3f &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 "< "<<(initialVelMag>temp) - <almostStationary) { - friction*=0.01f; cerr<<"not almostStationary"< old_vel.length()) { - cerr<<"\nvel.length() > old_vel.length() "< "< 10.0f) { - cerr<<"\nvel.length() > 10.0f "<get_physics_object()->set_velocity(vel); + if (!def._node) { + return; } + ActorNode *actor=DCAST(ActorNode, def._node); + float friction=0.9f; + 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 old_vel "< "<<(initialVelMag>temp) + <almostStationary) { + friction*=0.01f; cerr<<"not almostStationary"< old_vel.length()) { + cerr<<"\nvel.length() > old_vel.length() "< "< 10.0f) { + cerr<<"\nvel.length() > 10.0f "<set_contact_vector(force); + actor->get_physics_object()->set_velocity(vel); }