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