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 */
24 PhysxActor *PhysxContactPair::
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 */
39 PhysxActor *PhysxContactPair::
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 */
54 bool PhysxContactPair::
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 */
63 bool PhysxContactPair::
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
77 * @see PhysxScene::set_actor_group_pair_flag
78 */
79 LVector3f PhysxContactPair::
80 get_sum_normal_force() const {
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
92 * @see PhysxScene::set_actor_group_pair_flag
93 */
94 LVector3f PhysxContactPair::
95 get_sum_friction_force() const {
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()) {
114 PhysxContactPoint cp;
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 */
131 PhysxContactPoint PhysxContactPair::
132 get_contact_point(unsigned int idx) const {
133
134 nassertr(idx < _contacts.size(), PhysxContactPoint::empty());
135 return _contacts[idx];
136 }
PhysxActor
Actors are the main simulation objects.
Definition: physxActor.h:44
PhysxContactPair::get_sum_friction_force
LVector3f get_sum_friction_force() const
Returns the total tangential force that was applied for this pair.
Definition: physxContactPair.cxx:95
PhysxContactPair::get_actor_a
PhysxActor * get_actor_a() const
Returns the first of the two actors that makes up this pair.
Definition: physxContactPair.cxx:25
PhysxContactPair::get_num_contact_points
get_num_contact_points
Returns the total number of contact points reported in this pair's contact stream.
Definition: physxContactPair.h:45
PhysxContactPair::get_sum_normal_force
LVector3f get_sum_normal_force() const
Returns the total contact normal force that was applied for this pair, to maintain nonpenetration con...
Definition: physxContactPair.cxx:80
PhysxContactPair::is_deleted_b
bool is_deleted_b() const
Returns true if the second of the two actors is deleted.
Definition: physxContactPair.cxx:64
PhysxContactPair::get_actor_b
PhysxActor * get_actor_b() const
Returns the second of the two actors that make up his pair.
Definition: physxContactPair.cxx:40
PhysxContactPair::is_deleted_a
bool is_deleted_a() const
Returns true if the first of the two actors is deleted.
Definition: physxContactPair.cxx:55
PhysxContactPair::get_contact_point
get_contact_point
Returns an instance of PhysxContactPoint, which represents a single entry of this pair's contact stre...
Definition: physxContactPair.h:45
PhysxContactPoint
A helper structure for iterating over contact streams reported by PhysxContactPair.
Definition: physxContactPoint.h:29
PhysxManager::nxVec3_to_vec3
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:36
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
physxActor.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxContactPair.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxContactPoint.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxManager.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.