Panda3D
 All Classes Functions Variables Enumerations
physxContactReport.cxx
1 // Filename: physxContactReport.cxx
2 // Created by: enn0x (19Sep09)
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 "physxContactReport.h"
16 #include "physxContactPair.h"
17 #include "physxManager.h"
18 
19 #include "event.h"
20 #include "eventQueue.h"
21 #include "eventParameter.h"
22 
23 PStatCollector PhysxContactReport::_pcollector("App:PhysX:Contact Reporting");
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: PhysxContactReport::enable
27 // Access: Public
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 void PhysxContactReport::
31 enable() {
32 
33  _enabled = true;
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: PhysxContactReport::disable
38 // Access: Public
39 // Description:
40 ////////////////////////////////////////////////////////////////////
41 void PhysxContactReport::
42 disable() {
43 
44  _enabled = false;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: PhysxContactReport::is_enabled
49 // Access: Public
50 // Description:
51 ////////////////////////////////////////////////////////////////////
52 bool PhysxContactReport::
53 is_enabled() const {
54 
55  return _enabled;
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: PhysxContactReport::onContactNotify
60 // Access: Public
61 // Description:
62 ////////////////////////////////////////////////////////////////////
63 void PhysxContactReport::
64 onContactNotify(NxContactPair &pair, NxU32 flags) {
65 
66  if (!_enabled) {
67  return;
68  }
69 
70  _pcollector.start();
71 
72  Event *event;
73  if (flags & NX_NOTIFY_ON_START_TOUCH) {
74  event = new Event("physx-contact-start");
75  }
76  else if (flags & NX_NOTIFY_ON_END_TOUCH) {
77  event = new Event("physx-contact-stop");
78  }
79  else if (flags & NX_NOTIFY_ON_TOUCH) {
80  event = new Event("physx-contact-touch");
81  }
82  else if (flags & NX_NOTIFY_ON_START_TOUCH_FORCE_THRESHOLD) {
83  event = new Event("physx-contact-start-force-threshold");
84  }
85  else if (flags & NX_NOTIFY_ON_END_TOUCH_FORCE_THRESHOLD) {
86  event = new Event("physx-contact-stop-force-threshold");
87  }
88  else if (flags & NX_NOTIFY_ON_TOUCH_FORCE_THRESHOLD) {
89  event = new Event("physx-contact-touch-force-threshold");
90  }
91  else {
92  return;
93  }
94 
95  PT(PhysxContactPair) ppair = new PhysxContactPair(pair);
96  event->add_parameter(EventParameter(ppair));
97  EventQueue::get_global_event_queue()->queue_event(event);
98 
99  _pcollector.stop();
100 }
101 
An optional parameter associated with an event.
A lightweight class that represents a single element that may be timed and/or counted via stats...
A queue of pending events.
Definition: eventQueue.h:32
An instance of this class is send with contact reporting events.
A named event, possibly with parameters.
Definition: event.h:36