00001 // Filename: physxContactPair.cxx 00002 // Created by: enn0x (19Dec09) 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 "physxContactPair.h" 00016 #include "physxManager.h" 00017 #include "physxActor.h" 00018 #include "physxContactPoint.h" 00019 00020 TypeHandle PhysxContactPair::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: PhysxContactPair::get_actor_a 00024 // Access: Published 00025 // Description: Returns the first of the two actors that makes up 00026 // this pair. 00027 //////////////////////////////////////////////////////////////////// 00028 PhysxActor *PhysxContactPair:: 00029 get_actor_a() const { 00030 00031 if (_pair.isDeletedActor[0]) { 00032 physx_cat.warning() << "actor A has been deleted" << endl; 00033 return NULL; 00034 } 00035 00036 NxActor *actorPtr = _pair.actors[0]; 00037 return (actorPtr == NULL) ? NULL : (PhysxActor *)actorPtr->userData; 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: PhysxContactPair::get_actor_b 00042 // Access: Published 00043 // Description: Returns the second of the two actors that make up 00044 // his pair. 00045 //////////////////////////////////////////////////////////////////// 00046 PhysxActor *PhysxContactPair:: 00047 get_actor_b() const { 00048 00049 if (_pair.isDeletedActor[1]) { 00050 physx_cat.warning() << "actor B has been deleted" << endl; 00051 return NULL; 00052 } 00053 00054 NxActor *actorPtr = _pair.actors[1]; 00055 return (actorPtr == NULL) ? NULL : (PhysxActor *)actorPtr->userData; 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: PhysxContactPair::is_deleted_a 00060 // Access: Published 00061 // Description: Returns true if the first of the two actors is 00062 // deleted. 00063 //////////////////////////////////////////////////////////////////// 00064 bool PhysxContactPair:: 00065 is_deleted_a() const { 00066 00067 return _pair.isDeletedActor[0]; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: PhysxContactPair::is_deleted_b 00072 // Access: Published 00073 // Description: Returns true if the second of the two actors is 00074 // deleted. 00075 //////////////////////////////////////////////////////////////////// 00076 bool PhysxContactPair:: 00077 is_deleted_b() const { 00078 00079 return _pair.isDeletedActor[1]; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: PhysxContactPair::get_sum_normal_force 00084 // Access: Published 00085 // Description: Returns the total contact normal force that was 00086 // applied for this pair, to maintain nonpenetration 00087 // constraints. 00088 // 00089 // You should set the ContactPairFlag 00090 // CPF_notify_forces in order to receive this value. 00091 // 00092 // @see PhysxScene::set_actor_pair_flag 00093 // @see PhysxScene::set_actor_group_pair_flag 00094 //////////////////////////////////////////////////////////////////// 00095 LVector3f PhysxContactPair:: 00096 get_sum_normal_force() const { 00097 00098 return PhysxManager::nxVec3_to_vec3(_pair.sumNormalForce); 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: PhysxContactPair::get_sum_friction_force 00103 // Access: Published 00104 // Description: Returns the total tangential force that was applied 00105 // for this pair. 00106 // 00107 // You should set the ContactPairFlag 00108 // CPF_notify_forces in order to receive this value. 00109 // 00110 // @see PhysxScene::set_actor_pair_flag 00111 // @see PhysxScene::set_actor_group_pair_flag 00112 //////////////////////////////////////////////////////////////////// 00113 LVector3f PhysxContactPair:: 00114 get_sum_friction_force() const { 00115 00116 return PhysxManager::nxVec3_to_vec3(_pair.sumFrictionForce); 00117 } 00118 00119 //////////////////////////////////////////////////////////////////// 00120 // Function: PhysxContactPair::get_num_contact_points 00121 // Access: Published 00122 // Description: Returns the total number of contact points reported 00123 // in this pair's contact stream. 00124 // 00125 // This method is a helper for iterating over the 00126 // pair's contact stream. 00127 //////////////////////////////////////////////////////////////////// 00128 unsigned int PhysxContactPair:: 00129 get_num_contact_points() { 00130 00131 if (_contacts.size() == 0) { 00132 NxContactStreamIterator it(_pair.stream); 00133 while(it.goNextPair()) { 00134 while(it.goNextPatch()) { 00135 while(it.goNextPoint()) { 00136 PhysxContactPoint cp; 00137 cp.set(it); 00138 _contacts.push_back(cp); 00139 } 00140 } 00141 } 00142 } 00143 00144 return _contacts.size(); 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: PhysxContactPair::get_contact_point 00149 // Access: Published 00150 // Description: Returns an instance of PhysxContactPoint, which 00151 // represents a single entry of this pair's contact 00152 // stream. 00153 // 00154 // This method is a helper for iterating over the 00155 // pair's contact stream. 00156 //////////////////////////////////////////////////////////////////// 00157 PhysxContactPoint PhysxContactPair:: 00158 get_contact_point(unsigned int idx) const { 00159 00160 nassertr(idx < _contacts.size(), PhysxContactPoint::empty()); 00161 return _contacts[idx]; 00162 } 00163