/** * PANDA 3D SOFTWARE * Copyright (c) Carnegie Mellon University. All rights reserved. * * All use of this software is subject to the terms of the revised BSD * license. You should have received a copy of this license along * with this source code in a file named "LICENSE." * * @file physicsCollisionHandler.cxx * @author drose * @date 2002-03-16 */ #include "physicsCollisionHandler.h" #include "collisionNode.h" #include "collisionEntry.h" #include "collisionPolygon.h" #include "config_collide.h" #include "config_physics.h" #include "actorNode.h" #include "dcast.h" using std::cerr; using std::endl; TypeHandle PhysicsCollisionHandler::_type_handle; /** * */ PhysicsCollisionHandler:: PhysicsCollisionHandler() { _almost_stationary_speed = 0.1f; _static_friction_coef=0.9f; _dynamic_friction_coef=0.5f; set_horizontal(false); } /** * */ PhysicsCollisionHandler:: ~PhysicsCollisionHandler() { } /** * The vel parameter will be modified in place to account for friction. */ void PhysicsCollisionHandler:: apply_friction(ColliderDef &def, LVector3& vel, const LVector3& force, PN_stdfloat angle) { if (vel!=LVector3::zero()) { PN_stdfloat friction_coefficient=0.0f; // Determine the friction: if (vel.length()<_almost_stationary_speed) { physics_debug(" static friction"); friction_coefficient=_static_friction_coef; } else { physics_debug(" dynamic friction"); friction_coefficient=_dynamic_friction_coef; } // Apply the friction: physics_debug(" vel pre friction "<1.0f) { cerr<<"\n\nfriction error "<get_dt(); vel *= (1.0f-friction) * dt * dt; #else vel *= 1.0f-friction; #endif physics_debug(" vel post friction "<get_physics_object()->get_velocity(); if (vel == LVector3::zero()) { return; } physics_debug("apply_linear_force() {"); physics_debug(" vel "<get_mat(); // physics_debug( " adjustment trn "<get_physics_object()->get_lcs(); physics_debug( " adjustment lcs "<0.0f) { physics_debug(" positive contact"); #if 0 cerr<<"vel "<get_physics_object()->add_impact(force, -vel); #else adjustment*=adjustmentLength; physics_debug( " adjustment mul "< old_vel.length()) { // This is a check to avoid adding engergy: physics_debug( " vel got larger "< "< 10.0f) { // This is a check to see if the velocity is higher than I expect it to // go. The check value is arbitrary. physics_debug(" vel.length() > 10.0f "<set_contact_vector(adjustment); actor->get_physics_object()->set_velocity(vel); } /** * */ void PhysicsCollisionHandler:: apply_linear_force(ColliderDef &def, const LVector3 &force) { } /** * Called internally to validate the target passed to add_collider(). Returns * true if acceptable, false otherwise. */ bool PhysicsCollisionHandler:: validate_target(const NodePath &target) { if (!CollisionHandlerPhysical::validate_target(target)) { return false; } nassertr_always(target.node()->is_of_type(ActorNode::get_class_type()), false); return true; }