mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added contact_vector
This commit is contained in:
parent
05ac2f527e
commit
afe8501ff7
@ -15,3 +15,23 @@
|
|||||||
// panda3d@yahoogroups.com .
|
// 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;
|
||||||
|
}
|
||||||
|
@ -39,6 +39,9 @@ PUBLISHED:
|
|||||||
|
|
||||||
PhysicsObject *get_physics_object() { return _mass_center; }
|
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
|
// update the parent scene graph node with PhysicsObject information
|
||||||
// i.e. copy from PhysicsObject to PandaNode
|
// i.e. copy from PhysicsObject to PandaNode
|
||||||
void update_transform();
|
void update_transform();
|
||||||
@ -48,6 +51,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PhysicsObject *_mass_center;
|
PhysicsObject *_mass_center;
|
||||||
|
LVector3f _contact_vector;
|
||||||
bool _ok_to_callback;
|
bool _ok_to_callback;
|
||||||
|
|
||||||
// node hook if the client changes the node's transform.
|
// node hook if the client changes the node's transform.
|
||||||
|
@ -55,55 +55,55 @@ apply_linear_force(ColliderDef &def, const LVector3f &force) {
|
|||||||
if (force == LVector3f::zero()) {
|
if (force == LVector3f::zero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!def._node) {
|
||||||
if (def._node) {
|
return;
|
||||||
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 "<<vel<<" mag "<<initialVelMag
|
|
||||||
<<"\n force "<<force<<" mag "<<force.length()
|
|
||||||
<<"\n unitForce "<<unitForce<<" mag "<<unitForce.length()
|
|
||||||
<<"\n c "<<c<<" mag "<<c.length()
|
|
||||||
<<"\n vel "<<vel-c<<" mag "<<(vel-c).length()
|
|
||||||
<<"\n friction "<<friction
|
|
||||||
<<"\n vel "<<((vel-c)*friction)<<" mag "<<temp
|
|
||||||
<<"\n initialVelMag > "<<(initialVelMag>temp)
|
|
||||||
<<endl;
|
|
||||||
if (initialVelMag<temp) {
|
|
||||||
cerr<<"\n*************************************"<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif //]
|
|
||||||
float angle=adjustment.dot(vel);
|
|
||||||
vel-=adjustment;
|
|
||||||
if (angle<=0.0f) {
|
|
||||||
// ...avoid amplifying the velocity by checking to see
|
|
||||||
// that the adjustment and the velocity are more than
|
|
||||||
// right-angles (i.e. obtuse angle).
|
|
||||||
float almostStationary=1.0f;
|
|
||||||
if (vel.dot(vel)>almostStationary) {
|
|
||||||
friction*=0.01f; cerr<<"not almostStationary"<<endl;
|
|
||||||
}
|
|
||||||
//vel*=1.0f-friction;
|
|
||||||
}
|
|
||||||
|
|
||||||
LVector3f new_vel=vel;
|
|
||||||
if (vel.length() > old_vel.length()) {
|
|
||||||
cerr<<"\nvel.length() > old_vel.length() "<<vel.length()<<" > "<<old_vel.length()<<endl;
|
|
||||||
}
|
|
||||||
if (vel.length() > 10.0f) {
|
|
||||||
cerr<<"\nvel.length() > 10.0f "<<vel.length()<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
actor->get_physics_object()->set_velocity(vel);
|
|
||||||
}
|
}
|
||||||
|
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 "<<old_vel<<" len "<<old_vel.length()
|
||||||
|
<<"\n force "<<force<<" len "<<force.length()
|
||||||
|
<<"\n adjustment "<<adjustment<<" len"<<adjustment.length()
|
||||||
|
<<"\n vel "<<vel-c<<" len "<<(vel-c).length()
|
||||||
|
<<"\n friction "<<friction
|
||||||
|
<<"\n vel "<<((vel-c)*friction)<<" len "<<temp
|
||||||
|
<<"\n initialVelLen > "<<(initialVelMag>temp)
|
||||||
|
<<endl;
|
||||||
|
if (initialVelMag<temp) {
|
||||||
|
cerr<<"\n*************************************"<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //]
|
||||||
|
float angle=adjustment.dot(vel);
|
||||||
|
vel-=adjustment;
|
||||||
|
if (angle<=0.0f) {
|
||||||
|
// ...avoid amplifying the velocity by checking to see
|
||||||
|
// that the adjustment and the velocity are more than
|
||||||
|
// right-angles (i.e. obtuse angle).
|
||||||
|
float almostStationary=1.0f;
|
||||||
|
if (vel.dot(vel)>almostStationary) {
|
||||||
|
friction*=0.01f; cerr<<"not almostStationary"<<endl;
|
||||||
|
}
|
||||||
|
//vel*=1.0f-friction;
|
||||||
|
}
|
||||||
|
|
||||||
|
LVector3f new_vel=vel;
|
||||||
|
if (vel.length() > old_vel.length()) {
|
||||||
|
cerr<<"\nvel.length() > old_vel.length() "<<vel.length()<<" > "<<old_vel.length()<<endl;
|
||||||
|
}
|
||||||
|
if (vel.length() > 10.0f) {
|
||||||
|
cerr<<"\nvel.length() > 10.0f "<<vel.length()<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
actor->set_contact_vector(force);
|
||||||
|
actor->get_physics_object()->set_velocity(vel);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user