Panda3D
physxContactReport.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 physxContactReport.cxx
10  * @author enn0x
11  * @date 2009-09-19
12  */
13 
14 #include "physxContactReport.h"
15 #include "physxContactPair.h"
16 #include "physxManager.h"
17 
18 #include "event.h"
19 #include "eventQueue.h"
20 #include "eventParameter.h"
21 
22 PStatCollector PhysxContactReport::_pcollector("App:PhysX:Contact Reporting");
23 
24 /**
25  *
26  */
27 void PhysxContactReport::
28 enable() {
29 
30  _enabled = true;
31 }
32 
33 /**
34  *
35  */
36 void PhysxContactReport::
37 disable() {
38 
39  _enabled = false;
40 }
41 
42 /**
43  *
44  */
45 bool PhysxContactReport::
46 is_enabled() const {
47 
48  return _enabled;
49 }
50 
51 /**
52  *
53  */
54 void PhysxContactReport::
55 onContactNotify(NxContactPair &pair, NxU32 flags) {
56 
57  if (!_enabled) {
58  return;
59  }
60 
61  _pcollector.start();
62 
63  Event *event;
64  if (flags & NX_NOTIFY_ON_START_TOUCH) {
65  event = new Event("physx-contact-start");
66  }
67  else if (flags & NX_NOTIFY_ON_END_TOUCH) {
68  event = new Event("physx-contact-stop");
69  }
70  else if (flags & NX_NOTIFY_ON_TOUCH) {
71  event = new Event("physx-contact-touch");
72  }
73  else if (flags & NX_NOTIFY_ON_START_TOUCH_FORCE_THRESHOLD) {
74  event = new Event("physx-contact-start-force-threshold");
75  }
76  else if (flags & NX_NOTIFY_ON_END_TOUCH_FORCE_THRESHOLD) {
77  event = new Event("physx-contact-stop-force-threshold");
78  }
79  else if (flags & NX_NOTIFY_ON_TOUCH_FORCE_THRESHOLD) {
80  event = new Event("physx-contact-touch-force-threshold");
81  }
82  else {
83  return;
84  }
85 
86  PT(PhysxContactPair) ppair = new PhysxContactPair(pair);
87  event->add_parameter(EventParameter(ppair));
88  EventQueue::get_global_event_queue()->queue_event(event);
89 
90  _pcollector.stop();
91 }
An optional parameter associated with an event.
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
Definition: eventQueue.I:19
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight class that represents a single element that may be timed and/or counted via stats.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is send with contact reporting events.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A named event, possibly with parameters.
Definition: event.h:33
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.