Panda3D
physxContactPair.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physxContactPair.cxx
10  * @author enn0x
11  * @date 2009-12-19
12  */
13 
14 #include "physxContactPair.h"
15 #include "physxManager.h"
16 #include "physxActor.h"
17 #include "physxContactPoint.h"
18 
19 TypeHandle PhysxContactPair::_type_handle;
20 
21 /**
22  * Returns the first of the two actors that makes up this pair.
23  */
25 get_actor_a() const {
26 
27  if (_pair.isDeletedActor[0]) {
28  physx_cat.warning() << "actor A has been deleted" << std::endl;
29  return nullptr;
30  }
31 
32  NxActor *actorPtr = _pair.actors[0];
33  return (actorPtr == nullptr) ? nullptr : (PhysxActor *)actorPtr->userData;
34 }
35 
36 /**
37  * Returns the second of the two actors that make up his pair.
38  */
40 get_actor_b() const {
41 
42  if (_pair.isDeletedActor[1]) {
43  physx_cat.warning() << "actor B has been deleted" << std::endl;
44  return nullptr;
45  }
46 
47  NxActor *actorPtr = _pair.actors[1];
48  return (actorPtr == nullptr) ? nullptr : (PhysxActor *)actorPtr->userData;
49 }
50 
51 /**
52  * Returns true if the first of the two actors is deleted.
53  */
55 is_deleted_a() const {
56 
57  return _pair.isDeletedActor[0];
58 }
59 
60 /**
61  * Returns true if the second of the two actors is deleted.
62  */
64 is_deleted_b() const {
65 
66  return _pair.isDeletedActor[1];
67 }
68 
69 /**
70  * Returns the total contact normal force that was applied for this pair, to
71  * maintain nonpenetration constraints.
72  *
73  * You should set the ContactPairFlag CPF_notify_forces in order to receive
74  * this value.
75  *
76  * @see PhysxScene::set_actor_pair_flag @see
77  * PhysxScene::set_actor_group_pair_flag
78  */
79 LVector3f PhysxContactPair::
81 
82  return PhysxManager::nxVec3_to_vec3(_pair.sumNormalForce);
83 }
84 
85 /**
86  * Returns the total tangential force that was applied for this pair.
87  *
88  * You should set the ContactPairFlag CPF_notify_forces in order to receive
89  * this value.
90  *
91  * @see PhysxScene::set_actor_pair_flag @see
92  * PhysxScene::set_actor_group_pair_flag
93  */
94 LVector3f PhysxContactPair::
96 
97  return PhysxManager::nxVec3_to_vec3(_pair.sumFrictionForce);
98 }
99 
100 /**
101  * Returns the total number of contact points reported in this pair's contact
102  * stream.
103  *
104  * This method is a helper for iterating over the pair's contact stream.
105  */
106 unsigned int PhysxContactPair::
107 get_num_contact_points() {
108 
109  if (_contacts.size() == 0) {
110  NxContactStreamIterator it(_pair.stream);
111  while(it.goNextPair()) {
112  while(it.goNextPatch()) {
113  while(it.goNextPoint()) {
115  cp.set(it);
116  _contacts.push_back(cp);
117  }
118  }
119  }
120  }
121 
122  return _contacts.size();
123 }
124 
125 /**
126  * Returns an instance of PhysxContactPoint, which represents a single entry
127  * of this pair's contact stream.
128  *
129  * This method is a helper for iterating over the pair's contact stream.
130  */
132 get_contact_point(unsigned int idx) const {
133 
134  nassertr(idx < _contacts.size(), PhysxContactPoint::empty());
135  return _contacts[idx];
136 }
LVector3f get_sum_normal_force() const
Returns the total contact normal force that was applied for this pair, to maintain nonpenetration con...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A helper structure for iterating over contact streams reported by PhysxContactPair.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:36
Actors are the main simulation objects.
Definition: physxActor.h:44
PhysxActor * get_actor_a() const
Returns the first of the two actors that makes up this pair.
LVector3f get_sum_friction_force() const
Returns the total tangential force that was applied for this pair.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_contact_point
Returns an instance of PhysxContactPoint, which represents a single entry of this pair's contact stre...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_deleted_b() const
Returns true if the second of the two actors is deleted.
bool is_deleted_a() const
Returns true if the first of the two actors is deleted.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PhysxActor * get_actor_b() const
Returns the second of the two actors that make up his pair.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.