00001 // Filename: collisionLevelStateBase.cxx 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "collisionLevelStateBase.h" 00016 #include "collisionSolid.h" 00017 #include "collisionNode.h" 00018 #include "config_collide.h" 00019 #include "dcast.h" 00020 00021 PStatCollector CollisionLevelStateBase::_node_volume_pcollector("Collision Volumes:PandaNode"); 00022 00023 TypeHandle CollisionLevelStateBase::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: CollisionLevelStateBase::clear 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 void CollisionLevelStateBase:: 00031 clear() { 00032 _colliders.clear(); 00033 _local_bounds.clear(); 00034 _parent_bounds.clear(); 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: CollisionLevelStateBase::reserve 00039 // Access: Public 00040 // Description: Indicates an intention to add the indicated number of 00041 // colliders to the level state. 00042 //////////////////////////////////////////////////////////////////// 00043 void CollisionLevelStateBase:: 00044 reserve(int num_colliders) { 00045 _colliders.reserve(num_colliders); 00046 _local_bounds.reserve(num_colliders); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: CollisionLevelStateBase::prepare_collider 00051 // Access: Public 00052 // Description: Adds the indicated Collider to the set of Colliders 00053 // in the current level state. 00054 //////////////////////////////////////////////////////////////////// 00055 void CollisionLevelStateBase:: 00056 prepare_collider(const ColliderDef &def, const NodePath &root) { 00057 _colliders.push_back(def); 00058 00059 const CollisionSolid *collider = def._collider; 00060 CPT(BoundingVolume) bv = collider->get_bounds(); 00061 if (!bv->is_of_type(GeometricBoundingVolume::get_class_type())) { 00062 _local_bounds.push_back((GeometricBoundingVolume *)NULL); 00063 } else { 00064 // We can use a plain pointer, rather than a PT() here, because we 00065 // know we are going to save the volume in the vector, below. 00066 GeometricBoundingVolume *gbv; 00067 DCAST_INTO_V(gbv, bv->make_copy()); 00068 00069 // TODO: we need to make this logic work in the new relative 00070 // world. The bounding volume should be extended by the object's 00071 // motion relative to each object it is considering a collision 00072 // with. That makes things complicated! 00073 if (bv->as_bounding_sphere()) { 00074 LPoint3 pos_delta = def._node_path.get_pos_delta(root); 00075 00076 //LVector3 cap(pos_delta); 00077 //if(cap.length()>fluid_cap_amount) { 00078 // pos_delta=LPoint3(cap/cap.length())*fluid_cap_amount; 00079 //} 00080 if (pos_delta != LVector3::zero()) { 00081 // If the node has a delta, we have to include the starting 00082 // position in the volume as well. We only do this for bounding 00083 // spheres, since (a) other kinds of volumes may not extend so 00084 // well, and (b) we've only implemented fluid-motion detection 00085 // for CollisionSpheres anyway. 00086 LMatrix4 inv_trans = LMatrix4::translate_mat(-pos_delta); 00087 PT(GeometricBoundingVolume) gbv_prev; 00088 gbv_prev = DCAST(GeometricBoundingVolume, bv->make_copy()); 00089 00090 gbv_prev->xform(inv_trans); 00091 gbv->extend_by(gbv_prev); 00092 } 00093 } 00094 00095 CPT(TransformState) rel_transform = def._node_path.get_transform(root.get_parent()); 00096 gbv->xform(rel_transform->get_mat()); 00097 _local_bounds.push_back(gbv); 00098 } 00099 00100 _parent_bounds = _local_bounds; 00101 }